S
S
Stepan2015-09-27 14:19:54
User identification
Stepan, 2015-09-27 14:19:54

How to implement REST authentication in laravel 4?

How to implement REST authentication in laravel 4?
The old project guide asks to translate to REST. There is the following:
Constructor

$this->beforeFilter(function() {
         if(Request::format() == 'html') {
             if (!Auth::check() ){
        return Redirect::to('/login');
    } else {
     $this->user_id = Auth::user()->id;
     $this->zipcode = Session::get('zipcode');
        $this->store_id = Session::get('store_id');
        $this->city = City::where('zipcode',$this->zipcode)->first();
        $this->stores = DB::table('stores')
             ->leftJoin('store_locations','stores.id','=','store_locations.store_id')
             ->where('store_locations.zipcode',$this->zipcode)
             ->get();
        $this->departments = Department::where('store_id',$this->store_id)->get();
        $this->store = Store::find($this->store_id);
        $this->cart_id = Session::get('cart_id');
    }
   } else {
    $this->user_id = Input::get('user_id');
    $token = Input::get('token');                      // Initialize cart id as well
    if(User::where('token','=',$token)->where('id', $this->user_id)->count() == 0 ){
     $response_array = array('success' =>'false' , 'error_code' => '400', 'error' => 'Invalid Token');
     $response_code = 200;
     $response = Response::json($response_array , $response_code);
     return $response;
    }
   }
        } ,array('except' => array('login','verify','save','register','zipcode','social','forgot_password')));
    }

I make a request for authorization through the REST console, I get a normal response.
Next, I make a request to another controller like cart. Writes that it is not authorized.
How to understand what and how it authorizes there? Tried to send login password in headers but all in vain.
By debugging: it goes to $this->user_id = Input::get('user_id');
$token = Input::get('token');
And does not understand where to get these Input ?
Send them with every request? Or how? Do a hidden input on every page?
I do not understand how to do and what I missed, I will be grateful for the help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question