本文整理汇总了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;
}
示例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();
}
示例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();
}
示例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]);
}
}
示例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]);
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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]);
}
示例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
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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]);
}