Esempio n. 1
0
 public function acceptFriendRequest($token, $requestId)
 {
     $user = new User();
     $meId = $user->getMeId($token);
     try {
         $requestData = Capsule::table('friendrequests')->select('userFrom', 'userTo')->where('id', $requestId)->first();
         if ($requestData->userFrom == $meId) {
             $newFriendId = $requestData->userTo;
         } else {
             $newFriendId = $requestData->userFrom;
         }
     } catch (\Exception $e) {
         throw new \Exception('Wystąpił błąd przy pobieraniu przyjaciół');
     }
     if ($user->isUserMyFriend($newFriendId, $token)) {
         throw new \Exception('Ten użytkownik jest już Twoim znajomym');
     }
     try {
         Capsule::table('friendrequests')->where('id', $requestId)->where('userFrom', $meId)->orWhere('userTo', $meId)->where('accepted', 0)->update(array('accepted' => 1));
         Capsule::table('friends')->insert(array('userA' => $meId, 'userB' => $newFriendId));
     } catch (\Exception $e) {
         throw new \Exception('Wystąpił błąd przy pobieraniu przyjaciół');
     }
     $newFriendData = $user->getUser($newFriendId, $token);
     return $newFriendData;
 }
Esempio n. 2
0
 public function newTopic($userId, $token)
 {
     $user = new User();
     $meId = $user->getMeId($token);
     $conversation = $this->isConversationBetweenUsers($userId, $meId);
     if (!$conversation) {
         try {
             $conversation = Capsule::table('messagestopics')->insertGetId(array('userFrom' => $meId, 'userTo' => $userId, 'name' => ''));
         } catch (\Exception $e) {
             throw new \Exception('Problem z inicjacją czatu');
         }
     }
     return $conversation;
 }
Esempio n. 3
0
 public function getNotifications($token)
 {
     $user = new User();
     $userId = $user->getMeId($token);
     $array = array();
     try {
         $notifications = Capsule::table('friendrequests')->select('*')->where('userTo', $userId)->where('accepted', 0)->get();
     } catch (\Exception $e) {
         throw new \Exception('Problem z probraniem wiadmości');
     }
     foreach ($notifications as $notification) {
         if ($notification->userFrom == $userId) {
             $notification->firstName = $user->getUser($notification->userTo, $token)->firstName;
         }
         array_push($array, $notification);
     }
     return $array;
 }
Esempio n. 4
0
 /**
  * Check against the DB if the token is valid
  *
  * @param string $token
  * @return bool
  */
 public function authenticate($token)
 {
     return \src\models\User::validateToken($token);
 }
Esempio n. 5
0
    if ($user->changePassword($token, $data['oldPass'], $data['newPass'], $data['repPass'])) {
        $app->render(200, array('msg' => 'Hasło zostało zmienione'));
    }
    $app->render(401, array('msg' => 'Coś poszło nie tak'));
});
$app->get('/users/:user_id', function ($user_id) use($app) {
    $token = $app->request->headers("Authorization");
    $user = new User();
    $userData = $user->getUser($user_id, $token);
    $app->render(200, array('msg' => $userData));
});
/* edytuj uzytkownika */
$app->put('/users/:user_id', function ($user_id) use($app) {
    $token = $app->request->headers("Authorization");
    $user = new User();
    $json = $app->request->getBody();
    $data = json_decode($json, true);
    if ($user->updateUser($token, $user_id, $data)) {
        $app->render(200, array('msg' => 'Pomyślnie wyedytowano użytkownika'));
    }
    $app->render(400, array('error' => true, 'msg' => 'Wystąpił problem z edycją użytkownika'));
});
/* usun uzytkownika */
$app->delete('/users/:user_id', function ($user_id) use($app) {
    $token = $app->request->headers("Authorization");
    $user = new User();
    if ($user->removeUser($token, $user_id)) {
        $app->render(200, array('msg' => 'Użytkownik został pomyślnie usunięty z systemu'));
    }
    $app->render(400, array('error' => true, 'msg' => 'Wystąpił problem z usuwaniem użytkownika'));
});
Esempio n. 6
0
 public function deleteRegister($token, $id)
 {
     $user = new User();
     if ($this->getNumberOfRegisterDocuments($id) > 0) {
         throw new \Exception("Nie można usunąć rejestru, gdyż znajdują się w nim wprowadzone dokumenty.");
     }
     if (!$user->isUserHasRole($token, 'delete:all:register')) {
         if (!$user->isUserHasRole($token, 'delete:my:register')) {
             throw new \Exception("Brak uprawnień");
         } else {
             if (!$user->isUserBelongsToUnit($user->getMeId($token), $this->getRegisterUnitId($id))) {
                 throw new \Exception("Brak uprawnień");
             }
         }
     }
     try {
         Capsule::table('registers')->where('id', $id)->delete();
     } catch (\Exception $e) {
         throw new \Exception('Problem z usunięciem rejestru');
     }
     return true;
 }
Esempio n. 7
0
 public function removeRole($token, $rankId)
 {
     $user = new User();
     if (!$user->isUserHasRole($token, 'update:all:permissions')) {
         throw new \Exception("Brak uprawnień");
     }
     try {
         Capsule::table('rolestoranks')->where('rank_id', $rankId)->delete();
         Capsule::table('ranks')->where('id', $rankId)->delete();
     } catch (\Exception $e) {
         throw new \Exception("Problem z uzyskaniem informacji o rangach");
     }
     return true;
 }