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


PHP models\User类代码示例

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


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

示例1: actionCreate

 /**
  * Anlegen eines Benutzers
  * 
  * @return \yii\web\View
  * @author KAS <kassel@weitkamper.de> 28.07.2015
  */
 public function actionCreate()
 {
     Yii::$app->view->params['headline'] = 'Benutzer anlegen';
     $model = new User();
     //----------------------------------------------------------------------
     $post = \Yii::$app->request->post();
     if ($model->load($post)) {
         $authArr = [];
         foreach ($post['Auth'] as $authData) {
             $authArr[] = new Auth($authData);
         }
         // Daten Validieren und Zuordnen -----------------------------------
         if (Model::loadMultiple($authArr, $post) && Model::validateMultiple($authArr)) {
             // aus den Auth Objekten machen wir arrays,
             // damit wir das in die Mongo speichern können
             $model->auth = array_map(function ($a) {
                 return $a->toArray();
             }, $authArr);
             // Speichern ---------------------------------------------------
             $model->save();
             // Benutzer benachrichtigen ------------------------------------
             \Yii::$app->session->setFlash('success', 'Benutzer wurde erfolgreich angelegt!', TRUE);
             // Neue Daten laden, da wir in den Models Veränderungen vornehmen
             $model->refresh();
         }
     }
     // Defaultwerte festlegen ----------------------------------------------
     $model->created_at = new \MongoDate();
     $model->updated_at = new \MongoDate();
     $model->role = "Normal";
     //----------------------------------------------------------------------
     return $this->render('create', ['model' => $model]);
 }
开发者ID:KasselR,项目名称:yii2-kr,代码行数:39,代码来源:UsersController.php

示例2: login

 protected function login($instance)
 {
     if ($instance->getEmail()) {
         $user = User::where('email', $instance->getEmail());
     } else {
         return view('site.login', ['msg' => 'The email address you used is not public. please try another login method']);
     }
     if ($user->exists()) {
         $user = $user->first();
         $updateUser = User::where('id', $user->id)->update(['image' => $instance->getAvatar()]);
         if (Auth::loginUsingId($user->id)) {
             return true;
         }
     } else {
         $pwd = explode('@', $instance->getEmail());
         $pwd = Hash::make($pwd[0] . uniqid());
         $newUser = new User();
         $newUser->name = $instance->getName();
         $newUser->email = $instance->getEmail();
         $newUser->image = $instance->getAvatar();
         $newUser->password = $pwd;
         $newUser->status = 0;
         $newUser->role = 'user';
         if ($newUser->save()) {
             Event::fire(new NewUserEvent($newUser));
             if (Auth::loginUsingId($newUser->id)) {
                 return true;
             }
         }
     }
 }
开发者ID:nahid,项目名称:nahid.co,代码行数:31,代码来源:LoginController.php

示例3: loginAction

 public function loginAction()
 {
     if (!is_null($this->session->getCurrentUser())) {
         $this->redirect('/');
     }
     if (is_null($this->request->getPost('user')) || is_null($this->request->getPost('password'))) {
         throw new LoginException('Неверные данные формы авторизации.');
     }
     $user = addslashes(trim(strip_tags($this->request->getPost('user'))));
     $password = addslashes(trim(strip_tags($this->request->getPost('password'))));
     $usersModel = new Users();
     try {
         $currentUser = $usersModel->getUsersDataByLogPass($user, $password);
     } catch (\Exception $e) {
         throw new LoginException($e->getMessage());
     }
     if ($currentUser['roles_id'] == self::BANNED) {
         throw new LoginException('Доступ временно запрещен. Обратитесь к администратору.');
     }
     unset($currentUser['password']);
     $userObj = new User();
     $userObj->fillData($currentUser);
     $this->session->setCurrentUser($userObj);
     echo json_encode(array('location' => '/'));
     exit;
 }
开发者ID:BoesesGenie,项目名称:team-rex,代码行数:26,代码来源:LoginController.php

示例4: actionDel

 public function actionDel()
 {
     $id = $_REQUEST['id'];
     $model = new User();
     $status = $model->getDel(['_id' => $id]);
     return $status;
 }
开发者ID:hardshen,项目名称:niuke,代码行数:7,代码来源:UserController.php

示例5: 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

