本文整理汇总了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;
}
示例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'];
}
}
示例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'));
}
}
示例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.');
}
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
}
示例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');
}
}
示例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);
}
示例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;
}
示例13: loginUserByName
public static function loginUserByName($username, $password)
{
$user = User::findOne(['username' => $username]);
if (!$user || !Password::validate($password, $user->password_hash)) {
return;
}
return $user;
}
示例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;
}
示例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']);
}