app/controllers/UserController.php: in settingsAction() create password link for new passwords.
This commit is contained in:
parent
552af58c7f
commit
b6074cf3ef
1 changed files with 24 additions and 2 deletions
|
|
@ -4,7 +4,8 @@ namespace App\Controller;
|
||||||
|
|
||||||
use App\Controller\ControllerBase,
|
use App\Controller\ControllerBase,
|
||||||
App\Form\UserSettings as UserSettingsForm,
|
App\Form\UserSettings as UserSettingsForm,
|
||||||
App\Model\Data\ActivityLog;
|
App\Model\Data\ActivityLog,
|
||||||
|
App\Model\Data\PasswordLink;
|
||||||
|
|
||||||
class UserController extends ControllerBase
|
class UserController extends ControllerBase
|
||||||
{
|
{
|
||||||
|
|
@ -21,9 +22,30 @@ class UserController extends ControllerBase
|
||||||
|
|
||||||
$new_pw = $form->getValue('passwordNew');
|
$new_pw = $form->getValue('passwordNew');
|
||||||
if (strlen($new_pw) > 0) {
|
if (strlen($new_pw) > 0) {
|
||||||
|
|
||||||
$hash = password_hash($new_pw, PASSWORD_BCRYPT);
|
$hash = password_hash($new_pw, PASSWORD_BCRYPT);
|
||||||
$user->setPassword($hash);
|
|
||||||
|
// User had a password before. just update.
|
||||||
|
if (strlen($user->getPassword()) > 0) {
|
||||||
|
$user->setPassword($hash);
|
||||||
|
}
|
||||||
|
// Else we create a password link and email.
|
||||||
|
else {
|
||||||
|
$link = new PasswordLink();
|
||||||
|
$link->setUserId($user->getId())
|
||||||
|
->setPassword($hash)
|
||||||
|
->save();
|
||||||
|
|
||||||
|
// TODO: Send the email here.
|
||||||
|
|
||||||
|
$msg = "For security reasons. Before a password can be created "
|
||||||
|
. "a email has been sent to <strong>{$user->getEmail()}</strong> with "
|
||||||
|
. "a activation link.";
|
||||||
|
|
||||||
|
$this->flash->notice($msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
$form->initialize();
|
$form->initialize();
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue