Beispiel #1
0
 public function _invite($invite)
 {
     try {
         inviteMapper::getInstance()->getBy([inviteMapper::FIELD__INVITE => $invite]);
     } catch (mapperException $mapperException) {
         $message = $mapperException->getMessage();
         if (mb_strpos($message, 'not found') === false) {
             return self::error($mapperException->getMessage(), $mapperException->getCode(), codes::RESPONSE_CODE_NOT_FOUND);
         }
         return self::nothing([]);
     }
     $this->getSlim()->redirectTo('/authex/user/register', ['invite' => $invite]);
     return self::nothing([]);
 }
Beispiel #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]);
 }