示例6: actionRegister

 public function actionRegister()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new RegisterForm();
     $request = Yii::$app->request;
     $post = $request->post();
     if (isset($post)) {
         $model->attributes = $request->post('RegisterForm');
         if ($model->validate()) {
             //create user in DB
             $user = new User();
             $user->username = $model->username;
             $user->password = $model->password;
             $user->no_login = 0;
             $user->save();
             //perform login
             $login = new LoginForm();
             $login->username = $user->username;
             $login->password = $user->password;
             $login->login();
             return $this->goHome();
         }
     }
     return $this->render('register', ['model' => $model]);
 }
开发者ID:ren06,项目名称:calculator,代码行数:27,代码来源:SiteController.php

示例7: login

 protected function login($instance)
 {
     $user = User::where('email', $instance->getEmail());
     if ($user->exists()) {
         $user = $user->first();
         $updateUser = User::where('id', $user->id)->update(['image' => $instance->getAvatar()]);
         if (Auth::loginUsingId($user->id)) {
             return true;
         }
     } else {
         $pwd = explode('@', $instance->getEmail());
         $pwd = Hash::make($pwd[0] . uniqid());
         $newUser = new User();
         $newUser->name = $instance->getName();
         $newUser->email = $instance->getEmail();
         $newUser->image = $instance->getAvatar();
         $newUser->password = $pwd;
         $newUser->status = 0;
         $newUser->role = 'user';
         if ($newUser->save()) {
             if (Auth::loginUsingId($newUser->id)) {
                 return true;
             }
         }
     }
 }
开发者ID:MehmetNuri,项目名称:nahid.co,代码行数:26,代码来源:LoginController.php

示例8: manage

 public function manage(User $user, Project $project)
 {
     //dd($project);
     //return true;
     //dd( $user->role( 'admin' ));
     return $project->hasUser($user->id) || $user->role('admin');
 }
开发者ID:urands,项目名称:docbase,代码行数:7,代码来源:ProjectPolicy.php

示例9: withdrawPaypalPrepare

 public static function withdrawPaypalPrepare(User $user, $paypalEmail, $amount)
 {
     $withdrawal = Withdrawal::create(['user_id' => $user->id, 'merchant' => 'paypal', 'account' => $paypalEmail, 'amount' => $amount, 'currency' => 'USD', 'status' => 'waiting', 'transaction_number' => '']);
     $user->balance_blocked = $user->balance_blocked + $amount;
     $user->save();
     return $withdrawal;
 }
开发者ID:blozixdextr,项目名称:adtw,代码行数:7,代码来源:PaymentMapper.php

