/** * 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; }
/** * 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->scenario = User::SCENARIO_CREATE; if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (!($role = User::getAuthItem($model->role))) { $model->addError('role', 'Role does not exist'); } else { $transaction = $model->getDb()->beginTransaction(); try { if ($model->save(false)) { if (!$model->assignRole()) { throw new Exception(); } if (!Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) { throw new Exception(); } $transaction->commit(); return $this->redirect('index'); } } catch (Exception $e) { $transaction->rollBack(); } } } return $this->render('create', ['model' => $model]); }
/** * 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->scenario = 'create'; $userData = new UserData(); //$hotelMapping = new UserHotelMapping(); if ($model->load(Yii::$app->request->post()) && $userData->load(Yii::$app->request->post())) { $validUser = $model->validate(); $validUserData = $userData->validate(); //$validHotelMapping = $hotelMapping->validate(); if ($validUser && $validUserData) { // && $validHotelMapping $model->setPassword($model->password); $model->generateAuthKey(); if ($model->save()) { $userData->user_id = $model->id; //$hotelMapping->user_id = $model->id; $userData->save(false); //$hotelMapping->save(false); return $this->redirect(['view', 'id' => $model->id]); } } } return $this->render('create', ['model' => $model, 'userData' => $userData]); }
/** * 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->validate()) { $model->setPassword($model->password); $model->generateAuthKey(); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new User(); if ($model->load(\Yii::$app->request->post())) { if ($model->validate() && $model->save()) { if ($model->new_password) { $this->savePassword($model); } return $this->redirect(['index']); } } return $this->render('form', ['model' => $model]); }
public function actionRequestPasswordReset() { $model = new User(); $model->scenario = 'requestPasswordResetToken'; if ($model->load($_POST) && $model->validate()) { if ($this->sendPasswordResetEmail($model->email)) { Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.'); $this->redirect('index'); } else { Yii::$app->getSession()->setFlash('error', 'There was an error sending email.'); } } return $this->render('requestPasswordResetToken', array('model' => $model)); }
/** * 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->scenario = 'create'; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->setPassword($model->new_password); $model->generateAuthKey(); if ($model->save(false)) { return $this->redirect(['view', 'id' => $model->id]); } } else { Yii::$app->getSession()->setFlash('error', "Please correct the mistakes and try again later."); return $this->render('create', ['model' => $model]); } }
/** * 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->scenario = 'create'; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->setPassword($model->password); $model->generateAuthKey(); // Force null $model->full_name = empty($model->full_name) ? null : $model->full_name; $model->save(); $auth = Yii::$app->authManager; $auth->assign($auth->getRole($model->role), $model->id); Yii::$app->getSession()->setFlash('user_create_success', ['type' => Growl::TYPE_SUCCESS, 'title' => '<b>' . Yii::t('backend', 'Success') . '</b>', 'icon' => 'glyphicon glyphicon-ok-sign', 'body' => '<strong>' . $model->username . '</strong> ' . Yii::t('backend', 'has been added.')]); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Broker model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Broker(); $user = new User(); $user->group_id = 2; $model->type_id = Yii::$app->request->get('type_id'); if ($model->load(Yii::$app->request->post()) && $user->load(Yii::$app->request->post())) { $model->user_id = 1; if ($model->validate() && $user->validate()) { $user->setPassword($user->password); $user->generateAuthKey(); if ($user->save()) { $model->user_id = $user->id; if ($model->save()) { return $this->redirect(['/broker']); } } } } return $this->render('create', ['model' => $model, 'user' => $user]); }
public function actionUpdate($id) { if ($id) { $model = User::findOne($id); if (!$model) { throw new NotFoundHttpException(); } } else { $model = new User(); } $passwordModel = new \common\forms\UserChangePassword(); if ($model->load(Yii::$app->request->post()) && $passwordModel->load(Yii::$app->request->post()) && $model->validate() && $passwordModel->validate()) { if (!empty($passwordModel->password)) { $model->password = $passwordModel->password; } $model->save(); Yii::$app->session->addFlash('success', 'Пользователь сохранен'); return $this->goBack(); } else { Yii::$app->user->returnUrl = Yii::$app->request->referrer; } return $this->render('update', ['model' => $model, 'passwordModel' => $passwordModel]); }
public function actionReset() { $this->layout = 'login'; $model = new User(); if ($model->load(Yii::$app->request->post())) { if ($_POST['User']) { $model->attributes = $_POST['User']; $valid = $model->validate(); if ($valid) { $model = User::find()->where(['email' => $_POST['User']['email']])->one(); $str = date('ymdhis') . 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('d'); $potong = str_shuffle($str); $random = substr($potong, 3, 8, 12); $model->setPassword($random); $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 password telah direset sebagai berikut:<br/> Username : '******' <br/> Password :<b>' . $random . '</b><br/> Mohon lakukan penggantian password Anda setelah melakukan login. <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'] => 'Aplikasi Simpel Bapeten'])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send(); $model->save(); return $this->redirect(['/site/login']); } } } return $this->render('reset', ['model' => $model]); }
public static function addUser($weixinUser) { #注册新用户 $newuser = new User(); $newuser->setAttribute('username', $weixinUser); $newuser->setAttribute('password', $newuser->generatePassword(self::generateRandString())); $newuser->setAttribute('wangwang', $weixinUser); if ($newuser->validate() && $newuser->save()) { $accountarray = array('user_id' => \Yii::$app->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0); $newAccount = new Account(); $newAccount->setAttributes($accountarray); $newAccount->save(); } $user = User::find()->where("username=:username", [":username" => $weixinUser])->one(); return $user; }
/** * 创建一个管理员用户 * @author Fufeng Nie <*****@*****.**> */ public function actionCreateAdmin() { echo ' ┏┓ ┏┓+ + ┏┛┻━━━┛┻┓ + + ┃ ┃ ┃ ━ ┃ ++ + + + ████━████ ┃+ ┃ ┃ + ┃ ┻ ┃ ┃ ┃ + + ┗━┓ ┏━┛ ┃ ┃ ┃ ┃ + + + + ┃ ┃ Code is far away from bug with the animal protecting ┃ ┃ + 神兽保佑,代码无bug ' . date('Y-m-d H:i:s') . ' ┃ ┃ ┃ ┃ + ┃ ┗━━━┓ + + ┃ ┣┓ ┃ ┏┛ ┗┓┓┏━┳┓┏┛ + + + + ┃┫┫ ┃┫┫ ┗┻┛ ┗┻┛+ + + +', "\n\n\n"; do { $username = trim($this->prompt('请酝酿一个用户名,并在此输入:')); if ($username !== '') { break; } $this->stdout("\n错误:用户名不能为空\n\n", Console::FG_RED, Console::UNDERLINE); } while (true); do { $email = trim($this->prompt("请给【{$username}】指定邮箱地址:")); if ($email !== '') { break; } $this->stdout("\n错误:邮箱地址不能为空\n\n", Console::FG_RED, Console::UNDERLINE); } while (true); do { $password = trim($this->prompt("请给【{$username}】设定密码,密码不得少于6位:")); if ($password !== '') { break; } $this->stdout("\n错误:不是给你说了密码不能少于6位么?\n\n", Console::FG_RED, Console::UNDERLINE); } while (true); $userModel = new User(); $userModel->username = $userModel->nickname = $username; $userModel->email = $email; $userModel->setPassword($password); $userModel->generateAuthKey(); $userModel->status = User::STATUS_ACTIVE; echo "\n正在验证你输入的数据。。。\n\n"; if (!$userModel->validate() || !$userModel->save()) { $this->stdout("发生了一些错误,你要有心理准备。。。\n\n", Console::FG_RED, Console::UNDERLINE); sleep(1); foreach ($userModel->getErrors() as $errors) { foreach ($errors as $error) { echo " {$error}\n"; } } echo "\n"; return 1; } echo "哎呀,我成了管理员啦,好紧张好激动啊!\n\n\n"; return 0; }