102 lines
No EOL
2.6 KiB
PHP
102 lines
No EOL
2.6 KiB
PHP
<?php
|
|
|
|
class ProfileController extends Fiktiv_Controller_Action
|
|
{
|
|
public function indexAction()
|
|
{
|
|
|
|
$form = $this->view->form = new Zend_Form();
|
|
|
|
$form->addElement('text', 'email', array(
|
|
'label' => 'u:email',
|
|
'validators' => array(new Zend_Validate_EmailAddress())
|
|
));
|
|
|
|
$form->addElement('text', 'firstName', array(
|
|
'label' => 'u:firstname',
|
|
'validators' => array(new Zend_Validate_Alpha())
|
|
));
|
|
|
|
$form->addElement('text', 'lastName', array(
|
|
'label' => 'u:lastname',
|
|
'validators' => array(new Zend_Validate_Alpha())
|
|
));
|
|
|
|
$form->addElement('password', 'password', array(
|
|
'label' => 'u:password',
|
|
'validators' => array(new Zend_Validate_Alnum())
|
|
));
|
|
|
|
$form->addElement('password', 'passwordConfirm', array(
|
|
'label' => 'u:confirm password',
|
|
'validators' => array(new Zend_Validate_Alnum())
|
|
));
|
|
|
|
$form->addElement('Submit', 'save', array(
|
|
'label' => 'u:save'
|
|
));
|
|
|
|
$form->addDisplayGroup(
|
|
array(
|
|
'email',
|
|
'firstName',
|
|
'lastName'
|
|
),
|
|
'partOne',
|
|
array(
|
|
'legend' => 'u:user information'
|
|
)
|
|
);
|
|
|
|
$form->addDisplayGroup(
|
|
array(
|
|
'password',
|
|
'passwordConfirm'
|
|
),
|
|
'partTwo',
|
|
array(
|
|
'legend' => 'u:change password'
|
|
)
|
|
);
|
|
|
|
$form->addDisplayGroup(
|
|
array(
|
|
'save'
|
|
),
|
|
'partThree'
|
|
);
|
|
|
|
|
|
$user = Zend_Auth::getInstance()->getIdentity();
|
|
|
|
|
|
if ($this->_request->isPost()) {
|
|
|
|
$data = $this->_request->getPost();
|
|
|
|
if ($data['password'] !== $data['passwordConfirm'] || empty($data['password'])) {
|
|
|
|
if (!empty($data['password']))
|
|
$this->view->messages = 'passwords dont match';
|
|
|
|
|
|
} else {
|
|
|
|
if ($user->setPassword($data['password']))
|
|
$this->view->messages = 'Lösenordet är ändrat!';
|
|
|
|
unset($data['password']);
|
|
}
|
|
unset($data['passwordConfirm']);
|
|
unset($data['save']);
|
|
|
|
|
|
$user->setAttribs($data);
|
|
$user->save();
|
|
|
|
}
|
|
|
|
$form->populate($user->toArray());
|
|
|
|
}
|
|
} |