Archived
1
0
Fork 0

adding app/controllers/UserController.php

This commit is contained in:
Henrik Hautakoski 2018-04-01 10:10:24 +02:00
parent ad03270d57
commit 3e38c8ca41

View 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;
}
}