Beispiel #1
0
 public function reg()
 {
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     return $user->save() ? $user : null;
 }
Beispiel #2
0
 /**
  * 创建用户
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword('123456');
         $model->generateAuthKey();
         //$model->signup();
         $ret = $model->save();
         if ($ret) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new User();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create";
             $log->object_class = "User";
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $model->created_at = $now;
         $model->dob = strtotime($model->dob);
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         if (!empty($data['user-image'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $model->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => [[120, 120], [200, 200]], 'resizeType' => 2, 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $model->image = $copyResult['imageName'];
             }
         }
         // User class
         $model->generateAuthKey();
         $model->setPassword($model->password);
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
Beispiel #5
0
 public function resetpwd()
 {
     $token = \Yii::$app->request->get('token', '');
     $dtoken = base64_decode($token);
     $number = substr($dtoken, 29);
     $uid = \Yii::$app->request->get('uid', '');
     $sName = \Yii::$app->session['ruserName'] ?: \Yii::$app->user->identity->username;
     $newToken = substr(md5($sName . $uid . $number), 0, 29) . $number;
     if ($newToken != $dtoken) {
         $this->addError('repwd', '页面超时,请重新登陆后,再修改密码!');
         return false;
     }
     if ($_POST['LoginForm']['pwd'] != $_POST['LoginForm']['repwd']) {
         $this->addError('repwd', '两次密码不一致,请重新输入!');
         return false;
     }
     if (mb_strlen($_POST['LoginForm']['pwd']) < 6) {
         $this->addError('repwd', '新密码长度至少6位');
         return false;
     }
     $user = new User();
     $user->setPassword($_POST['LoginForm']['pwd'], $uid);
     return true;
 }