Moved authentication check to Access
This commit is contained in:
parent
0a7fc387ac
commit
925fccbd17
2 changed files with 9 additions and 9 deletions
|
@ -60,6 +60,12 @@ class Access
|
||||||
return intval($user->accessRank) >= $minAccessRank;
|
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)
|
public static function assert($privilege, $subPrivilege = null)
|
||||||
{
|
{
|
||||||
if (!self::check($privilege, $subPrivilege))
|
if (!self::check($privilege, $subPrivilege))
|
||||||
|
|
|
@ -263,13 +263,11 @@ class PostController
|
||||||
$context = getContext();
|
$context = getContext();
|
||||||
$post = PostModel::findByIdOrName($id);
|
$post = PostModel::findByIdOrName($id);
|
||||||
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
|
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
|
||||||
|
Access::assertAuthentication();
|
||||||
|
|
||||||
if (!InputHelper::get('submit'))
|
if (!InputHelper::get('submit'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Auth::isLoggedIn())
|
|
||||||
throw new SimpleException('Not logged in');
|
|
||||||
|
|
||||||
UserModel::updateUserScore(Auth::getCurrentUser(), $post, 1);
|
UserModel::updateUserScore(Auth::getCurrentUser(), $post, 1);
|
||||||
UserModel::addToUserFavorites(Auth::getCurrentUser(), $post);
|
UserModel::addToUserFavorites(Auth::getCurrentUser(), $post);
|
||||||
StatusHelper::success();
|
StatusHelper::success();
|
||||||
|
@ -280,13 +278,11 @@ class PostController
|
||||||
$context = getContext();
|
$context = getContext();
|
||||||
$post = PostModel::findByIdOrName($id);
|
$post = PostModel::findByIdOrName($id);
|
||||||
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
|
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
|
||||||
|
Access::assertAuthentication();
|
||||||
|
|
||||||
if (!InputHelper::get('submit'))
|
if (!InputHelper::get('submit'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Auth::isLoggedIn())
|
|
||||||
throw new SimpleException('Not logged in');
|
|
||||||
|
|
||||||
UserModel::removeFromUserFavorites(Auth::getCurrentUser(), $post);
|
UserModel::removeFromUserFavorites(Auth::getCurrentUser(), $post);
|
||||||
StatusHelper::success();
|
StatusHelper::success();
|
||||||
}
|
}
|
||||||
|
@ -296,13 +292,11 @@ class PostController
|
||||||
$context = getContext();
|
$context = getContext();
|
||||||
$post = PostModel::findByIdOrName($id);
|
$post = PostModel::findByIdOrName($id);
|
||||||
Access::assert(Privilege::ScorePost, Access::getIdentity($post->getUploader()));
|
Access::assert(Privilege::ScorePost, Access::getIdentity($post->getUploader()));
|
||||||
|
Access::assertAuthentication();
|
||||||
|
|
||||||
if (!InputHelper::get('submit'))
|
if (!InputHelper::get('submit'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Auth::isLoggedIn())
|
|
||||||
throw new SimpleException('Not logged in');
|
|
||||||
|
|
||||||
UserModel::updateUserScore(Auth::getCurrentUser(), $post, $score);
|
UserModel::updateUserScore(Auth::getCurrentUser(), $post, $score);
|
||||||
StatusHelper::success();
|
StatusHelper::success();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue