diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/frontend/controls/AccountActivation.php | 38 | ||||
-rw-r--r-- | app/frontend/controls/AccountActivation.tpl | 6 | ||||
-rw-r--r-- | app/frontend/facades/UserFacade.php | 16 | ||||
-rw-r--r-- | app/frontend/pages/Activate.page | 7 | ||||
-rw-r--r-- | app/frontend/url/config.xml | 6 |
5 files changed, 73 insertions, 0 deletions
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 @@ +<?php + +Prado::using('Application.web.FacadeTemplateControl'); + +Prado::using('Application.facades.UserFacade'); + +class AccountActivation extends FacadeTemplateControl { + + private $_emailHash; + private $_activationHash; + + public function getEmail() { + return $this->_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 @@ +<com:TLabel ID="SuccessLabel"> + <%[ Your account has been activated successfully. ]%> +</com:TLabel> +<com:Tlabel ID="ErrorLabel"> + <%[ There was a problem with account activation. Maybe your account is already active? ]%> +</com:Tlabel> 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 @@ +<com:TContent ID="Content"> + <com:AccountActivation> + <prop:Facade><%= UserFacade::getInstance() %></prop:Facade> + <prop:Email><%= $this->Request['email'] %></prop:Email> + <prop:Hash><%= $this->Request['hash'] %></prop:Hash> + </com:AccountActivation> +</com:TContent> 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=".*" /> + <url ServiceParameter="Activate" + UrlFormat="HiddenPath" + pattern="activate/{email}/{hash}/" + parameters.email="(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?" + parameters.hash="[a-f0-9]{32}" /> + <url ServiceParameter="*" UrlFormat="HiddenPath" EnableCustomUrl="false" |