示例#1
0
 function __invoke($req, $res, $next)
 {
     $apip = apip::getInstance();
     $userId = utils::getRequestHeader($req, 'AliceSPA-UserID');
     $webToken = utils::getRequestHeader($req, 'AliceSPA-WebToken');
     $userId = empty($userId) ? null : $userId[0];
     $webToken = empty($webToken) ? null : $webToken[0];
     if ($userId === null || $webToken === null) {
         $apip->pushError(3);
         return $res;
     }
     $r = utils::disposeAPIException(function () use($userId, $webToken) {
         return authService::getInstance()->authenticateByWebToken($userId, $webToken);
     }, [1 => ['dispel' => 3, 'dispelPushError' => false]]);
     if ($r === false) {
         $apip->pushError(3);
         return $res;
     }
     $roles = $req->getAttribute('route')->getArgument('AliceSPA_Roles');
     $r = authService::getInstance()->checkRoles($roles);
     if ($r === false) {
         $apip->pushError(5);
         return $res;
     }
     return $next($req, $res);
 }
示例#2
0
 public function register($req, $res, $args)
 {
     $auth = $this->c->get('auth');
     $apip = $this->c->get('apip');
     $parsedBody = $req->getParsedBody();
     $r = utils::disposeAPIException(function () use($parsedBody, $auth) {
         return $auth->registerByUnionField($parsedBody, $parsedBody['password']);
     }, [2 => ['dispel' => 4]]);
     if (!($r === true)) {
         return $res;
     }
     $r = $auth->loginByUnionField($parsedBody, $parsedBody['password']);
     $apip->setData($r);
     return $res;
 }