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


PHP User::findOne方法代码示例

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


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

示例1: ur_questions

 /**
  * @throws \PhpOffice\PhpWord\Exception\Exception
  * Создание word для юр вопросов
  */
 public static function ur_questions($row)
 {
     $user = User::findOne(\Yii::$app->user->identity->id);
     $file = \Yii::$app->basePath . '/temp/ur_questions/' . $row['qid'] . '.docx';
     $template = \Yii::$app->basePath . '/temp/ur_questions/Template.docx';
     $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($template);
     // Variables on different parts of document
     $row['question'] = str_replace("\n", "<w:br/>", $row['question']);
     //Для пробелов
     $templateProcessor->setValue('vopros', $row['question']);
     $templateProcessor->setValue('date', date("d.m.Y"));
     $templateProcessor->setValue('ur_name', $row['uname']);
     $templateProcessor->setValue('ur_ruk', $row['contact_face']);
     $templateProcessor->setValue('ur_phone', $row['contact_phone']);
     $templateProcessor->setValue('ur_mail', $row['contact_mail']);
     $templateProcessor->setValue('ur_region', $row['rname']);
     //$templateProcessor->setValue('serverName', realpath(__DIR__)); // On header
     $templateProcessor->saveAs($file);
     $qf = explode("|", $row['qfiles']);
     if (!isset($qf[0])) {
         $qf[0] = $qf;
     }
     $mail = \Yii::$app->mail->compose('ur_questions', ['uname' => $row['uname'], 'username' => $user['username'], 'mail' => $user['mail']])->setFrom([\Yii::$app->params['infoEmail'] => 'СоюзФарма'])->setTo(\Yii::$app->params['uristEmail'])->setSubject('Юридический вопрос')->attach($file);
     foreach ($qf as $q) {
         if ($q != "") {
             $mail->attach($q);
         }
     }
     $mail->send();
     // if($templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx')) {
     //      return true;
     //  }else{
     //    return false;
     // }
 }
开发者ID:pumi11,项目名称:aau,代码行数:39,代码来源:Word.php

示例2: doOauthLogin

 public function doOauthLogin($oauthClient)
 {
     $code = Yii::$app->request->get('code', false);
     if (!$code) {
         $url = $oauthClient->buildAuthUrl();
         // Build authorization URL
         Yii::$app->getResponse()->redirect($url);
         // Redirect to authorization URL.
     }
     // After user returns at our site:
     $accessToken = $oauthClient->fetchAccessToken($code);
     // Get access token
     $res = $oauthClient->api('index');
     $parts = parse_url($oauthClient->tokenUrl);
     $User = User::findOne(['username' => $res['username'], 'host' => $parts['host']]);
     if (!$User) {
         $User = new User();
         $User->username = $res['username'];
         $User->host = $parts['host'];
         $User->save();
     }
     $success = Yii::$app->user->login($User, 3600 * 24 * 30);
     //var_dump($success, Yii::$app->user);
     if (Yii::$app->session["_last_game"]) {
         return $this->redirect(Yii::$app->session["_last_game"]);
     } else {
         return $this->goHome();
     }
 }
开发者ID:francisberesford,项目名称:econosim-game,代码行数:29,代码来源:SiteController.php

示例3: actionShow

 /**
  * Shows user's profile.
  * @param  integer $id
  * @return \yii\web\Response
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionShow($id)
 {
     $this->enableCsrfValidation = false;
     $profile = $this->finder->findProfileById($id);
     if ($profile === null) {
         throw new NotFoundHttpException();
     }
     $query = Comments::find()->where(['deleted' => Comments::NO_DELETED, 'user_id' => $id])->orderBy('created_at');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->setPageSize(10);
     $comments = $query->offset($pages->offset)->limit($pages->limit)->all();
     $model = new Comments();
     $this->performAjaxValidation($model);
     $user = User::findOne(Yii::$app->user->getId());
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = time();
         $model->user_id = $profile->user->getId();
         $model->sender_id = Yii::$app->user->getId();
         $model->save();
         return $this->refresh();
     } else {
         return $this->render('show', ['profile' => $profile, 'model' => $model, 'user' => $user, 'comments' => $comments, 'pages' => $pages]);
     }
     return $this->render('show', ['profile' => $profile]);
 }
开发者ID:boozzd,项目名称:bulletin_board,代码行数:32,代码来源:ProfileController.php

示例4: findModel

 /**
  * @param string $username
  * @throws \yii\console\Exception
  * @return User the loaded model
  */
 private function findModel($username)
 {
     if (!($model = User::findOne(['username' => $username]))) {
         throw new Exception('User not found');
     }
     return $model;
 }
开发者ID:GT-Volk,项目名称:ManagerOrganizer,代码行数:12,代码来源:UsersController.php

示例5: getUser

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

