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


PHP User::findByUsername方法代码示例

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


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

示例1: beforeValidate

 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         if ($this->scenario == 'user-update') {
             // Верификация должностей и пользователей
             foreach ($this->position as $key => $positionId) {
                 if (!isset($this->user[$key])) {
                     continue;
                 }
                 if (!($position = Position::findOne($positionId))) {
                     continue;
                 }
                 if (is_numeric($this->user[$key])) {
                     $user = User::findIdentity($this->user[$key]);
                 } else {
                     $user = User::findByUsername(trim($this->user[$key]));
                 }
                 if (!$user) {
                     continue;
                 }
                 $this->_verifyPositions[] = ['positionId' => $position->id, 'userId' => $user->id];
             }
             if (empty($this->_verifyPositions)) {
                 $this->addError('position', 'Вы должны указать минимум одну должность');
             }
         }
         return true;
     }
     return false;
 }
开发者ID:NikDevPHP,项目名称:yii2-test-job,代码行数:33,代码来源:ProjectForm.php

示例2: getUser

 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username, sha1($this->password));
     }
     return $this->_user;
 }
开发者ID:kiril-malyhin,项目名称:BagPack-,代码行数:7,代码来源:LoginForm.php

示例3: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
开发者ID:andegas,项目名称:oppo_basic,代码行数:12,代码来源:LoginForm.php

