mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 20:06:09 +08:00
38 lines
749 B
PHP
38 lines
749 B
PHP
<?php
|
|
|
|
namespace App\Validators;
|
|
|
|
use App\Exceptions\Forbidden as ForbiddenException;
|
|
use App\Exceptions\Unauthorized as UnauthorizedException;
|
|
use Phalcon\Mvc\User\Component;
|
|
|
|
class Validator extends Component
|
|
{
|
|
|
|
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($userId, $ownerId)
|
|
{
|
|
if ($userId != $ownerId) {
|
|
throw new ForbiddenException('sys.access_denied');
|
|
}
|
|
}
|
|
|
|
}
|