/**
  * Update information
  *
  * @return User|null the saved model or null if saving fails
  */
 public function updateInformation(User $user)
 {
     if (!$this->validate()) {
         return null;
     }
     $user->username = $this->username;
     if ($this->informationUpdated = $user->save()) {
         return $user;
     }
     return null;
 }
Example #2
0
 /**
  * Change Password
  *
  * @return User|null the saved model or null if saving fails
  */
 public function updatePassword(\common\models\user\User $user)
 {
     if (!$this->validate()) {
         return null;
     }
     $user->setPassword($this->password);
     $user->generateAuthKey();
     if ($this->passwordUpdated = $user->save()) {
         return $user;
     }
     return null;
 }
Example #3
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function register($validate = true)
 {
     if ($validate && !$this->validate()) {
         return null;
     }
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     $user->save();
     return $user;
 }
Example #4
0
 /**
  * Get info of a user.
  * You can specify User's ID or GUID, like following:
  * 
  *     rhosocial user/info 123456
  * 
  * or
  * 
  *     rhosocial user/info 58B580CC-26F4-3D1F-9A1E-6FB608D7D925
  * 
  * TODO:
  * - multi ID or GUID.
  * @param string $id user id or guid.
  * @return string
  */
 public function actionIndex($id)
 {
     $user = null;
     if (preg_match(Number::GUID_REGEX, $id)) {
         $user = User::find()->guid($id)->one();
     } elseif (preg_match("/^\\d{1,10}\$/", $id)) {
         $user = User::find()->id($id)->one();
     } else {
         throw new Exception("The parameter '{$id}' cannot be recognized.");
     }
     if (!$user) {
         echo "The user whose id is '{$id}' cannot be found.\n";
         $users = User::find()->id($id, 'like')->all();
         if ($users) {
             $i = 0;
             echo "But we found the following user id(s):\n";
             foreach ($users as $user) {
                 echo $user->id . "\n";
                 $i++;
                 if ($i >= 100) {
                     echo "There are more than {$i} users found, but we cannot display them at one time.\n";
                     break;
                 }
             }
         }
         return;
     }
     $this->printUser($user);
 }
Example #5
0
 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]);
 }
Example #6
0
 /**
  * Trigger after the social login or registration finished.
  * 
  * @author A.Jafaripur <*****@*****.**>
  * 
  * @param yii\authclient\BaseClient $client Object which contain result from OAuth or OpenId
  * @return yii\web\Response redirect to home page.
  */
 public static function successCallback($client)
 {
     $attributes = $client->getUserAttributes();
     $service = $client->getName();
     $username = '';
     $email = '';
     if ($service == 'github') {
         $username = $attributes['login'];
         $email = $attributes['email'];
     } elseif ($service == 'linkedin') {
         $email = $username = $attributes['email'];
     } elseif ($service == 'google') {
         $email = $username = $attributes['emails'][0]['value'];
         // for OAuth
     } elseif ($service == 'facebook') {
         $email = $username = $attributes['email'];
     } elseif ($service == 'live') {
         $email = $username = $attributes['emails']['preferred'];
     }
     $user = User::find()->where(['username' => [$username, $email]])->orWhere(['email' => $email])->one();
     if (!$user) {
         $model = new RegisterForm();
         $model->username = $username;
         $model->email = $email;
         $model->password = Yii::$app->getSecurity()->generateRandomString(8);
         $user = $model->register(false);
     }
     if ($user) {
         if ($user->login(false)) {
             return Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl());
         }
     }
 }
