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


PHP User::findOne方法代码示例

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


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

示例1: getUser

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

示例2: actionAdd

 public function actionAdd($password, $discuz_uid, $type = 'User')
 {
     //TODO 这个之后一定要写进配置文件而非硬编码
     if ($password !== 'ngpt_2333') {
         Yii::warning("Wrong Password!!!!!!" . $password . "uid : {$discuz_uid}");
         return ['result' => 'failed', 'extra' => 'wrong password'];
     }
     if (is_numeric($discuz_uid) && intval($discuz_uid) <= 0) {
         Yii::warning("uid not a number : {$discuz_uid}");
         return ['result' => 'failed', 'extra' => 'discuz_uid should be numeric'];
     }
     $discuz_uid = intval($discuz_uid);
     /** @var User $user */
     $user = User::findOne(['discuz_user_id' => $discuz_uid]);
     if (!empty($user)) {
         return ['result' => 'succeed', 'extra' => $user->passkey];
     }
     $user = new User();
     $user->discuz_user_id = $discuz_uid;
     $user->passkey = User::genPasskey();
     Yii::info($user->attributes);
     if ($user->insert()) {
         return ['result' => 'succeed', 'extra' => $user->passkey];
     } else {
         Yii::warning("Insert to user table failed");
         return ['result' => 'failed', 'extra' => 'Database error'];
     }
 }
开发者ID:KKRainbow,项目名称:ngpt_seed,代码行数:28,代码来源:UserController.php

示例3: findPasswords

 public function findPasswords($attribute, $params)
 {
     $user = User::findOne(Yii::$app->user->getId());
     if (!Yii::$app->getSecurity()->validatePassword($this->oldpass, $user->password_hash)) {
         $this->addError($attribute, Yii::t('app/user', 'Old password is incorrect'));
     }
 }
开发者ID:vilariel,项目名称:remisesramallo,代码行数:7,代码来源:PasswordForm.php

示例4: findModel

 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:BillsOfHealth,项目名称:yii2-2015,代码行数:15,代码来源:UserController.php

示例5: getCurrentUser

 /**
  * @param integer $id
  *
  * @return array|boolean
  */
 public static function getCurrentUser($id)
 {
     /** @var $user User */
     $user = User::findOne(['id' => $id]);
     if (isset($user)) {
         return $user;
     }
     return false;
 }
开发者ID:TF03,项目名称:yii2-advanced-def,代码行数:14,代码来源:UserHelper.php

示例6: updateUserByUserId

 public function updateUserByUserId($userId, $email, $realName, $sex, $birthday)
 {
     $result = User::findOne($userId);
     if ($result) {
         $result->email = $email;
         $result->realName = $realName;
         $result->sex = $sex;
         $result->birthday = $birthday;
         $result->update();
     }
 }
开发者ID:jaybril,项目名称:www.mimgpotea.com,代码行数:11,代码来源:User.php

示例7: _updateUserStatus

 private function _updateUserStatus($id, $status)
 {
     $user = User::findOne(['braintree_customer_id' => $id]);
     if ($user) {
         $old_status = $user->status;
         $user->status = $status;
         if ($user->save()) {
             file_put_contents("webhook.log", "User {$id} status updated from '{$old_status}' to '{$status}'", FILE_APPEND);
         }
     }
 }
开发者ID:skamnev,项目名称:members,代码行数:11,代码来源:BraintreeWebhooksController.php

示例8: sendEmail

 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @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()) {
             return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send();
         }
     }
     return false;
 }
开发者ID:CTaiDeng,项目名称:funshop,代码行数:19,代码来源:PasswordResetRequestForm.php

示例9: checkAccount

 public function checkAccount()
 {
     $ev = new EmailValidator();
     if ($ev->validate($this->account)) {
         $model = User::findOne(['email' => $this->account]);
         if ($model != null) {
             $this->id = $model->id;
         }
         return $model;
     } else {
         $model = User::findOne(['username' => $this->account]);
         if ($model != null) {
             $this->id = $model->id;
         }
         return $model;
     }
 }
开发者ID:buuug7,项目名称:game4039,代码行数:17,代码来源:KefuAccountRepairCheckAccountForm.php

示例10: actionResetPassword

 public function actionResetPassword()
 {
     if (!Yii::$app->request->isPost) {
         exit('Invalid Request');
     }
     // $user = new User();
     $data = Yii::$app->request->post();
     if (!isset($data['user_id']) || empty($data['user_id'])) {
         exit('Request Data Error');
     }
     $user = User::findOne($data['user_id']);
     $user->password = $this->reset_password($data['passwrd'], $user->salt);
     $result = $user->save();
     if ($result) {
         $url = Url::toRoute(['site/index'], true);
         return $this->redirect($url);
     } else {
         exit('Update Error');
     }
 }
开发者ID:songhongyu,项目名称:datecenter,代码行数:20,代码来源:RegisterController.php

示例11: buildTorrentFile

 /**
  * @param string $infoPath
  * @param string $mainTracker
  * @param array $backupTracker
  */
 public static function buildTorrentFile($infoPath, $mainTracker, $backupTracker)
 {
     $be = new BEncoder();
     $info = file_get_contents($infoPath);
     $info = $be->decode($info);
     if (empty($info)) {
         return null;
     }
     /** @var User $user */
     $user = User::findOne(Yii::$app->user->getId());
     $passkey = $user->passkey;
     $seed = [];
     $seed['announce'] = $mainTracker . "passkey={$passkey}";
     foreach ($backupTracker as $tracker) {
         $seed['announce-list'] = $tracker . "passkey={$passkey}";
     }
     $seed['created date'] = $seed['created by'] = time();
     $seed['comment'] = 'Welcome To NGPT';
     $seed['encoding'] = 'UTF-8';
     $seed['info'] = $info;
     return $be->encode($seed);
 }
