5use Ajax\semantic\components\validation\Rule;
6use Ajax\semantic\html\collections\form\HtmlForm;
25 abstract protected function useAjax():bool;
33 abstract protected function authLoadView($viewName, $vars = [ ]):void;
68 return new \DateInterval(
'PT24H');
116 protected function _create(
string $login,
string $password):?bool{
136 protected function _sendEmailValidation(string $email,string $validationURL,string $expire):void{
146 protected function getEmailFromNewAccount($account):string{
156 return new
AuthTokens(self::$TOKENS_VALIDATE_EMAIL,10,$this->emailValidationDuration()->s,false);
160 $duration=$this->emailValidationDuration();
161 $tokens=$this->getAuthTokensEmailValidation();
163 $dExpire=$d->add($duration);
164 $key=$tokens->store([
'email'=>$email]);
165 return [
'url'=>$key.
'/'.\md5($email),
'expire'=>$dExpire];
169 $data=$this->generateEmailValidationUrl($email);
170 $validationURL=$this->getBaseUrl().
'/checkEmail/'.$data[
'url'];
171 $this->_sendEmailValidation($email, $validationURL,UDateTime::elapsed($data[
'expire']));
193 $tokens=$this->getAuthTokensEmailValidation();
194 if($tokens->exists($key)){
195 if(!$tokens->expired($key)){
196 $data=$tokens->fetch($key);
197 $email=$data[
'email'];
198 if(\md5($email)===$hashMail && $this->validateEmail($email)){
199 $fMessage =
new FlashMessage (
"Your email <b>$email</b> has been validated.",
'Account creation',
'success',
'user' );
200 $this->emailValidationSuccess($fMessage);
203 $msg=
'This validation link is not valid!';
205 $msg=
'This validation link is no longer active!';
209 $fMessage =
new FlashMessage ( $msg??
'This validation link is not valid!',
'Account creation',
'error',
'user' );
210 $this->emailValidationError($fMessage);
212 echo $this->fMessage($fMessage);
220 if($this->hasAccountCreation()){
221 $loginInputName=$this->_getLoginInputName();
222 $passwordInputName=$this->_getPasswordInputName();
223 if($this->useAjax()){
224 $frm=$this->_addFrmAjaxBehavior(
'frm-create');
225 $frm->addExtraFieldRules($passwordInputName.
'-conf', [
'empty',
"match[$passwordInputName]"]);
226 if($this->_newAccountCreationRule(
'')!==
null){
227 $this->jquery->exec(Rule::ajax($this->jquery,
'checkAccount', $this->getBaseUrl () .
'/newAccountCreationRule',
'{}',
'result=data.result;',
'postForm', [
228 'form' =>
'frm-create'
230 $frm->addExtraFieldRule($loginInputName,
'checkAccount',
"This $loginInputName value is not available!");
233 $this->authLoadView ( $this->_getFiles ()->getViewCreate(), [
'action' => $this->getBaseUrl () .
'/createAccount',
'loginInputName' => $loginInputName,
'loginLabel' => $this->loginLabel (),
'passwordInputName' => $passwordInputName,
'passwordLabel' => $this->passwordLabel (),
'passwordConfLabel'=>$this->passwordConfLabel(),
'rememberCaption' => $this->rememberCaption () ] );
243 #[\Ubiquity\attributes\items\router\Post]
245 $account=URequest::post($this->_getLoginInputName());
247 if($this->_create($account,URequest::post($this->_getPasswordInputName()))){
248 if($this->hasEmailValidation()){
249 $email=$this->getEmailFromNewAccount($account);
250 $this->prepareEmailValidation($email);
251 $msgSup=
"<br>Confirm your email address <b>$email</b> by checking your mailbox.";
253 $msg=
new FlashMessage (
'<b>{account}</b> account created with success!'.$msgSup,
'Account creation',
'success',
'check square' );
255 $msg=
new FlashMessage (
'The account <b>{account}</b> was not created!',
'Account creation',
'error',
'warning circle' );
257 $message=$this->fMessage($msg->parseContent([
'account'=>$account]));
258 $this->authLoadView ( $this->_getFiles ()->getViewNoAccess (), [
'_message' => $message,
'authURL' => $this->getBaseUrl (),
'bodySelector' => $this->_getBodySelector (),
'_loginCaption' => $this->_loginCaption ] );
Ubiquity\controllers\auth$AuthFiles This class is part of Ubiquity.
Trait AuthAccountCreationTrait.
fMessage(FlashMessage $fMessage, $id=null)
generateEmailValidationUrl($email)
addAccount()
Displays the account creation form.
hasAccountCreation()
Returns true for account creation.
createAccount()
Submit for a new account creation.
canCreateAccountMessage(FlashMessage $fMessage)
To override for modifying the account creation message information.
_create(string $login, string $password)
To override For creating a new user account.
createAccountMessage(FlashMessage $fMessage)
To override for modifying the account creation message.
validateEmail(string $mail)
To override Checks an email.
_newAccountCreationRule(string $accountName)
To override Returns true if the creation of $accountName is possible.
createAccountErrorMessage(FlashMessage $fMessage)
To override for modifying the error for account creation.
authLoadView($viewName, $vars=[])
emailValidationError(FlashMessage $fMessage)
To override Displayed when email is invalid or if an error occurs.
static string $TOKENS_VALIDATE_EMAIL
checkEmail(string $key, string $hashMail)
Route for email validation checking when creating a new account.
prepareEmailValidation(string $email)
emailValidationSuccess(FlashMessage $fMessage)
To override Displayed when email is valid.
getAuthTokensEmailValidation()
To override Returns the AuthTokens instance used for tokens generation when sending an email for the ...
emailValidationDuration()
Returns the default validity duration of a mail validation link.
DateTime utilities Ubiquity\utils\base$UDateTime This class is part of Ubiquity.
Http Request utilities, wrapper for accessing to $_GET, $_POST and php://input.