diff options
author | emkael <emkael@tlen.pl> | 2017-03-15 16:41:46 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-03-15 16:47:25 +0100 |
commit | 44149fc7916ab129e626441d2d81cd8ec7a8ec9f (patch) | |
tree | 22958adaa46b7595ce66e78ebf8dcf37e8ddae20 /app/frontend/facades | |
parent | f70a6798f14773faefea6628927d9240940a6f26 (diff) |
* activation on registration
Diffstat (limited to 'app/frontend/facades')
-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) |