开发者ID:KKRainbow,项目名称:ngpt_seed,代码行数:27,代码来源:TorrentFileTool.php

示例12: actionSetCoef

 /**
  * @param int $seed_id
  * @param int $upcoe
  * @param int $downcoe
  * @param int $duration 该系数的持续时间,后面会转换成到期时间,0表示永久
  * @param string $reason
  * @return array
  * @throws \Exception
  */
 public function actionSetCoef($seed_id, $upcoe, $downcoe, $duration, $reason, $replace)
 {
     $ret = [];
     $ret['result'] = 'failed';
     if (!is_numeric($upcoe) || !is_numeric($downcoe) || !is_numeric($duration) || !is_numeric($seed_id)) {
         $ret['extra'] = 'permission denied';
         return $ret;
     }
     /** @var User $user */
     $user = User::findOne(Yii::$app->user->identity->getId());
     if ($user->priv != 'Admin') {
         $ret['extra'] = 'permission denied';
         return $ret;
     }
     /** @var Seed $seed */
     $seed = Seed::findOne($seed_id);
     if (empty($seed) || !$seed->is_valid) {
         $ret['extra'] = 'not exists';
         return $ret;
     }
     $ret['result'] = 'success';
     $publisher = $seed->publisher;
     $record = new SeedOperationRecord();
     $record->admin_id = $user->user_id;
     $record->publisher_id = $publisher->user_id;
     $record->seed_id = $seed->seed_id;
     $record->operation_type = "SETCOEF";
     $record->detail_info = json_encode(['reason' => $reason, 'up_coe' => $upcoe, 'down_coe' => $downcoe, 'expire_time' => $duration]);
     $record->insert();
     $coef = $seed->getCoefArray();
     $coef_item = $coef[0];
     //复制栈顶
     $old_duration = $coef[0][2] - time();
     if ($duration == 0) {
         $replace = true;
     } else {
         if ($old_duration < $duration) {
             $replace = true;
         }
     }
     if ($upcoe >= 0) {
         $coef_item[0] = $upcoe;
     }
     if ($downcoe >= 0) {
         $coef_item[1] = $downcoe;
     }
     $coef_item[2] = $duration + time();
     //如果是永久有效,就直接替换栈顶的条目
     if ($replace) {
         $coef[0] = $coef_item;
     } else {
         array_unshift($coef, $coef_item);
     }
     $seed->setCoefArray($coef);
     $seed->save();
     $tmp = $seed->attributes;
     $tmp['discuz_pub_uid'] = $publisher->discuz_user_id;
     $ret['extra'] = $tmp;
     Yii::info($ret);
     return $ret;
 }
开发者ID:KKRainbow,项目名称:ngpt_seed,代码行数:70,代码来源:SeedController.php

示例13: loginUserByName

 public static function loginUserByName($username, $password)
 {
     $user = User::findOne(['username' => $username]);
     if (!$user || !Password::validate($password, $user->password_hash)) {
         return;
     }
     return $user;
 }
开发者ID:babagay,项目名称:razzd,代码行数:8,代码来源:RestApi.php

示例14: actionOperation

    public function actionOperation()
    {
        SeedOperationRecord::deleteAll();
        $offset = 0;
        $limit = 1000;
        QUERY:
        $sql = <<<SQL
        SELECT * FROM `ngpt_ngpt_seed_op_records` LIMIT {$limit} OFFSET {$offset};
SQL;
        $res = $this->fdb->createCommand($sql)->queryAll();
        foreach ($res as $oop) {
            var_dump($oop);
            $op = new SeedOperationRecord();
            /** @var User $admin */
            $admin = User::findOne(['discuz_user_id' => $oop['uid']]);
            /** @var Seed $seed */
            $seed = Seed::findOne(['info_hash' => strtoupper($oop['infohash'])]);
            if (empty($seed)) {
                continue;
            }
            $op->admin_id = $admin->user_id;
            $op->seed_id = $seed->seed_id;
            $op->operation_type = $oop['reason'];
            $op->detail_info = json_encode(['reason' => $oop['info']]);
            $op->publisher_id = $seed->publisher_user_id;
            $op->create_time = $this->date($oop['opdate']);
            var_dump($op->attributes);
            if (!$op->insert()) {
                var_dump($op->errors);
                return;
            }
        }
        if (count($res)) {
            $offset += $limit;
            goto QUERY;
        }
        return;
    }
开发者ID:KKRainbow,项目名称:ngpt_seed,代码行数:38,代码来源:TransferController.php

示例15: actionResendVerification

 /**
  * Resend verification email
  *
  * @param $id string User ID
  * @return \yii\web\Response
  */
 public function actionResendVerification($id)
 {
     $user = User::findOne($id);
     if (!$user || $user->status != User::STATUS_PENDING) {
         Yii::$app->session->addFlash('error', Yii::t('auth', 'No such user found. Please make sure you have provided correct credentials and your account is not verified yet.'));
         return $this->redirect(['login']);
     }
     if ($user->sendVerificationEmail()) {
         Yii::$app->session->addFlash('success', Yii::t('auth', 'Verification link was successfully sent to your email address. Please follow that link to proceed.'));
     } else {
         Yii::$app->session->addFlash('error', Yii::t('auth', 'Failed to send verification link. Please contact site administrator for more details.'));
     }
     return $this->redirect(['index']);
 }
开发者ID:WondersLabCorporation,项目名称:yii2,代码行数:20,代码来源:SiteController.php


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