1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-07-06 00:41:09 +08:00
2019-12-13 00:10:10 +08:00

38 lines
786 B
PHP

<?php
namespace App\Validators;
use App\Exceptions\Forbidden as ForbiddenException;
use App\Exceptions\Unauthorized as UnauthorizedException;
use Phalcon\Mvc\User\Component as UserComponent;
class Validator extends UserComponent
{
public function checkAuthToken($token)
{
if (!$token) {
throw new UnauthorizedException('sys.invalid_auth_token');
}
return $token;
}
public function checkAuthUser($user)
{
if (!$user) {
throw new UnauthorizedException('sys.auth_user_failed');
}
return $user;
}
public function checkOwner($itemUserId, $sessionUserId)
{
if ($itemUserId != $sessionUserId) {
throw new ForbiddenException('access_denied');
}
}
}