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


PHP User::save方法代码示例

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


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

示例1: handle

 /**
  * Execute the job.
  *
  * @param JWT $jwt
  * @param Carbon $carbon
  * @return String
  */
 public function handle(JWT $jwt, Carbon $carbon)
 {
     $timestamp = $carbon->now()->timestamp;
     $data = collect($this->user->toArray())->only('id')->merge(compact('timestamp'));
     $token = $jwt->encode($data, env('APP_KEY'));
     /**
      * Save token on the user model
      */
     if ($this->saveToken) {
         $this->user->setAttribute('api_token', $token);
         $this->user->save();
     }
     return $token;
 }
开发者ID:SkysoulDesign,项目名称:mirage.dev,代码行数:21,代码来源:GenerateTokenJob.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     $person = new User();
     $person->first_name = $request->input('first-name');
     $person->last_name = $request->input('last-name');
     $person->email = $request->input('work-email');
     $person->personal_email = $request->input('personal-email');
     $person->password = Hash::make(uniqid());
     $person->address1 = $request->input('address-one');
     $person->address2 = $request->input('address-two');
     $person->zip = $request->input('postcode');
     $person->city = $request->input('city');
     $person->state = $request->input('state');
     $person->country = $request->input('country');
     $person->dob = Carbon::createFromFormat('d/m/Y', $request->input('dob'))->toDateString();
     $person->work_telephone = $request->input('work-telephone');
     $person->personal_telephone = $request->input('personal-telephone');
     $person->gender = $request->input('gender');
     $person->save();
     // Placeholder face until one is submitted
     $path = 'people/' . $person->id . '/face.jpg';
     \Illuminate\Support\Facades\Storage::put($path, file_get_contents('http://api.adorable.io/avatar/400/' . md5($person->id . $person->email . Carbon::now()->getTimestamp()) . ''));
     $person->save();
     // Default job position
     $person->jobPositions()->attach(1, ['primary' => true]);
     // Default role
     $person->roles()->attach(1, ['primary' => true]);
     return redirect()->intended('/people/');
 }
开发者ID:TeenageHelpline,项目名称:Progress,代码行数:36,代码来源:UserController.php

示例3: resetPassword

 /**
  * Resets password
  *
  * @return boolean
  */
 public function resetPassword()
 {
     $this->user->setPassword($this->password);
     $this->user->removePasswordResetToken();
     $this->user->authorize(true);
     return $this->user->save(false);
 }
开发者ID:rkit,项目名称:bootstrap-yii2,代码行数:12,代码来源:ResetPasswordForm.php

示例4: 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 ['title' => "Create new User", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['forceReload' => '#crud-datatable-pjax', 'title' => "Create new User", 'content' => '<span class="text-success">Create User success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
             } else {
                 return ['title' => "Create new User", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } 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:javierojeda94,项目名称:sas_final,代码行数:35,代码来源:UserController.php

示例5: register

 public function register()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->password = Yii::$app->getSecurity()->generatePasswordHash($this->password);
         $user->realname = $this->realname;
         $user->email = $this->email;
         $user->school = $this->school;
         $user->class = $this->class;
         $user->studentnumber = $this->studentnumber;
         $user->created_at = date("Y-m-d H:i:s");
         $user->updated_at = date("Y-m-d H:i:s");
         $user->status = 1;
         $user->group = 'player';
         $user->save(true);
         if ($user->save(true)) {
             //true调用User里的rules方法进行二次验证
             return $user;
         } else {
             var_dump($user->errors);
         }
         return null;
     }
 }
开发者ID:eesast,项目名称:ts17web,代码行数:25,代码来源:RegisterForm.php

示例6: handle

 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name');
     $this->user->email = $this->request->input('email');
     $this->user->password = bcrypt($this->request->input('password'));
     $role = Role::whereName(Role::getAdministratorName())->firstOrFail();
     if ($this->user->save()) {
         $this->user->assignRole($role);
         return true;
     }
     return false;
 }
开发者ID:stevebauman,项目名称:administration,代码行数:17,代码来源:Finish.php

示例7: handle

 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name');
     $this->user->email = $this->request->input('email');
     $password = $this->request->input('password');
     // If the user doesn't have a set password mutator,
     // we'll encrypt the password.
     if (!$this->user->hasSetMutator('password')) {
         $password = bcrypt($password);
     }
     $this->user->password = $password;
     return $this->user->save();
 }
开发者ID:stevebauman,项目名称:administration,代码行数:18,代码来源:Store.php

示例8: onAuthSuccess

 public function onAuthSuccess($client)
 {
     $attributes = $client->getUserAttributes();
     /* @var $auth Auth */
     $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             $user = $auth->user;
             Yii::$app->user->login($user);
         } else {
             $password = Yii::$app->security->generateRandomString(6);
             $user = new User(['username' => $attributes['name'], 'email' => $attributes['email'], 'password' => $password]);
             if ($user->save()) {
                 $auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]);
                 if ($auth->save()) {
                     Yii::$app->user->login($user);
                 }
             }
         }
     } elseif (!$auth) {
         $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
         $auth->save();
     }
     $this->action->successUrl = Url::to(['/']);
     // GRAB POSTS
     Fbposts::grabSocial($client);
 }
开发者ID:IuriiP,项目名称:test160106,代码行数:27,代码来源:SiteController.php

