Moved authentication check to Access

This commit is contained in:
Marcin Kurczewski 2014-05-01 16:18:42 +02:00
parent 0a7fc387ac
commit 925fccbd17
2 changed files with 9 additions and 9 deletions

View file

@ -60,6 +60,12 @@ class Access
return intval($user->accessRank) >= $minAccessRank;
}
public static function assertAuthentication()
{
if (!Auth::isLoggedIn())
throw new SimpleException('Not logged in');
}
public static function assert($privilege, $subPrivilege = null)
{
if (!self::check($privilege, $subPrivilege))

View file

@ -263,13 +263,11 @@ class PostController
$context = getContext();
$post = PostModel::findByIdOrName($id);
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
Access::assertAuthentication();
if (!InputHelper::get('submit'))
return;
if (!Auth::isLoggedIn())
throw new SimpleException('Not logged in');
UserModel::updateUserScore(Auth::getCurrentUser(), $post, 1);
UserModel::addToUserFavorites(Auth::getCurrentUser(), $post);
StatusHelper::success();
@ -280,13 +278,11 @@ class PostController
$context = getContext();
$post = PostModel::findByIdOrName($id);
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
Access::assertAuthentication();
if (!InputHelper::get('submit'))
return;
if (!Auth::isLoggedIn())
throw new SimpleException('Not logged in');
UserModel::removeFromUserFavorites(Auth::getCurrentUser(), $post);
StatusHelper::success();
}
@ -296,13 +292,11 @@ class PostController
$context = getContext();
$post = PostModel::findByIdOrName($id);
Access::assert(Privilege::ScorePost, Access::getIdentity($post->getUploader()));
Access::assertAuthentication();
if (!InputHelper::get('submit'))
return;
if (!Auth::isLoggedIn())
throw new SimpleException('Not logged in');
UserModel::updateUserScore(Auth::getCurrentUser(), $post, $score);
StatusHelper::success();
}