示例10: findByEAuth

 /**
  * @param \nodge\eauth\ServiceBase $service
  * @return User
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('EAuth user should be authenticated before creating identity.');
     }
     $service_id = $service->getServiceName() . '-' . $service->getId();
     // find user auth
     $user_auth = AuthRecords::find()->where(["id" => $service_id])->one();
     // make new auth record and create user
     if (!isset($user_auth->user_id)) {
         $attributes = $service->getAttributes();
         $nameFromService = isset($attributes['name']) ? $attributes['name'] : null;
         // add user
         $model = new User();
         $model->username = $nameFromService ? $nameFromService : $service_id;
         $model->auth_key = md5($service_id);
         // set default pass for direct account access
         $password = $model->generatePass();
         $model->password_hash = Yii::$app->security->generatePasswordHash($password);
         $model->save();
         $user_id = $model->id;
         // add auth
         $new_auth = new AuthRecords();
         $new_auth->id = $service_id;
         $new_auth->user_id = $user_id;
         $new_auth->attributes = serialize($service->getAttributes());
         $new_auth->save();
     } else {
         $user_id = $user_auth->user_id;
     }
     return user::findIdentity($user_id);
 }
开发者ID:ut8ia,项目名称:radioDoc,代码行数:37,代码来源:User.php

示例11: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->comment('欢迎使用drip, 现在我将引导您创建一个用户:');
     $data = [];
     $data['username'] = trim($this->ask('请输入您要使用的用户名'));
     $data['email'] = trim($this->ask('请输入您的电子邮箱'));
     $data['password'] = trim($this->ask('请输入您的密码,位数不得低于6位'));
     $data['password_confirmation'] = trim($this->ask('请再次确认您的密码'));
     if ($data['password'] !== $data['password_confirmation']) {
         return $this->error('两次密码输入不一致');
     }
     $validator = \Validator::make($data, ['username' => 'required|unique:users,username|max:32', 'email' => 'required|email|unique:users,email|max:191', 'password' => 'required|min:6|confirmed']);
     if ($validator->fails()) {
         foreach ($validator->errors()->all() as $field => $error) {
             $this->error($error);
         }
         return false;
     }
     $user = new User();
     $user->username = $user->nickname = $data['username'];
     $user->email = $data['email'];
     $user->password = bcrypt($data['password']);
     $user->status = User::STATUS_ACTIVE;
     if ($user->save()) {
         return $this->comment('创建用户成功, 您的用户ID为' . $user->id);
     }
     return $this->error('创建用户失败');
 }
开发者ID:niefufeng,项目名称:drip,代码行数:33,代码来源:CreateUser.php

示例12: actionSignup

 public function actionSignup()
 {
     $post = Application::request()->post();
     $warning = '';
     if (sizeof($post) > 0) {
         $model = new User();
         $model->load($post);
         $validation = $model->validate();
         if ($validation) {
             $user_id = $model->save();
             if ($user_id) {
                 Application::Identity()->signin($user_id);
                 $this->redirect('/search');
             } else {
                 $warning = 'Error adding row to DB';
             }
         } else {
             $warning = 'Please enter correct fields values';
         }
     }
     if (!Application::Identity()->check()) {
         $this->render('signup.html', ['salt' => Helper::generateCode(15), 'warning' => $warning]);
     } else {
         $this->redirect('/search');
     }
 }
开发者ID:dimichspb,项目名称:basic-users-app,代码行数:26,代码来源:UserController.php

示例13: actionInit

 public function actionInit()
 {
     $model = new User();
     $model->username = 'admin';
     $model->auth_key = 'OocVKRx-iludROmUFYj4HmxNeC8v0-FG';
     $model->password_hash = '$2y$13$0d3FeUDYGSyZft.3I77hV.E357FsqqAJFqaWPstWODMbdlSvxV2gC';
     $model->email = 'sintret@gmail.com';
     $model->phone = '6281575068530';
     $model->role = User::ROLE_ADMIN;
     $model->status = User::STATUS_ACTIVE;
     if ($model->save()) {
         echo 'success insert user, with usename:admin and password:123456';
     } else {
         echo json_encode($model->getErrors());
     }
     $setting = new Setting();
     $setting->emailAdmin = 'sintret@gmail.com';
     $setting->emailSupport = 'sintret@gmail.com';
     $setting->emailOrder = 'sintret@gmail.com';
     $setting->facebook = 'https://www.facebook.com/sintret';
     $setting->instagram = 'https://instagram.com/andyfitria/';
     $setting->google = 'https://google.com/sintret/';
     if ($setting->save()) {
         echo "\r\n success insert basic settings";
     } else {
         echo json_encode($setting->getErrors());
     }
 }
开发者ID:sintret,项目名称:yii2-basic,代码行数:28,代码来源:InsertController.php

示例14: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user_1 = new User();
     $user_1->name = 'tech';
     $user_1->email = 'tech@ordent.co';
     $user_1->password = \Hash::make('tech1234');
     $user_1->phone = '082214250262';
     $user_1->jabatan = 'Technical Administrator';
     $user_1->save();
     $user_2 = new User();
     $user_2->name = 'admin';
     $user_2->email = 'admin@ordent.co';
     $user_2->password = \Hash::make('admin1234');
     $user_2->phone = '082214250262';
     $user_2->jabatan = 'Management Administrator';
     $user_2->save();
     $role_1 = new Role();
     $role_1->name = 'tech';
     $role_1->display_name = 'tech';
     $role_1->description = 'Technical Administration';
     $role_1->save();
     $role_2 = new Role();
     $role_2->name = 'admin';
     $role_2->display_name = 'admin';
     $role_2->description = 'Management Administration';
     $role_2->save();
     $user_1->attachRole($role_1);
     $user_2->attachRole($role_2);
 }
开发者ID:k1m0ch1,项目名称:egor,代码行数:34,代码来源:UsersSeeder.php

示例15: 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


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