Beispiel #1
0
 public function authFilter()
 {
     // Only need to check if user is not already logged in
     // If user is already logged in, means ajax request
     if (!Amp::check()) {
         if (!\Input::get('auth_token')) {
             throw new APIException('Auth token not set', 401);
         }
         $token = APIToken::where('device_id', '=', \Input::get('device_id'))->where('token', '=', \Input::get('auth_token'))->get();
         if ($token->isEmpty()) {
             throw new APIException('User not authenticated', 401);
         }
         $token = $token->first();
         if (\Input::get('auth_token') != $token->token) {
             throw new APIException('Invalid auth token', 401);
         }
         $user = \Repo::call('User')->find($token->user_id);
         if (!$user) {
             throw new APIException('User not found', 401);
         }
     }
 }
Beispiel #2
0
 public function validate($contexts = [], $data = null)
 {
     if (!$data) {
         $data = \Input::all();
     }
     $valid = \Amp::validator($data, $this);
     // Allows us to add different contexts for validation
     foreach ($contexts as $context) {
         $valid->addContext($context);
     }
     if ($valid->fails()) {
         $this->messages = $valid->messages();
         return false;
     }
     return true;
 }