示例4: getUser

 /**
  * Finds user by session's 'username'.
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername(Yii::$app->session->get('username'));
     }
     return $this->_user;
 }
开发者ID:bizley,项目名称:yii2-partial-password,代码行数:12,代码来源:PasswordForm.php

示例5: validateUsernameUnique

 public function validateUsernameUnique()
 {
     $user = User::findByUsername($this->username);
     if ($user) {
         $this->addError('username', 'Username must be unique.');
     }
 }
开发者ID:sevenzhou1218,项目名称:YiiTest,代码行数:7,代码来源:RegisterForm.php

示例6: getUser

 /**
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user !== null) {
         return $this->_user;
     }
     return $this->_user = User::findByUsername($this->email);
 }
开发者ID:remk-wadriga,项目名称:calories-calculating-yii2-project,代码行数:10,代码来源:RegistrationForm.php

示例7: actionAssignRole

 public function actionAssignRole($username, $roleName)
 {
     $user = User::findByUsername($username);
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($roleName);
     $auth->assign($role, $user);
 }
开发者ID:gustik,项目名称:yii2-app-light,代码行数:7,代码来源:RbacController.php

示例8: testAUserCanBeFoundByUsername

 public function testAUserCanBeFoundByUsername()
 {
     $createdUser = factory(User::class)->create(['username' => 'janedoe', 'name' => 'Jane Doe', 'created_timestamp_utc' => 1, 'updated_timestamp_utc' => 1]);
     $foundUser = User::findByUsername('janedoe');
     $this->assertEquals($createdUser->id, $foundUser->id);
     $this->assertEquals($createdUser->username, $foundUser->username);
 }
开发者ID:murribu,项目名称:crossword,代码行数:7,代码来源:UserTest.php

示例9: actionIndex

 public function actionIndex()
 {
     //没登录就回到主页
     if (Yii::$app->user->isGuest) {
         return $this->render('/site/index');
     }
     //没加入队伍就到/team/error页面
     if (User::findByUsername(Yii::$app->user->identity->username)->teamname == "") {
         return $this->render('/team/error', ['message' => '<h2>你还没有加入任何一个战队呢!</h2>']);
     }
     $myteamname = User::findByUsername(Yii::$app->user->identity->username)->teamname;
     $myteam = Team::findOne(['teamname' => $myteamname]);
     //上传文件
     $model = new UploadForm();
     if (Yii::$app->request->isPost) {
         if ($myteam->uploaded_time < 50) {
             $model->sourcecode = UploadedFile::getInstance($model, 'sourcecode');
             if ($id = $model->upload()) {
                 $myteam->uploaded_time++;
                 $myteam->save(false);
                 //上传成功就render到uploadsuccess页面
                 return $this->render('uploadsuccess', ['id' => $id]);
             }
         }
     }
     //上传文件$model,
     return $this->render('index', ['model' => $model, 'myteam' => $myteam]);
     //,'indexs'=>$indexs]);
 }
开发者ID:eesast,项目名称:ts17web,代码行数:29,代码来源:OnlineCompileController.php

示例10: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
开发者ID:ho96,项目名称:yii2-advanced-admin,代码行数:12,代码来源:LoginForm.php

示例11: actionUser

 /**
  * регистрация юзера по имейл
  * если регистрация для покупки, то передаются параметры рекомендатель и урл
  * @param type $affiliate_id
  * @param type $url_id
  * @return type
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionUser($affiliate_id = null, $url_id = null)
 {
     $request = Yii::$app->request;
     $model = new \app\models\registration\UserForm();
     if ($request->isAjax && $model->load($request->post())) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load($request->post()) && $model->validate()) {
         $user = User::findByUsername($model->email);
         if (!$user) {
             $user = $model->save();
         }
         $user->setCookie();
         if ($affiliate_id === null || $url_id === null) {
             Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту');
             return $this->goHome();
         }
         $url = Url::findOne($url_id);
         if (!$url) {
             throw new \yii\web\NotFoundHttpException('Урл не найден');
         }
         $user->purchase($affiliate_id, $url);
         return $this->redirect($url->link);
     }
     return $this->render('user', ['model' => $model]);
 }
开发者ID:nicdnepr,项目名称:skidos,代码行数:35,代码来源:RegistrationController.php

示例12: actionPerson

 public function actionPerson()
 {
     $user = User::findByUsername('123');
     var_dump($user);
     die;
     return $this->render('person');
 }
开发者ID:akucherevskiy,项目名称:on-home,代码行数:7,代码来源:SiteController.php

示例13: actionIndex

 public function actionIndex()
 {
     //没登录就回到主页
     if (Yii::$app->user->isGuest) {
         return $this->render('/site/index');
     }
     //没加入队伍就到/team/error页面
     if (User::findByUsername(Yii::$app->user->identity->username)->teamname == "") {
         return $this->render('/team/error', ['message' => '<h2>你还没有加入任何一个战队呢!</h2>']);
     }
     $myteamname = User::findByUsername(Yii::$app->user->identity->username)->teamname;
     $myteam = Team::findOne(['teamname' => $myteamname]);
     //上传文件
     $model = new UploadForm();
     if (Yii::$app->request->isPost) {
         if ($myteam->uploaded_time < 50) {
             $model->sourcecode = UploadedFile::getInstance($model, 'sourcecode');
             if ($id = $model->upload_first_round()) {
                 return $this->render('uploadsuccess');
             }
         }
     }
     $alreadysubmit = Firstroundcodes::find()->where(array('teamid' => $myteam->id))->exists();
     //上传文件$model,
     return $this->render('index', ['model' => $model, 'alreadysubmit' => $alreadysubmit, 'myteam' => $myteam]);
     //,'indexs'=>$indexs]);
 }
开发者ID:eesast,项目名称:ts17web,代码行数:27,代码来源:FirstroundsubmitController.php

示例14: getUser

 /**
  * Возвращает пользователя
  * @return User|null|static
  */
 protected function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->login);
     }
     return $this->_user;
 }
开发者ID:serj1chen,项目名称:accident_uawebchallenge,代码行数:11,代码来源:LoginForm.php

示例15: actionLogin

 /**
  * @return string
  */
 public function actionLogin($username)
 {
     $user = User::findByUsername($username);
     if (Yii::$app->user->login($user, 0)) {
         return $this->redirect(['/adm/user/update']);
     }
     return Adm::goBack(['/adm/user/update']);
 }
开发者ID:pavlinter,项目名称:yii2-app-core,代码行数:11,代码来源:DefaultController.php


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