diff options
Diffstat (limited to 'app/frontend/facades/UserFacade.php')
-rw-r--r-- | app/frontend/facades/UserFacade.php | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/app/frontend/facades/UserFacade.php b/app/frontend/facades/UserFacade.php index 9c1d5d8..96f4923 100644 --- a/app/frontend/facades/UserFacade.php +++ b/app/frontend/facades/UserFacade.php @@ -14,16 +14,29 @@ class UserFacade extends Facade { return User::finder()->findByLogin($login); } + public function findByEMail(string $email) { + return User::finder()->findByEMail($email); + } + public function checkForUsername(string $login) { return !User::finder()->count('login = ?', $login); } - public function registerUser(string $login, string $password, bool $admin) { + public function checkForEMail(string $email) { + return !User::finder()->count('e_mail = ?', $email); + } + + public function registerUser( + string $login, + string $password, + string $email, + bool $admin=FALSE) { $transaction = $this->beginTransaction(); try { $newUser = new User(); $newUser->Login = $login; $newUser->Password = $this->generatePassword($password); + $newUser->EMail = $email; $newUser->IsAdmin = $admin; $newUser->save(); $this->raiseEvent('UserRegistered', $newUser); @@ -55,6 +68,38 @@ class UserFacade extends Facade { return password_verify($password, $dbPassword); } + public function requestActivation(User $user) { + $user->IsActive = FALSE; + $user->ActivationHash = md5(mt_rand()); + $user->save(); + $this->_sendActivationMail($user); + } + + protected function _generateActivationLink($email, $hash) { + $application = Prado::getApplication(); + return $application->Request->getBaseUrl() + . $application->Service->constructUrl( + 'Activate', + ['email' => base64_encode($email), + 'hash' => $hash] + ); + } + + protected function _sendActivationMail(User $user) { + $mailModule = Prado::getApplication()->getModule('mail'); + $mailer = $mailModule->getMailer(); + $template = $mailModule->getTemplate('activation-link'); + $template->link = $this->_generateActivationLink( + $user->EMail, $user->ActivationHash + ); + $mailer->sendTemplate( + $template, + Prado::localize('rcal - account activation'), + $user->EMail, + $user->Login + ); + } + public function activateUser(string $email, string $hash) { $user = $this->findByEMail( base64_decode($email) |