From 5cf31430c777867dfe7f5751cf11d8928ae2784e Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 12 Jun 2018 00:34:49 +0200 Subject: [PATCH] app/controllers/UserController.php: adding activationLinkAction() --- app/controllers/UserController.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index a5be866..4e6c7de 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -58,6 +58,35 @@ class UserController extends ControllerBase $this->view->form = $form; } + /** + * Activate a password. + * + * @param $id + */ + public function activationLinkAction($id) + { + $link = PasswordLink::findFirst(['public_id = ?0', 'bind' => [ $id ]]); + + if ($link) { + if ($link->isValid()) { + + // Save the password. + $link->getUser() + ->setPassword($link->getPassword()) + ->save(); + + $this->flash->success('Your password has been activated.'); + } else { + $this->flash->error('This link has expired or has already been used.'); + } + + // Make sure the link is deleted. + $link->delete(); + } else { + $this->flash->error('This does not seem to be an active link'); + } + } + public function activityAction($page = 1) { $user = $this->_getAuth()->getUser();