1
votes

I'm using laravel 5.3 and already found out that the old auth controller has been moved to the core (Illuminate...). For unauthenticated users there is a "unauthenticated" function in App\Exceptions\Handler.php which is called when an unathenticated user throws an "authentication"-exception.

However I didn't found out where to put a function which should be called everytime a user successfully logs in or has been authenticated successfully by the remember token. In my example this function should do some things like log ip etc.

Can you help me where to put such a function?

Thanks!

4

4 Answers

1
votes

I think it can be done using this command in command prompt.

php artisan make:auth
0
votes

Unless I am missing something, there is no "unauthenticated" function in App\Exceptions\Handler.php of Laravel 5.3

You should look into authorization actions

Laravel 5.3 comes with the Auth scafolding pre-packaged.

PROJECT/app/Http/Controllers/Auth 
0
votes

In 5.3 I just modified the success and failure actions for the login using the out-of-the-box authentication. This Gist might be helpful to you. It actually explains step-by-step how to login using api/login and pass back a token to a mobile platform. Then you can subsequently call back to all of your API's with the token. I modified the returns to recognize the Json request header and send back the user as json.

Here is the information that might help you. Laravel API Token Help

0
votes

Here is a custom auth solution.

class AdminsController extends Controller
{
    public function getLogin()
    {
        return view('admin.login');
    }

    public function postLogin(Request $request)
    {
        $this->validate($request, ['email' => 'required|email', 'password' => 'required']);

        if(!Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
            return redirect()->back()->with(['fail' => 'Could not log you in!']);
        }

        return redirect()->route('admin.dashboard');

    }

    public function getLogout()
    {
            Auth::logout();
            return redirect()->route('index');
    }
}

And in the routes.php :

Route::group(['middleware' => ['guest']], function () {

    Route::get('/admin/login', [
        'uses' => 'AdminsController@getLogin',
        'as' => 'admin.login'
    ]);

    Route::post('/admin/login', [
        'uses' => 'AdminsController@postLogin',
        'as' => 'admin.login'
    ]);
});

Route::group(['middleware' => ['auth']], function () {
    Route::get('/admin/logout', [
        'uses' => 'AdminsController@getLogout',
        'as' => 'admin.logout'
    ]);
});

Hope you get around with this code and that it was helpful.