/** * 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; }
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']; } }
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')); } }
/** * 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.'); } }
/** * @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; }
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(); } }
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); } } }
/** * 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; }
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; } }
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'); } }
/** * @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); }
/** * @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; }
public static function loginUserByName($username, $password) { $user = User::findOne(['username' => $username]); if (!$user || !Password::validate($password, $user->password_hash)) { return; } return $user; }
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; }
/** * 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']); }
/** * Send message to razzded user */ private function sendNotifiRazzd() { $userModel = new \frontend\models\User(); $userName = $userModel->getFullname(Yii::$app->user->id); $notifi = \Yii::createObject(['class' => Notification::className(), 'uid' => $this->responder_uid, 'message' => 'YOU HAVE BEEN RAZZD BY ' . $userName, 'link' => '<a href="/razz/respond/' . $this->id . '" class="btn">RESPOND</a>', 'created_at' => time()]); $notifi->save(); $userModel = new \frontend\models\User(); $razdator = $userModel->getFullname(Yii::$app->user->id); $vis_a_vis = \frontend\models\User::findOne(['email' => $this->email]); $mailer = new \common\helpers\Mandrill($sendTo = $this->email, $subject = 'YOU HAVE BEEN RAZZD BY ' . ucfirst($razdator), $local_tpl_name = null, $sender = null, ['from_name' => '[Notification generator]', 'mandrill_template_name' => 'you-have-been-razzd', 'vars' => ['razee' => ucfirst($vis_a_vis->username), 'header' => $this->title, 'message' => $this->message, 'description' => $this->description, 'razdator' => ucfirst($razdator), 'link' => '<a href="' . Yii::$app->getUrlManager()->createAbsoluteUrl(["razz/respond/" . $this->id]) . '" class="btn">RESPOND</a>']]); $result = $mailer->sendWithMandrillTemplate(); $mess = (string) $result; unset($userModel); }
public function loadSteps() { $this->stepsInformation = []; if (!$this->checkProfileFields()) { $this->stepsInformation['steps'][] = Yii::t('frontend', 'Profile'); $this->stepsInformation['view'] = 'profile'; $this->stepsInformation['profileModel'] = User::findOne(Yii::$app->user->id); } else { $categories = $this->getActiveCategories(); foreach ($categories as $category) { if (!$this->checkCategoryAnswered($category['id'])) { $this->stepsInformation['steps'][] = $category['translation']['name']; $this->stepsInformation['view'] = 'questions'; $this->stepsInformation['currentCategory'] = $category; $this->stepsInformation['questionsAnswers'] = new MembersQuestionsAnswers($category['id']); break; } else { } } } }
public function actionProfile() { if ($post = Yii::$app->request->post('User')) { $profile = User::findOne(['id' => Yii::$app->user->identity->id]); $profile->fullname = $post['fullname']; $profile->email = $post['email']; if ($profile->validate()) { if ($profile->update()) { Yii::$app->getSession()->setFlash('success', 'Profile updated.'); } else { Yii::$app->getSession()->setFlash('error', 'Failed to update profile.'); } } } else { $profile = Yii::$app->user->identity; } return $this->render('profile', ['model' => $profile]); }
public function actionAutologin($id) { $member = User::findOne($id); Yii::$app->user->login($member); return $this->redirect(['news/index']); }