Beispiel #1
0
 protected function checkAuth(Request_Abstract $request, Response_Abstract $response)
 {
     $config = ['allow' => ['api-user-create' => 1, 'api-user-login' => 1, 'api-user-recommend' => 1, 'api-user-info' => 1, 'api-group-recommend' => 1]];
     $id = strtolower($request->getModuleName() . '-' . $request->getControllerName() . '-' . $request->getActionName());
     if (!isset($config['allow'][$id])) {
         $user = new User();
         $user->id = ApiRequest::getParam('uid');
         $token = ApiRequest::getParam('token');
         if (!$user->id || TextUtil::isEmptyString($token)) {
             return new ApiResponse(Code::FAIL_PARAMETER_MISSING, 'uid or token is missing');
         }
         if ($resp = UserManager::getInstance()->getUser($user)) {
             return $resp;
         }
         if ($user->token != $token) {
             return new ApiResponse(Code::FAIL_USER_TOKEN_EXPIRE, null);
         }
         UserManager::getInstance()->setAuthorizedUser($user);
     }
     return null;
 }
Beispiel #2
0
 public function init()
 {
     Dispatcher::getInstance()->disableView();
     $this->user = UserManager::getInstance()->getAuthorizedUser();
 }
Beispiel #3
0
 public function list_allAction()
 {
     if ($resp = $this->checkUserInput(null, self::GET)) {
         $resp->flush();
         return false;
     }
     $groupList = RosterGroupManager::getInstance()->getUserRosterGroup($this->user->id);
     $rosterManager = RosterManager::getInstance();
     $userManager = UserManager::getInstance();
     $list = [];
     /* @var RosterGroup $group */
     foreach ($groupList as $group) {
         $roster = new Roster();
         $roster->group_id = $group->id;
         $roster->uid = $group->uid;
         $roster->status = Roster::STATUS_AGREE;
         $rosterList = $rosterManager->getRosterAll($roster);
         $row = $group->toArray();
         if ($rosterList) {
             $row['rosters'] = [];
             foreach ($rosterList as $rst) {
                 $rosterData = $rst->toArray();
                 $user = $userManager->getUserById($rst->target_id);
                 if ($user) {
                     $user->makeSecret();
                     $rosterData['user'] = $user->toArray();
                 } else {
                     $rosterData['user'] = null;
                 }
                 $row['rosters'][] = $rosterData;
             }
         }
         $list[] = $row;
     }
     (new ApiResponse(Code::SUCCESS, $list))->flush();
     return false;
 }
Beispiel #4
0
 protected function checkRoster(Roster $model)
 {
     if (!$model->uid) {
         return new ApiResponse(Code::FAIL_USER_NOT_EXISTS, 'uid is empty');
     }
     if (!$model->target_id) {
         return new ApiResponse(Code::FAIL_USER_NOT_EXISTS, 'target_id is empty');
     }
     if ($model->uid == $model->target_id) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'target_id is uid');
     }
     if (!$model->checkStatus()) {
         return new ApiResponse(Code::FAIL_ROSTER_STATUS, 'status is error[' . $model->status . ']');
     }
     $friend = new User();
     $friend->id = $model->target_id;
     if ($resp = UserManager::getInstance()->getUser($friend)) {
         return new ApiResponse(Code::FAIL_USER_NOT_EXISTS, 'friend not exists');
     }
     if ($model->group_id > 0) {
         $grManager = RosterGroupManager::getInstance();
         if ($groupRoster = $grManager->getRosterGroupById($model->group_id)) {
             if ($groupRoster->uid != $model->uid) {
                 return new ApiResponse(Code::FAIL_GROUP_ROSTER_NOT_EXISTS, 'other\'s group roster');
             }
         } else {
             return new ApiResponse($grManager->getLastErrorCode(), $grManager->getLastErrorString());
         }
     }
     return null;
 }
Beispiel #5
0
 public function recommendAction()
 {
     if ($resp = $this->checkUserInput(null, self::GET)) {
         $resp->flush();
         return false;
     }
     // find last login success users, limit 30, and return
     $list = [];
     if ($uidList = LoginLogManager::getInstance()->getLatestSuccessUser(0, 20)) {
         $userManager = UserManager::getInstance();
         foreach ($uidList as $uid) {
             $user = new User();
             $user->id = $uid;
             if (!$userManager->getUser($user)) {
                 $row = $user->toArray();
                 unset($row['token']);
                 $list[] = $row;
             }
         }
     }
     (new ApiResponse(Code::SUCCESS, $list))->flush();
     return false;
 }
Beispiel #6
0
 public function deleteUser(User $user)
 {
     self::assertTrue(null === UserManager::getInstance()->removeUser($user));
     // user should be remove from cache
     self::assertTrue(\jegarn\manager\UserManager::getInstance()->getUser($user->username) === null);
 }