当前位置: 首页>>代码示例>>PHP>>正文


PHP User::save方法代码示例

本文整理汇总了PHP中common\models\User::save方法的典型用法代码示例。如果您正苦于以下问题:PHP User::save方法的具体用法?PHP User::save怎么用?PHP User::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\User的用法示例。


在下文中一共展示了User::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->first_name = $this->first_name;
         $user->last_name = $this->last_name;
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->save();
         //添加权限
         $permissionList = $_POST['SignupForm']['permissions'];
         foreach ($permissionList as $value) {
             $newPermission = new AuthAssignment();
             $newPermission->user_id = $user->id;
             $newPermission->item_name = $value;
             $newPermission->save();
             print_r($newPermission->getErrors());
         }
         //die;
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
开发者ID:oneword,项目名称:yii2DoingITeasyChannelCode,代码行数:32,代码来源:SignupForm.php

示例2: actionCreateuser

 public function actionCreateuser()
 {
     $userModel = User::findOne(['user_name' => yii::$app->request->post('user_name')]);
     if ($userModel === null) {
         $userModel = new User();
         $userModel->load(yii::$app->request->post());
         if ($userModel->save()) {
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User has been created'];
             yii::$app->UserComponent->sendWelcomeEmail($userModel->first_name, $userModel->email);
         } else {
             yii::$app->AjaxResponse->message = array_values($userModel->getErrors());
         }
     } else {
         // user exits but is not active
         if ($userModel->status_id != Types::$status['active']['id']) {
             $userModel->status_id = Types::$status['active']['id'];
             $userModel->save();
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User reactivated'];
         } else {
             yii::$app->AjaxResponse->message = ['User already exists'];
         }
     }
     yii::$app->AjaxResponse->sendContent();
 }
开发者ID:spiro-stathakis,项目名称:projects,代码行数:26,代码来源:AjaxController.php

示例3: resetPassword

 /**
  * Resets password.
  *
  * @return boolean if password was reset.
  */
 public function resetPassword()
 {
     if (!empty($this->password)) {
         $this->_user->password_hash = Yii::$app->security->generatePasswordHash($this->password);
     }
     return $this->_user->save();
 }
开发者ID:9618211,项目名称:walle-web,代码行数:12,代码来源:UserResetPasswordForm.php

示例4: actionCreate

 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $str = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('yyydmmdhis');
             $potong = str_shuffle($str);
             $random = substr($potong, 3, 12);
             $model->setPassword($random);
             $model->username = $_POST['User']['username'];
             $model->role = $_POST['User']['role'];
             $model->generateAuthKey();
             $content = '
                 <center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
                 <h4 align="center">Badan Pengawas Tenaga Nuklir  ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan akun telah terdaftar untuk masuk ke Sistem Aplikasi Perjalanan Dinas – BAPETEN, sebagai berikut:<br/> 
                 Username : ' . $model->username . ' <br/>
                 Password :<b>' . $random . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login.\\n
                 Terima Kasih. <hr/>
                 <h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN  ' . date('Y') . '</h5><br/>';
             Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => $model->username])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
             $model->save();
             return $this->redirect(['index']);
         } else {
             var_dump($model->errors);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:ilhammalik,项目名称:yii2-advanced-beta,代码行数:33,代码来源:UserController.php

示例5: actionCreate

 /**
  * Creates a new User model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new User();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['code' => '200', 'message' => 'Create User success'];
             } else {
                 return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
开发者ID:hdushku,项目名称:npai,代码行数:35,代码来源:UserController.php

示例6: generateToken

 public function generateToken()
 {
     $mobile = $this->_session['passwordResetMobile'];
     $this->_user = User::findByMobile($mobile);
     if (!User::isPasswordResetTokenValid($this->_user->password_reset_token)) {
         $this->_user->generatePasswordResetToken();
     }
     return $this->_user->save(false);
 }
开发者ID:daixianceng,项目名称:xiaoego.com,代码行数:9,代码来源:PasswordResetVerifyForm.php

示例7: resetPassword

 public function resetPassword()
 {
     $this->_user = User::findIdentity(Yii::$app->user->id);
     if (!Yii::$app->getSecurity()->validatePassword($this->password, $this->_user->password_hash)) {
         throw new InvalidParamException(Yii::t('User', 'source_password_error'));
     }
     $this->_user->setPassword($this->new_password);
     return $this->_user->save(false);
 }
开发者ID:duanbiaowu,项目名称:sailshop,代码行数:9,代码来源:ResetPasswordForm.php

示例8: resetPassword

 /**
  * Resets password.
  *
  * @return boolean if password was reset.
  */
 public function resetPassword()
 {
     $this->_user->setPassword($this->password);
     $this->_user->removePasswordResetToken();
     if ($this->_user->save()) {
         $this->_user->sendPasswordChangedEmail();
         return true;
     }
     return false;
 }
开发者ID:rocketyang,项目名称:admap,代码行数:15,代码来源:ResetPasswordForm.php

示例9: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     $model->setScenario('create_user');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->generatePasswordResetToken();
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     $model->status = User::STATUS_ACTIVE;
     $model->group = User::GROUP_READER;
     return $this->render('create', ['model' => $model]);
 }
