コード例 #1
0
 /**
  * @test
  */
 public function shouldGetLoggedOnUser()
 {
     // given
     if (Session::getInstance()->isSignedIn()) {
         Session::getInstance()->signOut();
     }
     $username = '******';
     $password = '******';
     $this->createUser($username, $password);
     // when
     $login = new Session();
     $login->signIn(array('username' => $username, 'password' => md5($password)));
     $this->mockCookie($login->getKey());
     $user = $login->getUser();
     // then
     $this->assertNotNull($user);
     $this->assertEquals(2, $user->getId());
     $this->assertEquals("username", $user->getUsername());
     $player = new CurrentPlayer();
     $this->assertEquals($user->getValues(), $player->getValues());
 }
コード例 #2
0
 private function extractUploadedFile()
 {
     if (empty($_FILES)) {
         throw new LudoDBException("No files uploaded", 400);
     }
     $file = array_shift($_FILES);
     $this->setValue('file_size', $file['size']);
     $this->setValue('display_name', $file['name']);
     $this->setValue('created_date', date("Y-m-d H:i:s"));
     $this->setValue('user_id', CurrentPlayer::getInstance()->getId());
     $tempPath = $this->getTempPath($file['name']);
     $this->setValue('path_on_server', $tempPath);
     move_uploaded_file($file['tmp_name'], $tempPath);
     if (!file_exists($tempPath)) {
         copy($file['tmp_name'], $tempPath);
         if (!file_exists($tempPath)) {
             throw new LudoDBException("Could not write temp file " . $file['tmp_name'] . " to " . LudoDBRegistry::get(self::FILE_UPLOAD_KEY));
         }
     }
 }
コード例 #3
0
 public function validateServiceData($service, $data)
 {
     if (!CurrentPlayer::getInstance()->hasAccessTo(ChessRoles::IMPORT_GAMES)) {
         throw new LudoDBUnauthorizedException("You do not have access to import games");
     }
     return true;
 }
コード例 #4
0
ファイル: Player.php プロジェクト: manishkhanchandani/mkgxy
 public function edit($data)
 {
     $cp = CurrentPlayer::getInstance();
     if (!$cp->hasAccessTo(ChessRoles::EDIT_USERS) && $cp->getId() !== $this->getId()) {
         throw new LudoDBUnauthorizedException("You are not allowed to edit this user");
     }
     if (!$cp->hasAccessTo(ChessRoles::EDIT_USERS)) {
         if (isset($data['user_access'])) {
             unset($data['user_access']);
         }
     }
     if (isset($values['password']) && !$values['password']) {
         unset($values['password']);
     }
     return parent::save($data);
 }
コード例 #5
0
ファイル: Game.php プロジェクト: manishkhanchandani/mkgxy
 public function validateArguments($service, $arguments)
 {
     if (count($arguments) > 1) {
         return false;
     }
     switch ($service) {
         case 'read':
             return count($arguments) === 1 && is_numeric($arguments[0]);
         case 'save':
             $cp = CurrentPlayer::getInstance();
             if (!$cp->hasAccessTo(ChessRoles::EDIT_GAMES) && !$cp->hasAccessTo(ChessRoles::IMPORT_GAMES)) {
                 throw new LudoDBUnauthorizedException("Your are not authorized to save new games");
             }
             return count($arguments) === 0 || is_numeric($arguments[0]);
     }
     return true;
 }