public function actionSign() { /*初始化用户*/ $woid = $this->get("woid", ''); $wx_user_info = ['avatar' => GlobalUrlService::buildStaticUrl("/images/wap/no_avatar.png"), 'nickname' => '匿名']; if ($woid) { $wx_user_info['nickname'] = "微信用户" . substr($woid, -10); $date_now = date("Y-m-d H:i:s"); $bind_info = UserOpenidUnionid::findOne(['other_openid' => strval($woid)]); if (!$bind_info) { $unique_name = md5($woid); $user_info = User::findOne(['unique_name' => $unique_name]); if (!$user_info) { $model_user = new User(); $model_user->nickname = "微信用户" . substr($woid, -10); $model_user->unique_name = $unique_name; $model_user->updated_time = $date_now; $model_user->created_time = $date_now; $model_user->save(0); $user_info = $model_user; } $model_bind = new UserOpenidUnionid(); $model_bind->uid = $user_info['uid']; $model_bind->openid = $woid; $model_bind->unionid = ''; $model_bind->other_openid = $woid; $model_bind->updated_time = $date_now; $model_bind->created_time = $date_now; $model_bind->save(0); } } return $this->render("sign", ["user_info" => $wx_user_info]); }
/** * Get user based on email * * @return user|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findOne(["email" => $this->email]); } return $this->_user; }
public function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new \yii\web\NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } }
/** * Validates the password. * This method serves as the inline validation for password. * * @param string $attribute the attribute currently being validated * @param array $params the additional name-value pairs given in the rule */ public function validatePassword($attribute, $params) { if (!$this->hasErrors()) { $user = User::findOne(Yii::$app->getUser()->id); if (!$user || !$user->validatePassword($this->oldPassword)) { $this->addError($attribute, Yii::t('app', 'Incorrect old password.')); } } }
/** * 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(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(\Yii::t('c/radiata/user', 'Password reset for') . ' ' . \Yii::$app->name)->send(); } } return false; }
/** * 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['noReply'] => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(Yii::t('app', 'Password reset for {name}', ['name' => Yii::$app->name]))->send(); } } return false; }
public function run($search = null, $id = null) { $out = ['more' => false]; if (!is_null($search)) { $query = new Query(); $query->select('[[id]], [[username]] AS [[text]]')->from('{{%user}}')->filterWhere(['like', '[[username]]', $search])->limit(20); $command = $query->createCommand(); $data = $command->queryAll(); $out['results'] = array_values($data); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => User::findOne($id)->username]; } else { $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')]; } return Json::encode($out); }
public function actionDologin() { $key = trim($this->getCookie("qrcode", "")); if (!$key || $key == "no") { return $this->renderJSON([], "扫描登录失败!{$key}", -1); } if (!$this->existCache($key)) { return $this->renderJSON([], "刷新页面!", 201); } $cache_status = $this->getCache($key); if ($cache_status < 1) { return $this->renderJSON([], "还没有登录!", -1); } $user_info = User::findOne(['uid' => $cache_status]); $data = ["nickname" => DataHelper::encode($user_info["nickname"]), "email" => "*****@*****.**"]; return $this->renderJSON($data, "", 200); }
public function run($id) { $id = (int) $id; if (($user = \common\models\user\User::findOne($id)) !== null) { if (!Yii::$app->getAuthManager()->checkAccess($id, 'Administrator')) { if ($user->delete()) { Yii::$app->getAuthManager()->revokeAll($id); $output = ['error' => false, 'message' => Yii::t('app', 'Successfully deleted!')]; } } else { $output = ['error' => true, 'message' => Yii::t('app', Yii::t('app', "You haven't enough permission to delete this user!"))]; } } if (empty($output)) { $output = ['error' => true, 'message' => Yii::t('app', 'The requested page does not exist.')]; } return \yii\helpers\Json::encode($output); }
public function checkLoginStatus() { $auth_cookie = $this->getCookie($this->auth_cookie_name); $login_status = false; if ($auth_cookie) { list($auth_token, $uid) = explode("#", $auth_cookie); if ($auth_token && $uid) { $user_info = User::findOne(['uid' => $uid]); $check_token = $this->geneAuthToken($user_info['uid'], $user_info['nickname']); if ($user_info && $auth_token == $check_token) { $login_status = true; $this->current_user = $user_info; $this->getView()->params['current_user'] = $this->current_user; } } } return $login_status; }
public function actionLockScreen($id) { if (!Yii::$app->user->isGuest) { Yii::$app->user->logout(); } $user = User::findOne($id); if ($user) { $successLogin = false; $model = new LockScreenLoginForm(); if ($model->load(Yii::$app->request->post())) { if ($model->login()) { $this->trigger(AdminLogEvent::EVENT_SUCCESS_AUTH); $successLogin = true; } else { $this->trigger(AdminLogEvent::EVENT_WRONG_AUTH); } } return $this->renderAjax('lock-screen', ['user' => $user, 'model' => $model, 'successLogin' => $successLogin]); } else { throw new ForbiddenHttpException(); } }
public function run($id) { $id = (int) $id; $output = []; if (($model = User::findOne($id)) !== null) { if ($model->status == User::STATUS_ACTIVE) { $model->status = User::STATUS_DISABLE; } else { $model->status = User::STATUS_ACTIVE; } if (Yii::$app->getAuthManager()->checkAccess($id, 'Administrator')) { $output = ['error' => true, 'message' => Yii::t('app', "You haven't enough permission to disable this user!")]; } else { if ($model->save()) { $output = ['error' => false, 'message' => Yii::t('app', 'Successfully status changed!')]; } } } if (empty($output)) { $output = ['error' => true, 'message' => Yii::t('app', 'The requested page does not exist.')]; } return \yii\helpers\Json::encode($output); }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function update() { if ($this->validate()) { $user = User::findOne($this->id); $user->email = $this->email; $user->nickname = $this->nickname; $user->phone = $this->phone; $user->remark = $this->remark; if (!empty($this->newPassword) && empty($this->password)) { $this->addError('password', '密码不可为空'); return false; } else { if (!empty($this->newPassword) && $user->validatePassword($this->password)) { $user->setPassword($this->newPassword); $user->generateAuthKey(); } } if ($user->save()) { return $user; } } return null; }
public static function add($xml, $source = "") { $data = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $type = trim($data->MsgType); $from_openid = $data->FromUserName; $to_openid = $data->ToUserName; $date_now = date("Y-m-d H:i:s"); switch ($type) { case "location": $content = trim($data->Label); break; case "voice": $content = trim($data->Recognition); break; case "image": $content = trim($data->PicUrl); break; case "link": $content = trim($data->Title); break; case "shortvideo": $content = trim($data->ThumbMediaId); break; case "event": $content = trim($data->Event); break; default: $content = trim($data->Content); break; } $model_wx_history = new WxHistory(); $model_wx_history->from_openid = $from_openid; $model_wx_history->to_openid = $to_openid; $model_wx_history->type = $type; $model_wx_history->content = $content; $model_wx_history->text = $xml; $model_wx_history->source = $source; $model_wx_history->created_time = $date_now; $model_wx_history->save(0); if (filter_var($content, FILTER_VALIDATE_URL) !== FALSE) { SpiderService::add($content); } if (in_array($type, ["text"]) && substr($content, 0, 1) == "#") { $bind_info = UserOpenidUnionid::findOne(['other_openid' => strval($from_openid)]); if (!$bind_info) { $unique_name = md5($from_openid); $user_info = User::findOne(['unique_name' => $unique_name]); if (!$user_info) { $model_user = new User(); $model_user->nickname = "微信用户" . substr($from_openid, -10); $model_user->unique_name = $unique_name; $model_user->updated_time = $date_now; $model_user->created_time = $date_now; $model_user->save(0); $user_info = $model_user; } $model_bind = new UserOpenidUnionid(); $model_bind->uid = $user_info['uid']; $model_bind->openid = $from_openid; $model_bind->unionid = ''; $model_bind->other_openid = $from_openid; $model_bind->updated_time = $date_now; $model_bind->created_time = $date_now; $model_bind->save(0); } if ($bind_info) { $model_message = new UserMessageHistory(); $model_message->uid = $bind_info['uid']; $model_message->type = 1; $model_message->content = ltrim($content, "#"); $model_message->status = 1; $model_message->updated_time = $date_now; $model_message->created_time = $date_now; $model_message->save(0); } } }
public function edit() { if ($this->validate()) { $user = Admin::findOne($this->id); $user->username = '******'; $user->email = $this->email; if (!empty($this->nickname)) { $user->nickname = $this->nickname; } if (!empty($this->phone)) { $user->phone = $this->phone; } if ($this->password !== null) { $user->setPassword($this->password); $user->generateAuthKey(); } if ($user->save()) { return $user; } } return null; }
/** * 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.'); } }
public function actionChangeagree() { $user = new User(); if (Yii::$app->request->isAjax) { $id_user = $_REQUEST['set']; $customer = $user->findOne($id_user); $customer->agree = Dict::USER_AGREE_YES; if ($customer->save(false)) { $arr = ["code" => 1]; } else { $arr = ["code" => 0]; } exit(json_encode($arr)); } else { return $this->redirect(["/user/login"]); } }
* Time: 10:00 */ use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\Menu; use yii\widgets\Breadcrumbs; use frontend\assets\FrontendAsset; yii::beginProfile('mainAsset', 'gx'); FrontendAsset::register($this); yii::endProfile('mainAsset', 'gx'); $this->title = 'admin'; $baseUrl = Yii::getAlias('@web'); $imgDomain = Yii::$app->params['imgDomain']; if (!Yii::$app->getUser()->isGuest) { $userExtendModel = \common\models\user\UserExtend::find()->andWhere(['user_id' => Yii::$app->getUser()->getId()])->one(); $userModel = \common\models\user\User::findOne(Yii::$app->getUser()->getId()); } ?> <?php $this->beginPage(); ?> <!DOCTYPE html> <html lang="<?php echo Yii::$app->language; ?> " xmlns="http://www.w3.org/1999/html"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge">
protected function findEditForm($id) { $model = User::findOne($id); if ($model == NULL) { throw new NotFoundHttpException('该用户不存在'); } $item = $model->getOldAttributes(); return new EditProfile([], $item); }
public function actionSetauth($id) { $code = $this->get("code", ""); $source = $this->get("source", "game"); $unvalid_url = UrlService::buildGameUrl("/mv/index"); if (!$id || $code != "030608bfff2840942db5cb9604ff0445") { return $this->redirect($unvalid_url); } $user_info = User::findOne(['uid' => $id]); if (!$user_info) { return $this->redirect($unvalid_url); } $this->createLoginStatus($user_info); return $this->redirect($unvalid_url); }