Example #7
0
 /**
  * Finds user by [[email]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByEmail($this->email);
     }
     return $this->_user;
 }
Example #8
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
 public function run()
 {
     $bars = [];
     if (BackendAccessControl::checkPermissionAccess(UserController::BACKEND_PERMISSION)) {
         $usersCount = User::find()->where(['status' => User::STATUS_ACTIVE])->count();
         $bars[] = ['bgClass' => 'bg-blue', 'label' => Yii::t('b/radiata/common', 'Total users'), 'data' => $usersCount, 'icon' => 'fa-user', 'url' => Url::to(['user/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(NewsController::BACKEND_PERMISSION)) {
         $newsCount = News::find()->count();
         $bars[] = ['bgClass' => 'bg-olive', 'label' => Yii::t('b/news', 'Total news'), 'data' => $newsCount, 'icon' => 'fa-bars', 'url' => Url::to(['/news/news/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(VoteController::BACKEND_PERMISSION)) {
         $newsCount = Vote::find()->count();
         $bars[] = ['bgClass' => 'bg-aqua', 'label' => Yii::t('b/vote', 'Total votes'), 'data' => $newsCount, 'icon' => 'fa-question-circle', 'url' => Url::to(['/vote/vote/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(BannerController::BACKEND_PERMISSION)) {
         $newsCount = Banner::find()->count();
         $bars[] = ['bgClass' => 'bg-maroon', 'label' => Yii::t('b/banner', 'Total banners'), 'data' => $newsCount, 'icon' => 'fa-flag', 'url' => Url::to(['/vote/vote/index'])];
     }
     if (BackendAccessControl::checkRoleAccess('developer')) {
         $migrator = new Migrator();
         $migrations = $migrator->findNewMigrations();
         if (count($migrations) > 0) {
             $bars[] = ['bgClass' => 'bg-gold', 'label' => Yii::t('b/radiata/common', 'New migrations'), 'data' => count($migrations), 'icon' => 'fa-database', 'url' => Url::to(['radiata/apply-migrations']), 'more' => Yii::t('b/radiata/common', 'Apply migrations')];
         }
     }
     if (count($bars) > 0) {
         return $this->render('SiteStatsBars', ['bars' => $bars]);
     }
 }
 /**
  * Finds user by [[id]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findById($this->user_id);
     }
     return $this->_user;
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Example #13
0
 /**
  * Displays a single Photo model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $albumModel = Album::findOne($model->album_id);
     $photoCount = Photo::find()->andWhere(['album_id' => $model->album_id])->count('*');
     $currentPage = Photo::find()->andWhere(['album_id' => $model->album_id])->andWhere('id >= ' . $id)->count('*');
     return $this->render('photoView', ['model' => $model, 'photoCount' => $photoCount, 'currentPage' => $currentPage, 'albumModel' => $albumModel, 'userCreadedBy' => User::find()->andWhere(['id' => $model->created_by])->asArray()->one(), 'userExtendCreadedBy' => UserExtend::find()->andWhere(['user_id' => $model->created_by])->asArray()->one(), 'user' => User::find()->andWhere(['id' => Yii::$app->getUser()->getId()])->asArray()->one(), 'userExtend' => UserExtend::find()->andWhere(['user_id' => Yii::$app->getUser()->getId()])->asArray()->one()]);
 }
Example #14
0
 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.'));
     }
 }
Example #15
0
 /**
  * 个人歌单
  * @param $userId
  * @return array
  */
 public function personalSongKingdomByUserId($userId)
 {
     $query = SongKingdom::find()->andWhere(['created_by' => $userId]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->setPageSize(10);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return ['models' => $models, 'pages' => $pages, 'userCreadedBy' => User::find()->andWhere(['id' => $userId])->asArray()->one(), 'userExtendCreadedBy' => UserExtend::find()->andWhere(['user_id' => $userId])->asArray()->one()];
 }
Example #16
0
 public function run()
 {
     if (BackendAccessControl::checkPermissionAccess(UserController::BACKEND_PERMISSION)) {
         $users = User::find()->where(['status' => User::STATUS_ACTIVE])->orderBy('id')->limit($this->limit)->all();
         if (count($users) > 0) {
             return $this->render('LastUsers', ['users' => $users]);
         }
     }
 }
 /**
  * 
  * @param int $user_no
  */
 public function actionGetContact($user_no)
 {
     $response = Yii::$app->response;
     /* @var $response Response */
     $response->format = Response::FORMAT_JSON;
     $user = User::find()->id($user_no)->one();
     if (!$user) {
         throw new \yii\base\InvalidParamException('User Not Found.');
     }
     return $user->profile->attributes;
 }
 /**
  * Creates a form model given a token.
  *
  * @param  string                          $token
  * @param  array                           $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Password reset token cannot be blank.');
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException('Wrong password reset token.');
     }
     parent::__construct($config);
 }
Example #19
0
 /**
  * Get the statistics of user.
  * If you want to count all users, you can skip `status` parameter, like following:
  * 
  *     rhosocial user/stat
  * 
  * if you want to know specified status, you can specify status number, like following:
  * 
  *     rhosocial user/stat 0
  * 
  * the above statement will return the sum of inactive users.
  * 
  * TODO:
  * - multi status.
  * @param string|integer $status user status.
  */
 public function actionIndex($status = 'all')
 {
     $query = User::find();
     if (is_string($status) && strtolower($status) === 'all') {
     } elseif (is_numeric($status)) {
         $query = $query->active((int) $status);
     } else {
         throw new Exception("Unrecognized parameter `{$status}`.");
     }
     echo $query->count();
 }
Example #20
0
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['status' => $this->status]);
     list($from, $to) = FieldHelper::getDateFromRange($this->created_at);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['between', 'created_at', $from, $to]);
     return $dataProvider;
 }
Example #21
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     $transaction = Yii::$app->db->beginTransaction();
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->first_name = $this->first_name;
         $user->last_name = $this->last_name;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $userRole = Yii::$app->authManager->getRole('user');
             Yii::$app->authManager->assign($userRole, $user->id);
             $transaction->commit();
             return $user;
         } else {
             $transaction->rollBack();
         }
     }
     return null;
 }
Example #22
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $userExtend = new UserExtend();
             $resultFullPath = $userExtend->defaultUserImage();
             if (!empty($resultFullPath)) {
                 $userExtend->user_id = $user->id;
                 $userExtend->avatar = $resultFullPath['avatar'];
                 $userExtend->image = $resultFullPath['image'];
                 $userExtend->save();
             }
             return $user;
         }
     }
     return null;
 }
 /**
  * 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;
 }
Example #24
0
 public function search($params)
 {
     $query = User::find();
     $query->select(['id', 'username', 'email', 'created_at', 'updated_at', 'status']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // load the seach form data and validate
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     // adjust the query by adding the filters
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['status' => $this->status]);
     return $dataProvider;
 }
 /**
  * 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;
 }
Example #26
0
 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);
 }
Example #27
0
 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);
 }
Example #28
0
 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;
 }
Example #29
0
 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);
 }
Example #30
0
 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();
     }
 }