本文整理汇总了PHP中backend\models\User::save方法的典型用法代码示例。如果您正苦于以下问题:PHP User::save方法的具体用法?PHP User::save怎么用?PHP User::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backend\models\User
的用法示例。
在下文中一共展示了User::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Create a new user
*
* <b>Request Type</b>: POST<br/><br/>
* <b>Request Endpoint</b>:http://{server-domain}/management/user<br/><br/>
* <b>Content-type</b>: application/json<br/><br/>
* <b>Summary</b>: This api is used for billing account to create a new user
* <br/><br/>
*
* <b>Request Params</b>:<br/>
* email: string, the user email, required<br/>
* role: string, the user role, required<br/>
* <br/><br/>
*
* <b>Response Params:</b><br/>
* ack: integer, mark the create result, 0 means create successfully, 1 means create fail<br/>
* data: array, json array to describe the user created<br/>
* <br/><br/>
*
* <b>Request Example:</b><br/>
* <pre>
* {
* "email" : "sarazhang@augmentum.com.cn",
* "role" : "admin"
* }
* </pre>
* <br/><br/>
*
* <b>Response Example</b>:<br/>
* <pre>
* {
* 'ack' : 1,
* 'data': {"msg": "您当前已成功发送验证邮件到sarazhang@augmentum.com.cn邮箱中", "user": {name:"Devin Jin", avatar:"path/to/avatar", email:"sarazhang@augmentum.com.cn", isActivated:false}}
* }
* </pre>
*/
public function actionCreate()
{
$params = $this->getParams();
if (empty($params['email'])) {
throw new InvalidParameterException(['email' => Yii::t('common', 'email_is_required')]);
}
$params['email'] = mb_strtolower($params['email']);
if (!StringUtil::isEmail($params['email'])) {
throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_format_wrong')]);
}
$user = User::getByEmail($params['email']);
if (!empty($user)) {
throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_has_used')]);
}
$user = new User();
$user->email = $params['email'];
$user->role = $params['role'];
$user->avatar = Yii::$app->params['defaultAvatar'];
$user->isActivated = User::NOT_ACTIVATED;
$user->accountId = $this->getAccountId();
if ($user->save()) {
$currentUser = $this->getUser();
$link = Yii::$app->request->hostInfo . '/site/invite/code?type=2';
//type=2 means invite user account
$result = EmailUtil::sendInviteEmail($user, $currentUser->name, $link, self::SUBJECT);
if ($result) {
return ['user' => $user];
} else {
throw new ServerErrorHttpException("validation save fail");
}
}
throw new ServerErrorHttpException("create user fail");
}
示例2: save
public function save($runValidation = true, $attributeNames = null)
{
if ($this->new_password) {
$this->setPassword($this->new_password);
}
return parent::save($runValidation, $attributeNames);
}
示例3: 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(['scenario' => 'signup']);
$model1 = new AmgenContactListvalidate();
if ($model->load(Yii::$app->request->post()) && $model1->load(Yii::$app->request->post()) && $model->validate() && $model1->validate()) {
$fname = $_POST['AmgenContactListvalidate']['first_name'];
$lname = $_POST['AmgenContactListvalidate']['last_name'];
$model1->first_name = $fname;
$model1->last_name = $lname;
$model1->Title = $_POST['AmgenContactListvalidate']['Title'];
$model1->function_Id = $_POST['AmgenContactListvalidate']['function_Id'];
$model1->group_Id = $_POST['AmgenContactListvalidate']['group_Id'];
$model1->Phone = $_POST['AmgenContactListvalidate']['Phone'];
$model1->speciality = $_POST['AmgenContactListvalidate']['speciality'];
$fullname = $fname . " " . $lname;
$model1->Name = $fullname;
if ($model1->save()) {
$id = $model1->id;
$password = $_POST['User']['password_hash'];
$hash = Yii::$app->getSecurity()->generatePasswordHash($password);
$model->password_hash = $hash;
//generating password hash
$model->attendee_id = $id;
$model->first_name = $fname;
$model->last_name = $lname;
$model->save();
Yii::$app->session->setFlash('success', 'User Sucessfully Created');
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model, 'model1' => $model1]);
}
}
示例4: actionCreate
public function actionCreate()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$model = new User();
$model->username = Yii::$app->request->post('name');
$model->email = Yii::$app->request->post('email');
$model->pass1 = Yii::$app->request->post('pass1');
$model->pass2 = Yii::$app->request->post('pass2');
$model->role = 1;
$model->created_at = time();
$model->auth_key = Yii::$app->security->generateRandomString();
$user = User::find()->where(['username' => $model->username])->one();
$mail = User::find()->where(['email' => $model->email])->one();
if (!$model->pass1 === $model->pass2) {
return ['status' => 'error', 'error' => array('password' => 'Passwords must be identical.')];
} elseif ($user) {
return ['status' => 'error', 'error' => array('login' => 'User with login ' . $model->username . ' already registered.')];
} elseif ($mail) {
return ['status' => 'error', 'error' => array('email' => 'User with login ' . $model->email . ' already registered.')];
} elseif ($model->save()) {
$model->role == 2 ? Yii::$app->authManager->assign(Yii::$app->authManager->getRole('admin'), $model->id) : Yii::$app->authManager->assign(Yii::$app->authManager->getRole('user'), $model->id);
return ['status' => 'success', 'data' => $model];
} else {
return ['status' => 'error', 'data' => $model];
}
}
示例5: 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->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例6: 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(['scenario' => 'admin-create']);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->authManager->assign(Yii::$app->authManager->getRole($model->role), $model->id);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例7: reg
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;
}
示例8: 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->save()) {
// Yii::$app->Controllers->activity_user("[CREATE COS]");
Yii::$app->Controllers->historyUserWithData($model);
echo 1;
} else {
return $this->renderAjax('create', ['model' => $model]);
}
}
示例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()
{
//if(!Yii::$app->user->can('createUser')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
$model = new User(['scenario' => 'admin-create']);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
//Yii::$app->authManager->assign(Yii::$app->authManager->getRole($model->role), $model->id);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例10: 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->auth_key = Yii::$app->security->generateRandomString();
$model->password_hash = Yii::$app->security->generatePasswordHash($model->newpass);
$model->password_reset_token = NULL;
$model->save();
$this->actionApprole($model->id, 'user');
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'admin' => true]);
}
}
示例11: actionCreate
/**
* 创建用户
*
* @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]);
}
示例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->save()) {
return $user;
}
}
return null;
}
示例13: 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 (Yii::$app->request->isPost) {
$model->load(Yii::$app->request->post());
if ($model->save()) {
$userdata = new WooUserData();
$userdata->user_id = $model->id;
$userdata->user_name = "Unset";
$userdata->user_lastname = "Unset";
$model->link("woouserdata", $userdata);
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model]);
}
}
示例14: create
/**
* 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;
}
示例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()
{
if (Yii::$app->user->can('createUser')) {
$model = new User();
if ($model->load(Yii::$app->request->post())) {
$lastInsertID = $model->getPrimaryKey();
$model->id = $lastInsertID;
$model->password_hash = Yii::$app->security->generatePasswordHash($_POST['User']['password_hash']);
$model->created_at = time();
$model->updated_at = time();
$model->save(false);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
} else {
throw new ForbiddenHttpException();
}
}