From f70a6798f14773faefea6628927d9240940a6f26 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 15 Mar 2017 16:36:16 +0100 Subject: * activation landing page --- app/frontend/controls/AccountActivation.php | 38 +++++++++++++++++++++++++++++ app/frontend/controls/AccountActivation.tpl | 6 +++++ app/frontend/facades/UserFacade.php | 16 ++++++++++++ app/frontend/pages/Activate.page | 7 ++++++ app/frontend/url/config.xml | 6 +++++ 5 files changed, 73 insertions(+) create mode 100644 app/frontend/controls/AccountActivation.php create mode 100644 app/frontend/controls/AccountActivation.tpl create mode 100644 app/frontend/pages/Activate.page diff --git a/app/frontend/controls/AccountActivation.php b/app/frontend/controls/AccountActivation.php new file mode 100644 index 0000000..f7b7f49 --- /dev/null +++ b/app/frontend/controls/AccountActivation.php @@ -0,0 +1,38 @@ +_emailHash; + } + + public function setEmail($email) { + $this->_emailHash = TPropertyValue::ensureString($email); + } + + public function getHash() { + return $this->_activationHash; + } + + public function setHash($hash) { + $this->_activationHash = TPropertyValue::ensureString($hash); + } + + public function onPreRender($param) { + parent::onPreRender($param); + $this->SuccessLabel->Visible = $this->Facade->activateUser( + $this->Email, $this->Hash + ); + $this->ErrorLabel->Visible = !$this->SuccessLabel->Visible; + } + +} + +?> diff --git a/app/frontend/controls/AccountActivation.tpl b/app/frontend/controls/AccountActivation.tpl new file mode 100644 index 0000000..19c00b3 --- /dev/null +++ b/app/frontend/controls/AccountActivation.tpl @@ -0,0 +1,6 @@ + + <%[ Your account has been activated successfully. ]%> + + + <%[ There was a problem with account activation. Maybe your account is already active? ]%> + diff --git a/app/frontend/facades/UserFacade.php b/app/frontend/facades/UserFacade.php index 6a7feac..9c1d5d8 100644 --- a/app/frontend/facades/UserFacade.php +++ b/app/frontend/facades/UserFacade.php @@ -55,6 +55,22 @@ class UserFacade extends Facade { return password_verify($password, $dbPassword); } + public function activateUser(string $email, string $hash) { + $user = $this->findByEMail( + base64_decode($email) + ); + $activation = $user && !$user->IsActive + && ($user->ActivationHash === $hash); + if ($activation) { + $user->IsActive = TRUE; + $user->ActivationDate = date('Y-m-d H:i:s'); + $user->ActivationHash = NULL; + $user->save(); + return TRUE; + } + return FALSE; + } + public function setTimezonePreference(DbUser $user, string $timezone) { if ($user->IsGuest) { throw new TInvalidDataException( diff --git a/app/frontend/pages/Activate.page b/app/frontend/pages/Activate.page new file mode 100644 index 0000000..c967834 --- /dev/null +++ b/app/frontend/pages/Activate.page @@ -0,0 +1,7 @@ + + + <%= UserFacade::getInstance() %> + <%= $this->Request['email'] %> + <%= $this->Request['hash'] %> + + diff --git a/app/frontend/url/config.xml b/app/frontend/url/config.xml index b072b2d..71a65f3 100644 --- a/app/frontend/url/config.xml +++ b/app/frontend/url/config.xml @@ -25,6 +25,12 @@ pattern="calendar/{calendar}/" parameters.calendar=".*" /> + +