Beispiel #1
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());
         }
     }
 }
 /**
  * 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);
 }
 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]);
     }
 }
Beispiel #4
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()]);
 }
 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]);
         }
     }
 }
Beispiel #6
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()];
 }
 /**
  * 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();
 }
 /**
  * 
  * @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;
 }
Beispiel #9
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;
 }
 /**
  * 判断用户名称是否重复
  */
 public function unique($attribute)
 {
     $query = Admin::find()->andWhere([$attribute => trim($this->{$attribute})]);
     if (!$this->isNewRecord) {
         $query->andWhere(' id != :id', ['id' => $this->id]);
     }
     $model = $query->one();
     if ($model !== null) {
         $message = Yii::t('admin', '"{value}" 已经存在.');
         $params = ['attribute' => $this->getAttributeLabel($attribute), 'value' => $this->{$attribute}];
         $this->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
     }
 }
Beispiel #11
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;
 }
Beispiel #12
0
 /**
  * Get 
  * @param integer $id
  * @throws Exception
  */
 public function actionFollowingPhones($id)
 {
     $user = User::find()->id($id)->one();
     if (!$user) {
         throw new Exception("User {$id} not found.");
     }
     $followings = $user->followings;
     for ($i = 0; $i < count($followings); $i++) {
         if ((int) $user->getUserPhones($followings[$i])->count() > 0) {
             echo "{$i} :All the phones owned by {$followings[$i]}->id you can visit:\n";
             $phones = $user->getUserPhones($followings[$i])->all();
             for ($j = 0; $j < count($phones); $j++) {
                 echo $phones[$j]->phone . "\n";
             }
             echo "\n";
             unset($phones);
         }
     }
     echo count($followings) . " users.\n";
     unset($followings);
     unset($user->followings);
 }
 public function actionGroupRefresh($id = '')
 {
     $query = User::find()->id($id, 'like')->active(self::USER_STATUS_TEST_ACTIVE);
     $query = $query->orderBy($query->noInitModel->createdAtAttribute);
     $user = $query->one();
     if (!$user || !$user->follows) {
         return;
     }
     $follow = $user->follows[0];
     $blame = ['content' => $this->faker->name];
     $follow->addOrCreateGroup($blame);
     var_dump($blame->attributes);
     echo $follow->save();
 }
Beispiel #14
0
 /**
  * Displays a single Diary model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     return $this->render('diaryView', ['model' => $model, '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()]);
 }
Beispiel #15
0
 protected function hasBackendAccess($username)
 {
     return \common\models\user\User::find()->where(['username' => $username])->one()->getUserRole();
 }
Beispiel #16
0
 /**
  * 判断一个权限项有没有被后台管理员占用
  * @param string $role
  * @return boolean
  */
 public function isExist($role)
 {
     return User::find()->where(['role_name' => $role])->exists();
 }
 /**
  * Get contact.
  * @return type
  */
 public function actionGet()
 {
     $id = Yii::$app->request->post('id');
     $user = User::find()->id($id)->one();
     return $user;
 }
Beispiel #18
0
 /**
  * Lists all User models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => User::find(), 'pagination' => ['class' => 'yii\\data\\Pagination', 'defaultPageSize' => 16], 'sort' => ['class' => 'yii\\data\\Sort', 'defaultOrder' => ['updated_at' => SORT_DESC]]]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }