예제 #1
0
파일: SignupForm.php 프로젝트: apuc/api
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
예제 #2
0
파일: User.php 프로젝트: weiyiyi/base
 public function fields()
 {
     $fields = parent::fields();
     // 删除一些包含敏感信息的字段
     unset($fields['password_hash']);
     return $fields;
 }
예제 #3
0
 /**
  * Creates a form model given a token.
  *
  * @param  string $token
  * @param  array $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Password reset token cannot be blank.');
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException('Wrong password reset token.');
     }
     parent::__construct($config);
 }
예제 #4
0
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send();
         }
     }
     return false;
 }
예제 #5
0
파일: UserSearch.php 프로젝트: weiyiyi/base
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'last_login_time' => $this->last_login_time, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'delect' => $this->delect]);
     $query->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'zipcode', $this->zipcode])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'client_name', $this->client_name])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'state', $this->state])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'street', $this->street])->andFilterWhere(['like', 'time_zone', $this->time_zone])->andFilterWhere(['like', 'channels', $this->channels])->andFilterWhere(['like', 'register_ip', $this->register_ip])->andFilterWhere(['like', 'last_login_ip', $this->last_login_ip])->andFilterWhere(['like', 'avatar_img', $this->avatar_img])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'accessToken', $this->accessToken]);
     return $dataProvider;
 }
예제 #6
0
파일: UserSearch.php 프로젝트: apuc/api
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'money' => $this->money, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'cash_id', $this->cash_id])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'salt', $this->salt])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'photo', $this->photo]);
     return $dataProvider;
 }
예제 #7
0
파일: RegController.php 프로젝트: apuc/api
 public function actionForgot()
 {
     $this->layout = "no_login";
     if (Yii::$app->request->post()) {
         $user = \common\models\db\User::findByEmail(Yii::$app->request->post()['email']);
         if (!empty($user)) {
             $pass = $user->generateRandomPassword();
             $user->update();
             $msg = "<h3>Новый пароль выслан Вам на указанный Email</h3>";
             Email::sendForgotPass(Yii::$app->request->post()['email'], $pass);
         } else {
             $msg = "<h3>Пользователь с таким паролем не найден</h3>";
         }
         return $this->render('new_pass', ['msg' => $msg]);
     } else {
         return $this->render('forgot');
     }
 }
예제 #8
0
파일: User.php 프로젝트: weiyiyi/base
 public function rules()
 {
     return array_merge(parent::rules(), [[['email', 'password_hash', 'password2'], 'required'], ['password2', 'compare', "compareAttribute" => "password_hash", 'message' => '两次密码输入不一致.请重新输入'], ['password2', 'required', 'message' => '确认密码不能为空'], ['email', 'email', 'message' => '邮箱格式不对'], ['email', 'unique'], ['phone', 'match', 'pattern' => '/^[0-9]{10}$/']]);
 }
예제 #9
0
파일: Promotion.php 프로젝트: apuc/api
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
예제 #10
0
파일: Order.php 프로젝트: apuc/api
 public function addTask()
 {
     $db = Yii::$app->db;
     $user = User::findOne(['id' => $this->user_id]);
     $user->debitMoney($this->sum);
     $transaction = $db->beginTransaction();
     try {
         $user->save();
         $this->save();
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         return false;
     }
     return true;
 }
예제 #11
0
파일: UserController.php 프로젝트: apuc/api
 public function actionSetMoney($id)
 {
     $setMoney = new SetMoney();
     if ($setMoney->load(Yii::$app->request->post()) && $setMoney->validate()) {
         $setMoney->apply();
         return $this->redirect('index');
     }
     return $this->render('set_money', ['user' => User::findOne($id), 'model' => new SetMoney()]);
 }
예제 #12
0
파일: Payment.php 프로젝트: apuc/api
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCash()
 {
     return $this->hasOne(User::className(), ['id' => 'cash_id']);
 }