Laravel 5.2 login with Laravel Auth Component and AngularJS

I want to develop login functionality with Auth component of laravel and angularJS. Laravel's Auth component handles all the requirement of login system. ie Store login session, redirect to dashboard or requested page if user is already logged in, redirect to login page if user is not logged in, authenticate http request using csrf token etc. Now, I want to develop these all functionality using Auth component of laravel and AngularJS. So I don't know that if I developed login functionality with angularJS, will laravel still handle all functionality as mentioned above ? I have doubt because articles on internet tells that I can do it using token based authentication. If I do token based login using angular? Then how I can handle redirection to login for not logged in users, redirection to previous requested page for logged in users, authentication every http request etc. If anyone can explain with some demo or link , it will be appreciated.

I have refereed some links. But I can't get that how to maintain other functionalities like redirection of page, authenticate request etc. Here are links.

  • http://justinvoelkel.me/laravel-angularjs-part-two-login-and-authentication/
  • http://ryanchenkie.com/token-based-authentication-for-angularjs-and-laravel-apps/

  • laravel Auth provide every functionality that you have listed above.

    Login:
    $condition = array('email' => $emailId, 'password' => $password);
    if(Auth::attempt($condition, $remember))
    {
        // successful login
    }
    else
    {
        // redirect to login page
        return redirect()->to('/signup');
    }
    
    
    CSRF Token
    Route::get('/',[
        'middleware'=>'auth',       // middleware auth checks for csrf token on every routing done through routes.php
        'uses'=>'HomeController@function'
    ]);
    

    etc


    To check if a user is logged, just check his token though a middleware, there is a JWT package for Laravel which makes it really easy to use.

    To handle login:

    AngularJS send a request to your Laravel API. Larevel check if everything is ok for login:

  • If everything is ok, Laravel should return the token
  • If not return an error (HTTP codes) and handle it in Angular
  • If something isn't clear or if you need more information feel free to ask

    链接地址: http://www.djcxy.com/p/33116.html

    上一篇: 与Google的Laravel Socialite保存不同的ID号码,导致重复的错误

    下一篇: Laravel 5.2使用Laravel Auth Component和AngularJS登录