示例6: sendMail

 public function sendMail()
 {
     /* @var $user User */
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             $setting = Setting::find()->where(['id' => 1])->one();
             $username = $setting->sendgridUsername;
             $password = $setting->sendgridPassword;
             $mail_admin = $setting->emailAdmin;
             $sendgrid = new \SendGrid($username, $password, array("turn_off_ssl_verification" => true));
             $email = new \SendGrid\Email();
             $mail = $user->email;
             //echo $user->email;exit(0);
             $resetLink = \Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
             $body_message = 'Hello ' . Html::encode($user->username) . ', <br>
             Follow the link below to reset your password:  <br>
             ' . Html::a(Html::encode($resetLink), $resetLink);
             $email->addTo($user->email)->setFrom($mail_admin)->setSubject('Password reset for ' . \Yii::$app->name)->setHtml($body_message);
             $response = $sendgrid->send($email);
             //print_r($response); exit(0);
             return $response;
         }
     }
     return false;
 }
开发者ID:sintret,项目名称:yii2-basic,代码行数:29,代码来源:PasswordResetRequestForm.php

示例7: save

 public function save()
 {
     $this->deletedIdList = [];
     $this->errorIdList = [];
     if ($this->hasErrors()) {
         return false;
     }
     if (!($user = User::findOne(['api_key' => $this->apikey]))) {
         $this->addError('apikey', 'User does not exist.');
         return false;
     }
     foreach ($this->id as $id) {
         $battle = Battle::findOne(['id' => (int) (string) $id]);
         if (!$battle) {
             $this->errorIdList[] = ['id' => $id, 'error' => 'not found'];
             continue;
         }
         if ($battle->user_id != $user->id) {
             $this->errorIdList[] = ['id' => $id, 'error' => 'user not match'];
             continue;
         }
         if ($battle->is_automated) {
             $this->errorIdList[] = ['id' => $id, 'error' => 'automated result'];
             continue;
         }
         if (!$this->test) {
             $battle->delete();
         }
         $this->deletedIdList[] = ['id' => $id, 'error' => null];
     }
     return true;
 }
开发者ID:frozenpandaman,项目名称:stat.ink,代码行数:32,代码来源:DeleteBattleForm.php

示例8: getUser

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

示例9: validateEmail

 public function validateEmail()
 {
     $user = User::findOne(['email' => $this->email]);
     if ($user != null) {
         $this->addError('email', 'E-mail znajduje się już w bazie');
     }
 }
开发者ID:vodas,项目名称:praktykigda,代码行数:7,代码来源:RegisterForm.php

示例10: testTimestampBehavior

 public function testTimestampBehavior()
 {
     $this->specify('create and update time are set on creation', function () {
         $user = new User(['username' => 'test', 'email' => 'test@example.com', 'password' => 'testpw']);
         $time = time();
         expect('new record can be saved', $user->save())->true();
         $user = User::findOne($user->id);
         expect('saved record can be found', $user)->notNull();
         expect('creation time is a datetime string', preg_match(self::DATE_PATTERN, $user->created_at))->equals(1);
         expect('update time is a datetime string', preg_match(self::DATE_PATTERN, $user->updated_at))->equals(1);
         expect('creation time is set correctly', strtotime($user->created_at))->greaterOrEquals($time);
         expect('update time is set correctly', strtotime($user->updated_at))->greaterOrEquals($time);
     });
     $this->specify('only update time is set on update', function () {
         $user = $this->users('default');
         $user->username = 'modified';
         $created_at = $user->created_at;
         $updated_at = $user->updated_at;
         $time = time();
         expect('user record can be updated', $user->save())->true();
         $user = User::findOne($user->id);
         expect('updated record can be found', $user)->notNull();
         expect('creation time is unchanged', $user->created_at)->equals($created_at);
         expect('update time is updated', $user->updated_at)->notEquals($updated_at);
         expect('update time is a datetime string', preg_match(self::DATE_PATTERN, $user->updated_at))->equals(1);
         expect('update time is set correctly', strtotime($user->updated_at))->greaterOrEquals($time);
     });
 }
开发者ID:maxwelldu,项目名称:yii2-dockerized,代码行数:28,代码来源:TimestampBehaviorTest.php

示例11: actionInit

 /**
  *
  */
 public function actionInit()
 {
     // assign roles
     $oAuthManager = \Yii::$app->authManager;
     $oAuthManager->removeAll();
     // role user
     $oRoleUser = $oAuthManager->createRole('user');
     $oRoleUser->description = 'Registered user';
     $oAuthManager->add($oRoleUser);
     // create default users
     $aDefaultUser = \Yii::$app->params['aDefaultUser'];
     $oSecurity = \Yii::$app->security;
     foreach ($aDefaultUser as $sUsername => $aUserData) {
         $mUser = User::findOne(['username' => $aUserData['username']]);
         if (!$mUser) {
             $mUser = new User();
             $mUser->username = $sUsername;
             $mUser->password = $oSecurity->generatePasswordHash($aUserData['password']);
             $mUser->email = $aUserData['email'];
             $mUser->authKey = $oSecurity->generateRandomString();
         }
         if ($mUser->validate()) {
             $mUser->save();
             // assign role to each
             $oAuthManager->assign($oAuthManager->getRole($aUserData['role']), $mUser->id);
         }
     }
 }
开发者ID:Sywooch,项目名称:EVE-Manager-Yii-2.x,代码行数:31,代码来源:RbacController.php

