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


PHP models\User类代码示例

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


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

示例1: actionCreate

 /**
  * Creates a new SocialServiceManager model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new SocialServiceManager();
     if ($model->load(Yii::$app->request->post())) {
         $person = new Person();
         $person->name = $model->name;
         $person->lastname = $model->last_name;
         $person->phone = $model->phone;
         $person->save(false);
         $user = new User();
         $user->username = $model->username;
         $user->password = $model->password;
         $user->email = $model->email;
         $user->person_id = $person->id;
         $user->scenario = 'register';
         if ($user->validate(['username', 'password'])) {
             $user->register();
             $model->user_id = $user->id;
             $model->save(false);
             //assign the role to the user
             $authManager = Yii::$app->getAuthManager();
             $socialServiceMRole = $authManager->getRole('socialServiceManager');
             $authManager->assign($socialServiceMRole, $user->id);
             //set the success message
             Yii::$app->getSession()->setFlash('success', 'Usuario creado con éxito');
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             $model->addErrors($user->errors);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:RomarioLopezC,项目名称:RobotSS,代码行数:37,代码来源:SocialServiceManagerController.php

示例2: loadAttributes

 public function loadAttributes(User $user)
 {
     $user->setAttributes($this->attributes);
     $profile = \Yii::createObject(Profile::className());
     $profile->setAttributes(['name' => $this->name]);
     $user->setProfile($profile);
 }
开发者ID:Uthpala,项目名称:doingiteasychannel,代码行数:7,代码来源:RegistrationForm.php

示例3: loadAttributes

 /**
  * @inheritdoc
  */
 protected function loadAttributes(\dektrium\user\models\User $user)
 {
     $user->setAttributes(['email' => $this->email, 'username' => $this->username, 'password' => $this->password]);
     $profile = \Yii::createObject(Profile::className());
     $profile->setAttributes(['name' => ucwords(strtolower($this->firstname)) . " " . ucwords(strtolower($this->lastname)), 'firstname' => ucwords(strtolower($this->firstname)), 'lastname' => ucwords(strtolower($this->lastname)), 'birthday' => $this->birthday, 'terms' => $this->terms]);
     $user->setProfile($profile);
 }
开发者ID:cinghie,项目名称:yii2-user-extended,代码行数:10,代码来源:RegistrationForm.php

示例4: rules

 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'exist', 'targetClass' => $this->module->manager->userClass, 'message' => \Yii::t('user', 'There is no user with such email.')], ['email', function ($attribute) {
         $this->_user = $this->module->manager->findUserByEmail($this->email);
         if ($this->_user !== null && $this->getModule()->enableConfirmation && !$this->_user->getIsConfirmed()) {
             $this->addError($attribute, \Yii::t('user', 'You need to confirm your email address'));
         }
     }]];
 }
开发者ID:ilyar,项目名称:dektrium-yii2-user,代码行数:12,代码来源:RecoveryRequestForm.php

