本文整理汇总了PHP中app\modules\user\models\User::save方法的典型用法代码示例。如果您正苦于以下问题:PHP User::save方法的具体用法?PHP User::save怎么用?PHP User::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\user\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()
{
$auth = Yii::$app->authManager;
$role = $auth->getRole($this->jabatan);
if ($this->validate() && !empty($role)) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->validate() && $user->save()) {
$person = new Person();
$person->first_name = $this->first_name;
$person->last_name = $this->last_name;
$person->gender = $this->gender;
$person->birth_date = $this->birth_date;
$person->user_id = $user->id;
if ($person->validate() && $person->save()) {
$auth->assign($role, $user->id);
return true;
}
}
}
return false;
}
示例2: 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->last_name = $this->last_name;
$user->first_name = $this->first_name;
$user->patronymic = $this->patronymic;
$user->email_work = $this->email_work;
$user->post_id = $this->post_id;
$user->department_id = $this->department_id;
$user->status_id = User::STATUS_WAIT;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->generateEmailConfirmToken();
if ($user->save()) {
// Присваиваем роль по умолчанию
//$auth = Yii::$app->authManager;
//$authorRole = $auth->getRole('user');
//$auth->assign($authorRole, $user->getId());
//Отправляем письмо с подтверждением
/*Yii::$app->mailer->compose('confirmEmail', ['user' => $user])
->setFrom([Yii::$app->params['app']['supportEmail'] => Yii::$app->params['app']['title']])
->setTo($this->email_work)
->setSubject('Email confirmation for ' . Yii::$app->name)
->send();
*/
Yii::$app->mailer->compose('confirmEmail', ['user' => $user])->setFrom([Yii::$app->params['app']['email'] => Yii::$app->params['app']['title']])->setTo($this->email_work)->setSubject('Email confirmation for ')->send();
}
return $user;
}
return null;
}
示例3: signup
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->status = User::STATUS_WAIT;
$user->generateAuthKey();
$user->generateEmailConfirmToken();
if ($user->save()) {
$auth = Yii::$app->authManager;
$userRoleDefault = $auth->getRole('user');
$auth->assign($userRoleDefault, $user->getId());
$userProfile = new Profile();
$userProfile->user_id = $user->getId();
$userProfile->user_agent = Yii::$app->request->getUserAgent();
$userProfile->user_ip = Yii::$app->request->getUserIP();
$userProfile->name = $user->username;
$userProfile->avatar_id = 1;
//default.png (id = 1)
$userProfile->save(false);
Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/emailConfirm'], ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(Module::t('app', 'EMAIL_SIGNUP_SUBJECT') . Yii::$app->name)->send();
}
return $user;
}
return null;
}
示例4: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$profile = new Profile();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->role = 'user';
$user->status = 1;
$profile->firstname = $this->firstname;
$profile->lastname = $this->lastname;
$profile->avatar = $this->avatar;
// $profile->gender = 0;
$transaction = Yii::$app->db->beginTransaction();
if ($user->save()) {
$profile->user_id = $user->getId();
if ($profile->save()) {
$transaction->commit();
return $user;
}
} else {
$transaction->rollback();
print_r($user->getErrors());
return false;
}
}
return null;
}
示例5: create
/**
* @param Configuration $config
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public static function create($config)
{
$language = substr(Yii::$app->language, 0, 2);
$db = Yii::$app->getDb();
// Settings
$db->createCommand()->batchInsert('{{%settings}}', ['group', 'name', 'value'], [['stock', 'outofstock', 0], ['stock', 'lowstock', 10], ['general', 'shopEmail', $config->shopEmail], ['general', 'adminEmail', $config->adminEmail]])->execute();
// Currencies
$db->createCommand()->batchInsert('{{%currency}}', ['code', 'name', 'is_default', 'rate', 'symbol'], [['EUR', 'Euro', 0, 0.0145, '€'], ['UAH', 'Hryvnia', 0, 0.3601, '₴'], ['RUB', 'Ruble', 1, 1, '₽'], ['USD', 'US Dollar', 0, 0.0158, '$']])->execute();
// Countries
static::callLocalized('countries', $language);
// Users
$root_auth_key = Yii::$app->security->generateRandomString();
$root_password = Yii::$app->security->generatePasswordHash($config->adminPassword);
$user = new User(['email' => $config->adminEmail, 'name' => 'admin', 'country_id' => 'us', 'address' => '7805 Southcrest Parkway, Southaven, MS(Mississippi) 38671', 'phone' => '(662) 349-7500', 'password_hash' => $root_password, 'auth_key' => $root_auth_key, 'role' => User::USER_ROLE_ADMIN]);
$user->save();
// Categories
static::callLocalized('categories', $language);
// Products
static::callLocalized('products', $language);
// Comments
static::callLocalized('comments', $language);
// Pages
static::callLocalized('pages', $language);
// News
static::callLocalized('news', $language);
// Relations
$db->createCommand()->batchInsert('{{%relation}}', ['item_id', 'related_id', 'model'], [[1, 2, 'Product'], [1, 3, 'Product'], [3, 1, 'Product'], [3, 2, 'Product']])->execute();
}
示例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();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例7: testSave
public function testSave()
{
$model = new User(['username' => 'test_user', 'email' => 'other@example.com', 'status' => 1]);
$model->setPassword('new-password');
expect('model is saved', $model->save())->true();
expect('password is correct', $model->validatePassword('new-password'))->true();
expect('auth key is correct', $model->auth_key)->notEmpty();
expect('created_at is correct', $model->created_at)->notEmpty();
expect('updated_at is correct', $model->updated_at)->notEmpty();
}
示例8: actionCreate
/**
* Creates a new Person model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Person();
$modelUser = new User();
$modelAuthRule = new AuthRule();
$modelAuthItem = new AuthItem();
$authRule = AuthRule::find()->all();
$authItem = AuthItem::find()->all();
if (Yii::$app->request->isPost) {
// do transaction if fails it will not saved
$transaction = Yii::$app->db->beginTransaction();
try {
if ($modelUser->load(Yii::$app->request->post()) && $modelUser->validate()) {
$modelUser->generateAuthKey();
// first attempt save user record
if ($modelUser->save()) {
if ($model->load(Yii::$app->request->post())) {
$model->user_id = $modelUser->id;
// second attemp save person record
if ($model->validate() && $model->save()) {
if ($modelAuthItem->load(Yii::$app->request->post()) && $modelAuthItem->validate()) {
$auth = Yii::$app->authManager;
$role = $auth->getRole($modelAuthItem->name);
if (!empty($role)) {
// thrid attemp assign role to user
$auth->assign($role, $modelUser->id);
$transaction->commit();
Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Karyawan Berhasil Disimpan'));
return $this->redirect(['index']);
} else {
throw new \Exception("AuthRole search data checkpoint fail to save");
}
} else {
throw new \Exception("AuthItem (Role) validation checkpoint fail to save");
}
} else {
throw new \Exception("Person save checkpoint fail to save");
}
} else {
throw new \Exception("Person loaded checkpoint fail to save");
}
} else {
throw new \Exception("User save checkpoint fail to save");
}
} else {
throw new \Exception("User validation checkpoint fail to save");
}
} catch (\Exception $e) {
$transaction->rollback();
Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Karyawan Gagal Disimpan'));
}
}
return $this->render('create', ['model' => $model, 'modelUser' => $modelUser, 'modelAuthRule' => $modelAuthRule, 'authRule' => $authRule, 'modelAuthItem' => $modelAuthItem, 'authItem' => $authItem]);
}
示例9: actionCreate
public function actionCreate()
{
$model = new User(['scenario' => 'admin-create']);
$statusArray = User::getStatusArray();
$roleArray = User::getRoleArray();
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('create', ['model' => $model, 'statusArray' => $statusArray, 'roleArray' => $roleArray]);
}
示例10: 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->status = User::STATUS_WAIT;
$user->generateAuthKey();
$user->generateEmailConfirmToken();
//
if ($user->save()) {
$auth = Yii::$app->authManager;
$role = $auth->getRole('client');
$auth->assign($role, $user->getId());
$confirmLink = Yii::$app->urlManager->createAbsoluteUrl(['user/default/confirm-email', 'token' => $user->email_confirm_token]);
$message = "Здравствуйте, " . Html::encode($user->username) . "!";
$message .= "Для подтверждения адреса пройдите по ссылке:";
//$message .= Html::a(Html::encode($confirmLink), $confirmLink) ;
$message .= $confirmLink;
$message .= " Если Вы не регистрировались у на нашем сайте, то просто удалите это письмо.";
// Отправляем
mail($user->email, 'Регистрация на сайте', $message);
// $mailer =Yii::$app->get('mailsmtp');
//
// $message =$mailer->compose('confirmEmail', ['user' => $user])
//
// ->setTo($this->email)
// ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])
// ->setSubject('Email confirmation for ' . Yii::$app->name);
//
// $message->getSwiftMessage()->getHeaders()->addTextHeader('name', 'value');
// $failures =null;
// try {
//
// if(!$mailer->send($message, $failures)) $errorCode=$failures; //отправляем
//
// }catch (\Swift_TransportException $e) { //проверяем на ошибки
// $pattern = '|got code "(.+?)", with|is';
// preg_match($pattern, $e->getMessage(), $out);
// $errorCode=$out[1];
// }
/*Yii::$app->mailer->compose('confirmEmail', ['user' => $user])
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])
->setTo($this->email)
->setSubject('Email confirmation for ' . Yii::$app->name)
->send();*/
}
return $user;
}
return null;
}
示例11: Register
public function Register()
{
if ($this->validate()) {
$user = new User();
$userProps['User'] = $this->getAttributes();
$user->load($userProps);
$user->save();
Yii::$app->user->login($user, 60 * 60 * 24 * 365);
return true;
} else {
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->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 ($model->load(Yii::$app->request->post())) {
$security = new Security();
$model->password = $security->generatePasswordHash(md5($model->password));
$model->auth_key = $security->generateRandomString(64);
$model->created_date = time();
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model]);
}
}
示例14: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate() === true) {
$user = new User();
$user->setScenario('signup');
$user->username = $this->username;
$user->password = $this->password;
$user->email = $this->email;
$user->generateAuthKey();
if ($user->save() === false) {
return null;
}
return $user;
}
return null;
}
示例15: 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->status = User::STATUS_WAIT;
$user->generateAuthKey();
$user->generateEmailConfirmToken();
if ($user->save()) {
Yii::$app->mailer->compose('confirmEmail', ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])->setTo($this->email)->setSubject('Email confirmation for ' . Yii::$app->name)->send();
}
return $user;
}
return null;
}