adding app/controllers/UserController.php
This commit is contained in:
parent
ad03270d57
commit
3e38c8ca41
1 changed files with 34 additions and 0 deletions
34
app/controllers/UserController.php
Normal file
34
app/controllers/UserController.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Form\UserSettings as UserSettingsForm;
|
||||
|
||||
class UserController extends ControllerBase
|
||||
{
|
||||
public function settingsAction()
|
||||
{
|
||||
$user = $this->_getAuth()->getUser();
|
||||
|
||||
$form = new UserSettingsForm($user);
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
if ($form->isValid($data)) {
|
||||
|
||||
$new_pw = $form->getValue('passwordNew');
|
||||
if (strlen($new_pw) > 0) {
|
||||
$hash = password_hash($new_pw, PASSWORD_BCRYPT);
|
||||
$user->setPassword($hash);
|
||||
}
|
||||
$user->save();
|
||||
$form->initialize();
|
||||
|
||||
$this->flash->message('success', 'Settings saved!');
|
||||
} else {
|
||||
$this->flash->message('error', 'Could not save settings');
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
Reference in a new issue