开发者ID:specialnote,项目名称:myYii,代码行数:18,代码来源:UserController.php

示例10: actionUser

 /**
  * Create init user
  */
 public function actionUser()
 {
     echo "Create init user ...\n";
     // 提示当前操作
     $username = $this->prompt('User Name:');
     // 接收用户名
     $email = $this->prompt('Email:');
     // 接收Email
     $password = $this->prompt('Password:');
     // 接收密码
     $model = new User();
     // 创建一个新用户
     $model->username = $username;
     // 完成赋值
     $model->email = $email;
     $model->password = $password;
     if (!$model->save()) {
         foreach ($model->getErrors() as $error) {
             foreach ($error as $e) {
                 echo "{$e}\n";
             }
         }
         return 1;
         // 命令行返回1表示有异常
     }
     return 0;
     // 返回0表示一切OK
 }
开发者ID:packageman,项目名称:Yii2-advanced,代码行数:31,代码来源:InitController.php

示例11: signup

 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->phone = $this->phone;
         $user->setPassword($this->password);
         if (empty($this->username)) {
             $user->username = $this->phone;
         } else {
             $user->username = $this->username;
         }
         if (!empty($this->email)) {
             $user->email = $this->email;
         }
         #$user->generateAuthKey();
         $ret = $user->save();
         if (!$ret) {
             Yii::$app->getSession()->setFlash('error', '系统错误,注册失败。');
             return false;
         }
         return $user;
     }
     $error = array_pop($this->getErrors());
     Yii::$app->getSession()->setFlash('error', $error[0]);
     return false;
 }
开发者ID:johnny618,项目名称:love,代码行数:26,代码来源:SignupForm.php

示例12: signup

 /**
  * 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->validate()) {
             $broker = new Broker();
             $broker->user_id = 1;
             $broker->type_id = $this->type_id;
             $broker->name = $this->name;
             $broker->company = $this->company;
             $broker->phone = $this->phone;
             $broker->email = $this->email;
             $broker->address = $this->address;
             $broker->contact = $this->contact;
             $broker->recommend = $this->recommend;
             $broker->note_user = $this->note_user;
             $broker->sale_add = $this->sale_add;
             if ($broker->validate()) {
                 $user->save();
                 $broker->user_id = $user->id;
                 $broker->save();
                 return $user;
             }
         }
     }
     return null;
 }
开发者ID:dench,项目名称:resistor,代码行数:36,代码来源:SignupForm.php

示例13: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->gender = $this->gender;
         $user->firstname = $this->firstname;
         $user->lastname = $this->lastname;
         $user->username = $this->email;
         $user->email = $this->email;
         $user->birthday = $this->birthday;
         $user->user_role = $this->user_role;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             if ($user->user_role == 'host') {
                 $auth = Yii::$app->authManager;
                 $hostRole = $auth->getRole('host');
                 $auth->assign($hostRole, $user->id);
             } elseif ($user->user_role == 'traveller') {
                 $auth = Yii::$app->authManager;
                 $hostRole = $auth->getRole('traveller');
                 $auth->assign($hostRole, $user->id);
             }
             return $user;
         }
     }
     return null;
 }
开发者ID:Junaid-Farid,项目名称:staylance-new,代码行数:33,代码来源:SignupForm.php

示例14: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->nombre = $this->nombre;
         $user->apellido = $this->apellido;
         $user->username = $this->username;
         $user->email = $this->email;
         $user->cedula = $this->cedula;
         $user->supervisor = $this->supervisor;
         $user->id_division = $this->id_division;
         $user->id_organizacion = $this->id_organizacion;
         $user->id_empresa = $this->id_empresa;
         $user->departamento = $this->departamento;
         $user->id_aplicacion = $this->id_aplicacion;
         $user->id_distrito = $this->id_distrito;
         $user->telefono = $this->telefono;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
开发者ID:noeliovando,项目名称:yii2advance,代码行数:30,代码来源:SignupForm.php

示例15: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         $model->username = $_POST['User']['username'];
         $model->email = $_POST['User']['email'];
         $model->password = $_POST['User']['password'];
         $model->setPassword($_POST['User']['password']);
         $model->generateAuthKey();
         $model->fname = $_POST['User']['fname'];
         $model->lname = $_POST['User']['lname'];
         $model->groupid = $_POST['User']['groupid'];
         $model->departmentid = $_POST['User']['departmentid'];
         //  $model->roleid = $_POST['User']['roleid'];
         $model->roleid = 2;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             print_r($model->getErrors());
         }
         //            if ($id = $model->signup() ) {
         //                return $this->redirect(['view', 'id' => $id->id]);
         //            }
         //            if(is_null($model->signup())){
         //              //  echo "Value is null";
         //                print_r($model->getErrors());
         //            }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:nirantarnoy,项目名称:paperless,代码行数:35,代码来源:UserController.php


注:本文中的common\models\User::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。