示例5: rules

 /** @inheritdoc */
 public function rules()
 {
     return ['emailTrim' => ['email', 'filter', 'filter' => 'trim'], 'emailRequired' => ['email', 'required'], 'emailPattern' => ['email', 'email'], 'emailExist' => ['email', 'exist', 'targetClass' => $this->module->modelMap['User'], 'message' => \Yii::t('user', 'There is no user with this email address')], 'emailUnconfirmed' => ['email', function ($attribute) {
         $this->user = $this->finder->findUserByEmail($this->email);
         if ($this->user !== null && $this->module->enableConfirmation && !$this->user->getIsConfirmed()) {
             $this->addError($attribute, \Yii::t('user', 'You need to confirm your email address'));
         }
     }], 'passwordRequired' => ['password', 'required'], 'passwordLength' => ['password', 'string', 'min' => 6]];
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:10,代码来源:RecoveryForm.php

示例6: actionConnect

 public function actionConnect($account_id)
 {
     //var_dump("connect");die;
     $account = $this->finder->findAccountById($account_id);
     if ($account === null || $account->getIsConnected()) {
         throw new NotFoundHttpException();
     }
     /** @var User $user */
     $user = \Yii::createObject(['class' => User::className(), 'scenario' => 'connect']);
     if (\Yii::$app->request->get("provider") == 'kd') {
         $data = array();
         $data['User'] = array();
         $data['User']['username'] = \Yii::$app->request->get("username");
         $data['User']['email'] = \Yii::$app->request->get("email");
     } else {
         $data = \Yii::$app->request->post();
     }
     if ($user->load($data) && $user->create()) {
         $account->user_id = $user->id;
         $account->save(false);
         \Yii::$app->user->login($user, $this->module->rememberFor);
         return $this->goBack();
     }
     return $this->render('connect', ['model' => $user, 'account' => $account]);
 }
开发者ID:kd-brinex,项目名称:kd,代码行数:25,代码来源:RegistrationController.php

示例7: safeDown

 public function safeDown()
 {
     $controller = Yii::$app->controller;
     $model = \Yii::createObject(LoginForm::className());
     do {
         if ($model->hasErrors()) {
             $this->showErrors($model);
         }
         // get username
         $username = $controller->prompt($controller->ansiFormat("\tUsername: ", \yii\helpers\Console::FG_BLUE));
         // get password
         echo $controller->ansiFormat("\tPassword: ", \yii\helpers\Console::FG_BLUE);
         system('stty -echo');
         $password = trim(fgets(STDIN));
         system('stty echo');
         echo "\n";
         $model->login = $username;
         $model->password = $password;
     } while (!$model->validate());
     $user = User::findOne(['username' => $username]);
     if (empty($user)) {
         throw new \yii\console\Exception("Unable to find user {$username}");
     }
     $this->delete('{{%auth_assignment}}', ['item_name' => 'admin', 'user_id' => $user->primaryKey]);
     $user->delete();
 }
开发者ID:hector-del-rio,项目名称:yii2-attache,代码行数:26,代码来源:m150805_191756_yii2user_add_admin_user.php

示例8: checkUserSetup

 private static function checkUserSetup()
 {
     if (UserModel::find()->where('id != 1')->count() == 0) {
         $link = Html::a('user module', ['/user/admin/create']);
         \Yii::$app->session->addFlash('warning', "There is no additional user registered, visit {$link} to create an editor.");
     }
 }
开发者ID:7flash,项目名称:app,代码行数:7,代码来源:Helper.php

示例9: findModel

 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:kapilbhadke,项目名称:ConnectMe,代码行数:8,代码来源:ConnectMeUserController.php

示例10: actionFollowings

 public function actionFollowings($id)
 {
     $followings = FollowerUsertoUser::find()->where(['follower_user_id' => $id])->all();
     $following_users_ids = ArrayHelper::getColumn($followings, 'followed_user_id');
     $query = User::find()->where(['id' => $following_users_ids]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('index', ['models' => $models, 'caller' => $id, 'callerType' => 'Followings']);
 }
开发者ID:KhemPoudel,项目名称:onlinePaathsaala,代码行数:10,代码来源:FollowController.php

示例11: login

 /**
  * Validates form and logs the user in.
  *
  * @return bool whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         if (Yii::$app->getUser()->login($this->user, $this->rememberMe ? $this->module->rememberFor : 0)) {
             UserLog::log("login-success");
             $this->user->last_login = gmdate("Y-m-d H:i:s");
             $this->user->save();
             return true;
         } else {
             return false;
         }
     } else {
         $message = '';
         foreach ($this->errors['login'] as $error) {
             $message .= $error . "\n";
         }
         UserLog::log("login-failure", $message);
         return false;
     }
 }
开发者ID:lnch,项目名称:yii2-user-control,代码行数:25,代码来源:LoginForm.php

示例12: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'index' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     /** @var User $user */
     $user = Yii::createObject(['class' => User::className(), 'scenario' => 'create']);
     $this->performAjaxValidation($user);
     if ($user->load(Yii::$app->request->post()) && $user->create()) {
         Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User has been created'));
         return $this->redirect(['update', 'id' => $user->id]);
     }
     return $this->render('create', ['user' => $user]);
 }
开发者ID:ketuker,项目名称:oil-palm-cultivation-thesis,代码行数:17,代码来源:AdminController.php

示例13: register

 /**
  * Registers a new user account.
  * @return bool
  */
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->user->setAttributes(['email' => $this->email, 'username' => $this->username, 'password' => $this->password]);
     return $this->user->register();
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:12,代码来源:RegistrationForm.php

示例14: rules

 public function rules()
 {
     $rules = parent::rules();
     // add some rules
     $rules['vmlistLength'] = ['vmlist', 'string', 'max' => 255];
     return $rules;
 }
开发者ID:serveurexpress,项目名称:vmpanel,代码行数:7,代码来源:User.php

示例15: afterSave

 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         UcenterUtil::register($this->username, $this->password, $this->email);
     }
 }
开发者ID:buuug7,项目名称:game4039,代码行数:7,代码来源:User.php


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