示例12: run

 public function run()
 {
     Yii::$app->response->format = 'json';
     $request = Yii::$app->getRequest();
     $screenName = $request->get('screen_name');
     $user = null;
     if ($screenName != '') {
         if (is_scalar($screenName) && ($user = User::findOne(['screen_name' => $screenName]))) {
             // ok
         } else {
             return ['error' => ['screen_name' => ['not found']]];
         }
     }
     $now = @$_SERVER['REQUEST_TIME'] ?: time();
     $subQuery = (new \yii\db\Query())->select(['id' => 'MAX({{battle}}.[[id]])'])->from('battle')->andWhere(['>=', '{{battle}}.[[at]]', gmdate('Y-m-d H:i:sO', $now - 60 * 86400)])->groupBy('{{battle}}.[[user_id]]');
     if ($user) {
         $subQuery->andWhere(['{{battle}}.[[user_id]]' => $user->id]);
     }
     $battles = Battle::find()->andWhere(['in', '{{battle}}.[[id]]', $subQuery])->with(['user', 'user.userStat', 'lobby', 'rule', 'map', 'weapon', 'weapon.subweapon', 'weapon.special', 'rank', 'battleImageResult', 'battleImageJudge'])->limit(500)->orderBy('{{battle}}.[[id]] DESC');
     $ret = [];
     foreach ($battles->each() as $model) {
         $json = $model->user->toJsonArray();
         $json['latest_battle'] = $model->toJsonArray(['user', 'death_reasons']);
         $ret[] = $json;
     }
     if ($user) {
         return count($ret) >= 1 ? array_shift($ret) : null;
     }
     return $ret;
 }
开发者ID:Bochozkar,项目名称:stat.ink,代码行数:30,代码来源:UserAction.php

示例13: run

 public function run()
 {
     $request = Yii::$app->getRequest();
     $user = User::findOne(['screen_name' => $request->get('screen_name')]);
     if (!$user) {
         throw new NotFoundHttpException(Yii::t('app', 'Could not find user'));
     }
     // リスト表示モード切替
     if ($request->get('v') != '') {
         $view = $request->get('v');
         if ($view === 'simple' || $view === 'standard') {
             Yii::$app->response->cookies->add(new Cookie(['name' => 'battle-list', 'value' => $view, 'expire' => time() + 86400 * 366]));
         }
         $next = $_GET;
         unset($next['v']);
         $next[0] = 'show/user';
         $this->controller->redirect(Url::to($next));
         return;
     }
     $battle = Battle::find()->with(['lobby', 'rule', 'rule.mode', 'map', 'weapon', 'weapon.subweapon', 'weapon.special', 'rank', 'rankAfter']);
     $filter = new BattleFilterForm();
     $filter->load($_GET);
     $filter->screen_name = $user->screen_name;
     if ($filter->validate()) {
         $battle->filter($filter);
     }
     $summary = $battle->summary;
     $permLink = Url::to(array_merge(['show/user', 'screen_name' => $user->screen_name], $filter->hasErrors() ? [] : $filter->toPermLink()), true);
     $isPjax = $request->isPjax;
     $template = $this->viewMode === 'simple' ? 'user.simple.tpl' : 'user.tpl';
     return $this->controller->render($template, array_merge(['user' => $user, 'battleDataProvider' => new ActiveDataProvider(['query' => $battle, 'pagination' => ['pageSize' => 100]]), 'summary' => $summary, 'filter' => $filter, 'permLink' => $permLink], $this->makeFilterFormData($user)));
 }
开发者ID:Bochozkar,项目名称:stat.ink,代码行数:32,代码来源:UserAction.php

示例14: getUser

 /**
  * Finds user by [[id]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findOne(\Yii::$app->user->id);
     }
     return $this->_user;
 }
开发者ID:mops1k,项目名称:yiimine,代码行数:12,代码来源:ChangePasswordForm.php

示例15: actionEditUser

 public function actionEditUser()
 {
     $user = Yii::$app->user->identity;
     $user_pass = User::findOne($user->id);
     $user->scenario = 'edit-user';
     $user_pass->scenario = 'edit-password';
     $user_pass->password = "";
     $session = Yii::$app->session;
     $post = Yii::$app->request->post();
     $msg = false;
     if (isset($post['editUser'])) {
         // Безопасное присваивание значений атрибутам
         $user->attributes = $post['User'];
         if ($user->validate()) {
             $user->save(false);
             $session->setFlash('successEditUser', "Учетные данные успешно сохранены!");
         }
     }
     if (isset($post['editPassword'])) {
         $user_pass->attributes = $post['User'];
         if ($user_pass->validate()) {
             $user_pass->save(false);
             $session->setFlash('successEditUser', "Пароль успешно изменен!");
         }
     }
     if ($session->hasFlash('successEditUser')) {
         $msg = $session->getFlash('successEditUser');
     }
     $user_pass->password = "";
     $user_pass->password_repeat = "";
     return $this->render('editUser', ['user' => $user, 'user_pass' => $user_pass, 'msg' => $msg]);
 }
开发者ID:a7000q,项目名称:yasvoboden,代码行数:32,代码来源:UserController.php


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