/**
  * @return string
  */
 public function actionIn()
 {
     if (!User()->isGuest) {
         return $this->redirect(['/']);
     }
     $this->layout = '//wide';
     $SignInForm = \Yii::createObject(Account\frontend\forms\SignInForm::className());
     return $this->render('in', ['SignInForm' => $SignInForm]);
 }
 /**
  * @return array
  */
 public function actionIn()
 {
     $result = ['result' => false, 'message' => ['title' => \Yii::t('account', 'Sign In'), 'text' => \Yii::t('account', 'Unknown error.')]];
     /** @var Account\frontend\forms\SignInForm $SignInForm */
     $SignInForm = \Yii::createObject(Account\frontend\forms\SignInForm::className());
     if ($SignInForm->load(Request()->post()) && $SignInForm->validate() && $SignInForm->login()) {
         $result = ['result' => true, 'message' => ['title' => \Yii::t('account', 'Sign In'), 'text' => \Yii::t('account', 'Welcome!')], 'redirect' => UrlManager()->createUrl(['/'])];
     }
     if ($SignInForm->hasErrors()) {
         $result = ['result' => false, 'message' => ['title' => \Yii::t('account', 'Sign In'), 'text' => \Yii::t('account', 'Form errors.')], 'errors' => $SignInForm->getFirstErrors()];
     }
     return $result;
 }
 /**
  * @param \yii\authclient\ClientInterface $Client
  * @return bool
  * @throws \yii\base\InvalidConfigException
  */
 public function save(\yii\authclient\ClientInterface $Client)
 {
     /** @var \cookyii\modules\Account\resources\Account $Account */
     $Account = \Yii::createObject(\cookyii\modules\Account\resources\Account::className());
     $Account->appendClientAttributes($Client);
     $Account->setAttributes(['email' => $this->email, 'password' => Security()->generateRandomString(10)]);
     $Account->validate() && $Account->save();
     if (!$Account->hasErrors()) {
         $Account->notificationHelper->sendSignUpEmail();
         AuthManager()->assign(RbacFactory::Role(\common\Roles::USER), $Account->id);
         $SignInFormModel = \Yii::createObject(SignInForm::className());
         User()->login($Account, $SignInFormModel::REMEMBER_TIME);
     }
     if ($Account->hasErrors()) {
         $this->populateErrors($Account, 'name');
     }
     return !$Account->hasErrors();
 }
Exemple #4
0
 /**
  * @return bool
  */
 public function register()
 {
     /** @var \cookyii\modules\Account\resources\Account $Account */
     $Account = \Yii::createObject(\cookyii\modules\Account\resources\Account::className());
     $Account->setAttributes(['name' => $this->name, 'email' => $this->email, 'password' => $this->password, 'activated_at' => time()]);
     $Account->validate() && $Account->save();
     if (!$Account->hasErrors()) {
         $Account->notificationHelper->sendSignUpEmail();
         AuthManager()->assign(RbacFactory::Role(\common\Roles::USER), $Account->id);
         if ($this->loginAfterRegister) {
             $SignInFormModel = \Yii::createObject(SignInForm::className());
             User()->login($Account, $SignInFormModel::REMEMBER_TIME);
         }
     }
     if ($Account->hasErrors()) {
         $this->populateErrors($Account, 'name');
     }
     return !$Account->hasErrors();
 }
 /**
  * @return bool
  * @throws \yii\web\ServerErrorHttpException
  */
 public function resetPassword()
 {
     $Account = $this->getAccount();
     $new_password = Security()->generateRandomString(8);
     $Account->password = $new_password;
     $Account->validate() && $Account->save();
     if (!$Account->hasErrors()) {
         $Account->notificationHelper->sendNewPasswordEmail($new_password);
         $Account->refreshToken();
         if ($this->loginAfterReset) {
             $SignInFormModel = \Yii::createObject(SignInForm::className());
             User()->login($Account, $SignInFormModel::REMEMBER_TIME);
         }
     }
     if ($Account->hasErrors()) {
         $this->populateErrors($Account, 'email');
     }
     return !$Account->hasErrors();
 }