示例9: actionRacer

 public function actionRacer()
 {
     $user = new User();
     $racer = new Racer();
     $races = Race::findAll(['status' => 'PENDING']);
     if ($user->load(Yii::$app->request->post()) && $racer->load(Yii::$app->request->post())) {
         $user->type = 'RACER';
         $user->status = 'ACTIVE';
         $user->password = hash('sha256', $user->identity);
         $user->creation_date = date('Y-m-d H:i:s');
         if ($user->save()) {
             $racer->place = strtoupper($racer->place);
             $racer->user_id = $user->id;
             $racer->creation_date = date('Y-m-d H:i:s');
             if ($racer->save()) {
                 Yii::$app->session->setFlash('racerCreated');
                 return $this->redirect(['racer']);
             } else {
                 Yii::$app->session->setFlash('errorRacer', array_values($racer->getFirstErrors())[0]);
             }
         } else {
             Yii::$app->session->setFlash('errorRacer', array_values($user->getFirstErrors())[0]);
         }
     }
     return $this->render('racer', ['user' => $user, 'racer' => $racer, 'races' => $races]);
 }
开发者ID:frankpaul142,项目名称:aurasur,代码行数:26,代码来源:UserController.php

示例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->generateAuthKey();
         $user->mobile = $this->mobile;
         $user->user_extra1 = $this->user_extra1;
         //上传用户信息图片, 多文件上传, 最多2张图
         $tmpStr2 = "";
         $this->files = UploadedFile::getInstances($this, 'files');
         foreach ($this->files as $file) {
             //$user->files = UploadedFile::getInstances($user, 'files');
             //foreach ($user->files as $file)
             //{
             $targetFileId = date("YmdHis") . '-' . uniqid();
             $ext = pathinfo($file->name, PATHINFO_EXTENSION);
             $targetFileName = "{$targetFileId}.{$ext}";
             $targetFile = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . SignupForm::PHOTO_PATH . DIRECTORY_SEPARATOR . $targetFileName;
             $file->saveAs($targetFile);
             //$tmpStr2 =  $tmpStr2 . "{$targetFile};";
             $tmpStr2 = $tmpStr2 . "/user/photo/{$targetFileName};";
         }
         $user->user_extra2 = $tmpStr2;
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
开发者ID:hehbhehb,项目名称:hongsong,代码行数:37,代码来源:SignupForm.php

示例11: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $user = new User();
     $user->fill(['name' => 'Erick Mo', 'email' => 'mo@thunderlab.id', 'password' => '123123123']);
     $user->save();
 }
开发者ID:ThunderID,项目名称:Halo,代码行数:12,代码来源:UserTableSeeder.php

示例12: handleRegister

 /**
  * @return mixed
  */
 public function handleRegister()
 {
     $rules = ['first_name' => 'required|min:3', 'last_name' => 'required|min:3', 'email' => 'unique:User:email|required|email', 'confirm-email' => 'required|email|equalTo:email', 'agree' => 'required', 'password' => 'required|min:3', 'confirm-password' => 'required|equalTo:password', 'join_list' => 'required'];
     $errors = $this->validate($rules);
     if (sizeof($errors) > 0) {
         $html = $this->blade->with('session', $this->session)->withTemplate('register')->render();
         $new_html = $this->repopulateForm($html, $errors, $this->request->getParameters());
         return $this->response->setContent($new_html);
     } else {
         $user = new User();
         $user->email = $this->request->getParameter('email');
         $user->password = password_hash($this->request->getParameter('password'), PASSWORD_DEFAULT);
         $user->save();
         $user_id = $user->id;
         $registration = new Registration();
         $registration->user_id = $user_id;
         $registration->first_name = $this->request->getParameter('first_name');
         $registration->last_name = $this->request->getParameter('last_name');
         $registration->colour = $this->request->getParameter('colour');
         $registration->comments = $this->request->getParameter('comments');
         $registration->join_list = $this->request->getParameter('join_list');
         $registration->save();
         return $this->response->setContent($this->blade->with('session', $this->session)->render("generic-page", ['content' => 'Thanks for joining our site!', 'title' => 'Thanks!']));
     }
 }
开发者ID:tsawler,项目名称:intermediate-php-course,代码行数:28,代码来源:RegisterController.php

示例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();
     $model->active = true;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($model->rol == 'Básico') {
             $auth = Yii::$app->authManager;
             $roles = $auth->getRole('Básico');
             $auth->assign($roles, $model->id);
         }
         if ($model->rol == 'Operador') {
             $auth = Yii::$app->authManager;
             $roles = $auth->getRole('Operador');
             $auth->assign($roles, $model->id);
         }
         if ($model->rol == 'Administrador') {
             $auth = Yii::$app->authManager;
             $roles = $auth->getRole('Administrador');
             $auth->assign($roles, $model->id);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:rodespsan,项目名称:FMAT-SAECC,代码行数:30,代码来源:UserController.php

示例14: reset

 public function reset(User $user)
 {
     $newPassword = $this->generatePassword();
     $user->password = $newPassword;
     $user->save();
     $this->smsGateway->send($user->telephone, $this->getMessage($newPassword));
 }
开发者ID:sasik-github,项目名称:system.pro,代码行数:7,代码来源:PasswordReseter.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()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $model = new User();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $email = new Email();
            $email->to_name = $model->name;
            $email->to_email = $model->email;
            $email->subject = "Your Tixty Purchase";
            $message = <<<EOT
Hi {$model->name}!!

You just registered as a user. Use {$model->email} to login with the password you chose and start buying tickets at <a href="https://tixty.co.uk/">tixty.co.uk</a>

Thanks,

Tixty
EOT;
            $email->body = nl2br($message);
            $email->save();
            $email->send();
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', ['model' => $model]);
        }
    }
开发者ID:yodathedark,项目名称:moltis-tickets,代码行数:33,代码来源:UserController.php


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