dimanche 25 octobre 2015

How to authenticate the user base on the reponse of my API using Laravel?

Description:

I have been using Laravel for a bunch of project now. Implementing User Authentication is simple in Laravel.

I've done that here :

// Posting the sign-in information and check it with the database
    public function postSignIn(){


        $validator = Validator::make(Input::only('username', 'password') , array(
          'username' => 'required',
          'password' => 'required'
        ));


        if ($validator->fails()) {
          return Redirect::to('/')->with('error', 'Please fill out your information ')->withErrors($validator)->withInput();
        }
        $username = strtolower(Input::get('username'));
        $password = Input::get('password');


        $auth = Auth::attempt(array(
          'username' => $username,
          'password' => $password
        ));

        if ($auth) {
          return Redirect::to('/dashboard')->with('success', 'Hi '. $username .' ! You have been successfully logged in.');
        }
        else {
          return Redirect::to('/')->with('error', 'Username/Password Wrong')->withInput(Request::except('password'))->with('username', $username)->withErrors($validator);
        }
      }


Problem:

Now, the structure that I am dealing with is a little different - I don't have a database or a users table locally.

I have to make an API call to query what I need.


I have a log-in form. As soon as a user submit to that form. I make an API call to

http://ift.tt/1OPlw5Y

if the response showing that user is exist then I want to allow them in.


Can I still use Laravel to achieve the log-in feature ?

Can someone shed some lights on this ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire