示例#1
0
 /**
  * @param userModel|modelBase $user
  *
  * @return array
  * @throws \mpcmf\modules\moduleBase\exceptions\mapperException
  * @throws \mpcmf\system\acl\exception\aclException
  * @throws \mpcmf\system\application\exception\webApplicationException
  */
 public function _token_generate($user = null)
 {
     $slim = $this->getSlim();
     if ($user === null) {
         $user = aclManager::getInstance()->getCurrentUser();
     }
     $tokenMapper = tokenMapper::getInstance();
     if ($slim->request()->isPost() && $slim->request->post('updateToken') === 'true') {
         try {
             /** @var tokenModel $tokenModel */
             $tokenModel = $tokenMapper->getBy([tokenMapper::FIELD__USER => $user->getUserId()]);
         } catch (mapperException $mapperException) {
             $tokenModel = tokenModel::fromArray([tokenMapper::FIELD__USER => $user->getUserId(), tokenMapper::FIELD__LIMIT => tokenMapper::DEFAULT_LIMIT]);
         }
         $tokenString = tokenManager::getInstance()->generateToken($tokenModel);
         $result = ['token' => $tokenString];
         $this->getSlim()->response()->header('Content-type', 'application/json');
         $this->getSlim()->response()->write(json_encode($result, JSON_UNESCAPED_UNICODE));
         $this->getSlim()->stop();
     }
     return self::nothing([]);
 }
示例#2
0
 public function _profile()
 {
     $inviteMapper = inviteMapper::getInstance();
     $user = aclManager::getInstance()->getCurrentUser();
     $slim = $this->getSlim();
     $tokenMapper = tokenMapper::getInstance();
     if ($slim->request()->isPost()) {
         // TODO :: extract it to another action (create invite)
         $input = $this->getSlim()->request()->post('item', []);
         if (!isset($input['email'])) {
             $slim->response()->write(json_encode(['message' => 'email field is empty']));
             $slim->stop();
         }
         $response = $inviteMapper->createInvite($input, $user);
         if (!$response['status']) {
             $slim->response()->setStatus(409);
             $slim->response()->write(json_encode(['message' => 'Invite already sended!']));
             $slim->stop();
         }
         try {
             $invites = $inviteMapper->getInvitesByUserModel($user)->export();
         } catch (mapperException $mapperException) {
             $invites = [];
         }
         $response['invites'] = $invites;
         $slim->response()->write(json_encode($response));
         $slim->stop();
     }
     try {
         /** @var tokenModel $tokenModel */
         $tokenModel = $tokenMapper->getBy([tokenMapper::FIELD__USER => $user->getUserId()]);
         $token = $tokenModel->getToken();
     } catch (mapperException $mapperException) {
         $token = '';
     }
     try {
         $invites = $inviteMapper->getInvitesByUserModel($user)->export();
     } catch (mapperException $mapperException) {
         $invites = [];
     }
     return self::success(['user' => $user, 'inviteEntity' => invite::getInstance(), 'invites' => $invites, 'token' => $token]);
 }
 public function _userGet($id)
 {
     try {
         /** @var userModel $user */
         $user = userMapper::getInstance()->getById($id);
     } catch (mapperException $mapperException) {
         return self::errorByException($mapperException);
     }
     try {
         $userToken = tokenMapper::getInstance()->getBy([tokenMapper::FIELD__USER => $user->getIdValue()]);
     } catch (mapperException $mapperException) {
         $userToken = null;
     }
     return self::success(['user' => $user, 'userToken' => $userToken]);
 }