/** * @inheritdoc */ public function beforeAction($action) { if (Yii::$app->request->get('token') === null) { throw new ForbiddenHttpException(Module::t('errors', 'Invalid authentication token.')); } return true; }
/** * Validates that the account exists. * * @param string $attribute attribute name. * @param array $params additional parameters. */ public function validateAccountExists($attribute, $params) { $account = Module::getInstance()->getDataContract()->findAccount(['email' => $this->email]); if ($account === null) { $this->addError($attribute, Module::t('errors', 'Please check the e-mail address.')); } }
/** * Validates that the account exists. * * @param string $attribute attribute name. * @param array $params additional parameters. */ public function validateAccountExists($attribute, $params) { $account = Module::getInstance()->getDataContract()->findAccount(['email' => $this->email]); if ($account === null) { $this->addError($attribute, Module::t('errors', 'There is no account is associated with this e-mail address.')); } }
/** * @inheritdoc */ public function beforeAction($action) { if (!Module::getInstance()->enableSignup) { $this->owner->pageNotFound(); } return true; }
/** * Validates this model and creates a new account for the user. * * @return boolean whether sign-up was successful. */ public function signup() { if ($this->validate()) { $dataContract = Module::getInstance()->getDataContract(); $account = $dataContract->createAccount(['attributes' => $this->attributes]); if ($account->validate()) { if ($account->save(false)) { $dataContract->createPasswordHistory(['accountId' => $account->id, 'password' => $account->password]); return true; } } foreach ($account->getErrors('password') as $error) { $this->addError('password', $error); } } return false; }
</h1> <p class="help-block"> <?php echo Module::t('views', 'Please enter your e-mail address and we will send you instructions on how to reset your password.'); ?> </p> <?php $form = ActiveForm::begin(['id' => 'forgotpasswordform']); ?> <fieldset> <?php echo $form->field($model, 'email'); ?> </fieldset> <?php echo Html::submitButton(Module::t('views', 'Send'), ['class' => 'btn btn-lg btn-primary']); ?> <?php ActiveForm::end(); ?> </div> </div> </div>
/** * Returns a model class using the given condition. * * @param string $className class name. * @param mixed $condition search condition. * @return ActiveRecord|null model instance or null if not found. */ protected function findInternal($className, $condition) { /** @var ActiveRecord $modelClass */ $modelClass = Module::getInstance()->getClassName($className); return $modelClass::findOne($condition); }
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('labels', 'ID'), 'accountId' => Module::t('labels', 'Account ID'), 'success' => Module::t('labels', 'Success'), 'numFailedAttempts' => Module::t('labels', '# Failed Attempts'), 'createdAt' => Module::t('labels', 'Created At')]; }
/** * Generates "remember me" authentication key */ public function generateAuthKey() { $this->authKey = Module::getInstance()->getTokenGenerator()->generate(); }
/** * Returns the account associated with the value of the login attribute. * * @return Account model instance. */ public function getAccount() { if ($this->_account === null) { $this->_account = Module::getInstance()->getDataContract()->findAccount([Module::getInstance()->loginAttribute => $this->username]); } return $this->_account; }
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('labels', 'ID'), 'accountId' => Module::t('labels', 'Account ID'), 'name' => Module::t('labels', 'Name'), 'clientId' => Module::t('labels', 'Client ID'), 'data' => Module::t('labels', 'Data')]; }
* This file is part of Account. * * (c) 2014 Nord Software * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use nord\yii\account\Module; use yii\helpers\Html; /* @var $this yii\web\View */ $this->title = Module::t('views', 'Sign up successful'); ?> <div class="register-controller done-action"> <h1 class="page-header"><?php echo Html::encode($this->title); ?> </h1> <p class="lead"><?php echo Module::t('views', 'You will soon receive an email with instructions on how to activate your account.'); ?> </p> <p><?php echo Html::a(Module::t('views', 'Done'), Yii::$app->homeUrl, ['class' => 'btn btn-primary btn-lg']); ?> </p> </div>
* This file is part of Account. * * (c) 2014 Nord Software * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use nord\yii\account\Module; use yii\helpers\Html; /* @var $this yii\web\View */ $this->title = Module::t('views', 'Success'); ?> <div class="register-controller done-action"> <h1 class="page-header"><?php echo Html::encode($this->title); ?> </h1> <p class="lead"><?php echo Module::t('views', 'Thank you for signing up!'); ?> </p> <p><?php echo Module::t('views', 'You will soon receive an email with instructions on how to activate your account.'); ?> </p> </div>
<?php /* * This file is part of Account. * * (c) 2014 Nord Software * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use nord\yii\account\Module; use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $actionUrl string */ echo Module::t('email', 'Thank you for signing up'); ?> <br><br> <?php echo Module::t('email', 'Please click the link below to activate your account:'); ?> <br> <?php echo Html::a($actionUrl, $actionUrl);
<?php /* * This file is part of Account. * * (c) 2014 Nord Software * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use nord\yii\account\Module; use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $actionUrl string */ echo Module::t('email', 'You have requested to reset your password'); ?> <br><br> <?php echo Module::t('email', 'Please click the link below to reset the password for your account:'); ?> <br> <?php echo Html::a($actionUrl, $actionUrl);
/** * Sends a test "recover pasword" e-mail to the specified e-mail address * * @param string $email */ public function actionTestResendPasswordEmail($email) { $actionUrl = 'http://example.com/recoverPassword/' . $email; $this->module->getMailSender()->sendResetPasswordMail(['to' => [$email], 'from' => $this->module->getParam(Module::PARAM_FROM_EMAIL_ADDRESS), 'subject' => Module::t('email', 'Thank you for signing up'), 'data' => ['actionUrl' => $actionUrl]]); }
/** * Creates a password history entry. * * @param Account $account model instance. */ public function createHistoryEntry(ActiveRecord $account) { Module::getInstance()->getDataContract()->createPasswordHistory(['accountId' => $account->getPrimaryKey(), 'password' => $account->password]); }
<?php echo Module::t('views', 'Please enter a new password twice to change the your password.'); ?> </p> <?php $form = ActiveForm::begin(['id' => 'passwordform']); ?> <fieldset> <?php echo $form->field($model, 'password')->passwordInput(); ?> <?php echo $form->field($model, 'verifyPassword')->passwordInput(); ?> </fieldset> <?php echo Html::submitButton(Module::t('views', 'Change Password'), ['class' => 'btn btn-lg btn-primary']); ?> <?php ActiveForm::end(); ?> </div> </div> </div>
<?php echo Html::submitButton(Module::t('views', 'Login'), ['class' => 'btn btn-lg btn-primary']); ?> <?php ActiveForm::end(); ?> <?php if (Module::getInstance()->enableClientAuth) { ?> <hr/> <p class="help-block"> <?php echo Module::t('views', 'You may also log in using one of the providers below:'); ?> </p> <?php echo AuthChoice::widget(); ?> <?php } ?> </div> </div> </div>
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('labels', 'ID'), 'accountId' => Module::t('labels', 'Account ID'), 'type' => Module::t('labels', 'Type'), 'token' => Module::t('labels', 'Token'), 'createdAt' => Module::t('labels', 'Created At'), 'status' => Module::t('labels', 'Status')]; }
/** * Sends a reset password email to owner of the given account. * * @param ActiveRecord $account model instance. */ protected function sendResetPasswordMail(ActiveRecord $account) { $token = $this->module->generateToken(Module::TOKEN_RESET_PASSWORD, $account->id); $actionUrl = $this->module->createUrl([Module::URL_ROUTE_RESET_PASSWORD, 'token' => $token], true); $this->module->getMailSender()->sendResetPasswordMail(['to' => [$account->email], 'from' => $this->module->getParam(Module::PARAM_FROM_EMAIL_ADDRESS), 'subject' => Module::t('email', 'Reset password'), 'data' => ['actionUrl' => $actionUrl]]); }
/** * @param string $message error message. * @throws HttpException when called. */ public function fatalError($message = null) { throw new ServerErrorHttpException($message === null ? Module::t('errors', 'Something went wrong.') : $message); }
/** * @inheritdoc */ public function attributeLabels() { return ['email' => Module::t('labels', 'Email'), 'username' => Module::t('labels', 'Username')]; }
/* * This file is part of Account. * * (c) 2014 Nord Software * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use nord\yii\account\Module; use yii\helpers\Html; /* @var $this yii\web\View */ $this->title = Module::t('views', 'Success'); ?> <div class="password-controller sent-action"> <h1 class="page-header"><?php echo Html::encode($this->title); ?> </h1> <p class="lead"><?php echo Module::t('views', 'Do not worry'); ?> </p> <p><?php echo Module::t('views', 'You will soon receive an email with instructions on how to reset the password for your account.'); ?> </p> </div>
</h1> <p class="help-block"> <?php echo Module::t('views', 'Please enter your e-mail address and we will send you instructions on how to reset your password.'); ?> </p> <?php $form = ActiveForm::begin(['id' => 'forgotpasswordform']); ?> <fieldset> <?php echo $form->field($model, 'email'); ?> </fieldset> <?php echo Html::submitButton(Module::t('views', 'Recover Account'), ['class' => 'btn btn-lg btn-primary']); ?> <?php ActiveForm::end(); ?> </div> </div> </div>
/** * Invoked after a successful authentication with a client. * * @param ClientInterface $client client instance. * @return \yii\web\Response */ public function clientLogin(ClientInterface $client) { $attributes = $client->getUserAttributes(); $name = $client->getId(); $dataContract = $this->module->getDataContract(); $provider = $dataContract->findProvider(['name' => $name, 'clientId' => $attributes['id']]); if ($provider === null) { $provider = $dataContract->createProvider(['attributes' => ['name' => $name, 'clientId' => $attributes['id'], 'data' => $attributes]]); if (!$provider->save(false)) { $this->fatalError(); } } if ($provider->account !== null) { Yii::$app->user->login($provider->account, Module::getParam(Module::PARAM_LOGIN_EXPIRE_TIME)); return $this->goHome(); } else { return $this->redirect([Module::URL_ROUTE_CONNECT, 'providerId' => $provider->id]); } }
/** * Generates a new truly unique random token and saves it in the database. * * @param string $type token type. * @param integer $accountId account id. * @return string the generated token. */ public function generateToken($type, $accountId) { $dataContract = $this->getDataContract(); $attributes = ['accountId' => $accountId, 'type' => $type]; while (!isset($attributes['token'])) { $attributes['token'] = Module::getInstance()->getTokenGenerator()->generate(); if ($dataContract->findToken($attributes) !== null) { unset($attributes['token']); } } $dataContract->createToken(['attributes' => $attributes]); return $attributes['token']; }
/** * Sends an activation email to owner of the given account. * * @param ActiveRecord $account account instance. */ protected function sendActivationMail(ActiveRecord $account) { $token = $this->module->generateToken(Module::TOKEN_ACTIVATE, $account->id); $actionUrl = $this->module->createUrl([Module::URL_ROUTE_ACTIVATE, 'token' => $token], true); $this->module->getMailSender()->sendActivationMail(['to' => [$account->email], 'from' => $this->module->getParam(Module::PARAM_FROM_EMAIL_ADDRESS), 'subject' => Module::t('email', 'Thank you for signing up'), 'data' => ['actionUrl' => $actionUrl]]); }
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('labels', 'ID'), 'accountId' => Module::t('labels', 'Account ID'), 'password' => Module::t('labels', 'Password'), 'createdAt' => Module::t('labels', 'Created At')]; }
/** * @inheritdoc */ public function validateAttribute($object, $attribute) { $password = $object->{$attribute}; $length = mb_strlen($password); if ($this->minLength && $length < $this->minLength) { $this->addError($object, $attribute, Module::t('errors', "{attribute} is too short, minimum is {n} {n, plural, =1{character} other{characters}}.", ['n' => $this->minLength])); return false; } if ($this->minDigits) { $digits = ''; if (preg_match_all("/[\\d+]/u", $password, $matches)) { $digits = implode('', $matches[0]); } if (mb_strlen($digits) < $this->minDigits) { $this->addError($object, $attribute, Module::t('errors', "{attribute} should contain at least {n} {n, plural, =1{digit} other{digits}}.", ['n' => $this->minLength])); return false; } } if ($this->minUpperCaseLetters) { $numUpperCaseChars = ''; if (preg_match_all("/[A-Z]/u", $password, $matches)) { $numUpperCaseChars = implode('', $matches[0]); } if (mb_strlen($numUpperCaseChars) < $this->minUpperCaseLetters) { $this->addError($object, $attribute, Module::t('errors', "{attribute} should contain at least {n} upper case {n, plural, =1{character} other{characters}}.", ['n' => $this->minLength])); return false; } } if ($this->minLowerCaseLetters) { $numLowerCaseChars = ''; if (preg_match_all("/[a-z]/u", $password, $matches)) { $numLowerCaseChars = implode('', $matches[0]); } if (mb_strlen($numLowerCaseChars) < $this->minLowerCaseLetters) { $this->addError($object, $attribute, Module::t('errors', "{attribute} should contain at least {n} lower case {n, plural, =1{character} other{characters}}.", ['n' => $this->minLength])); return false; } } if ($this->minSpecialChars) { $numSpecialChars = ''; if (preg_match_all("/[" . implode('|', $this->specialChars) . "]/u", $password, $matches)) { $numSpecialChars = implode('', $matches[0]); } if (mb_strlen($numSpecialChars) < $this->minSpecialChars) { $this->addError($object, $attribute, Module::t('errors', "{attribute} should contain at least {n} non alpha numeric {n, plural, =1{character} other{characters}}.", ['n' => $this->minLength])); return false; } } return true; }