/**
  *  Register the user
  *
  * @return string|\yii\web\Response
  */
 public function actionRegister()
 {
     $model = new User();
     $model->scenario = 'register';
     if ($model->load(Yii::$app->request->post()) && $model->register(FALSE, User::STATUS_PENDING)) {
         // Send Welcome Message to activate the account
         Mailer::sendWelcomeMessage($model);
         Yii::$app->session->setFlash('success', Yii::t('user', 'You\'ve successfully been registered. Check your mail to activate your account'));
         return $this->redirect(Yii::$app->urlManager->createUrl('//user/auth/login'));
     }
     return $this->render('register', ['model' => $model]);
 }
 /**
  * Sends recovery message.
  */
 public function recoverPassword()
 {
     $user = User::findOne(['email' => $this->email]);
     if ($user != NULL) {
         $user->password_reset_token = Yii::$app->getSecurity()->generateRandomString() . '_' . time();
         $user->save(FALSE);
     }
     // Sends recovery mail
     Mailer::sendRecoveryMessage($user);
     Yii::$app->session->setFlash('info', 'You will receive an email with instructions on how to reset your password in a few minutes.');
 }
Пример #3
0
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'username', $this->username]);
     return $dataProvider;
 }
Пример #4
0
 /**
  * @param integer $id   User Id
  * @param string  $code Password Reset Token
  *
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionReset($id, $code)
 {
     $model = User::findOne(['id' => $id, 'password_reset_token' => $code, 'status' => User::STATUS_ACTIVE]);
     if ($model == NULL) {
         throw new NotFoundHttpException();
     }
     $model->scenario = 'reset';
     if (!empty($model)) {
         if ($model->load(Yii::$app->request->post())) {
             if ($model->validate()) {
                 $model->password_reset_token = NULL;
                 $model->save();
                 Yii::$app->session->setFlash('success', Yii::t('user', 'Your password has successfully been changed. Now you can login with your new password.'));
                 return $this->redirect(['//user/auth/login']);
             }
         }
     }
     return $this->render('reset', ['model' => $model]);
 }
Пример #5
0
 /**
  * Setup Administrative User
  *
  * This should be the last step, before the user is created also the
  * application secret will created.
  */
 public function actionAdmin()
 {
     $model = new User();
     $profile = new Profile();
     $model->scenario = 'register';
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         if ($model->register(TRUE)) {
             return $this->redirect(Yii::$app->urlManager->createUrl('//installer/config/finished'));
         }
     }
     return $this->render('admin', ['model' => $model, 'profile' => $profile]);
 }
 public function up()
 {
     $this->createTable(SocialAccount::tableName(), ['id' => Schema::TYPE_PK, 'uid' => Schema::TYPE_INTEGER . ' NOT NULL UNIQUE', 'provider' => Schema::TYPE_STRING . ' NOT NULL', 'client_id' => Schema::TYPE_STRING . ' NOT NULL']);
     $this->createIndex('account_unique', SocialAccount::tableName(), ['provider', 'client_id'], TRUE);
     $this->addForeignKey('fk_user_account', SocialAccount::tableName(), 'uid', User::tableName(), 'id', 'CASCADE', 'RESTRICT');
 }
Пример #7
0
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'uid']);
 }
 public function down()
 {
     $this->dropTable(Profile::tableName());
     $this->dropTable(User::tableName());
 }