Exemplo n.º 1
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->user = User::find()->where(['email' => $this->email])->one();
     if ($this->user) {
         $model = new Reset();
         $model->user_id = $this->user->id;
         return $model->save();
     }
     return true;
 }
 public function actionReset($code)
 {
     $code = Reset::find()->where(['code' => $code, 'used' => 0])->andWhere(['>', 'expires', time()])->one();
     if (!$code) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $model = new ResetPasswordForm($code->user_id);
     $model->load(Yii::$app->getRequest()->getBodyParams(), '');
     if ($model->save() === false && !$model->hasErrors()) {
         throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
     }
     $code->used = 1;
     $code->save();
     return $model;
 }