當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。