0

I just created a simple login with guest middleware that allows the user to access one account at a time, but I am just worried if this is the right way to do it.

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

        Route::get('/', 'LoginController@index')->name('login');
        Route::post('/', 'LoginController@post')->name('login.post');

    });



/** login.post controller **/
    public function post(Request $request){
            $this->rules($request);

            $rules = array(
                'username' => $request->username,
                'password' => $request->password,
            );

            if(Auth::attempt($rules)) {
                if(Auth::user()->is_active == true){
                /** IF THE USER IS CURRECTLY LOGIN **/
                 if(Auth::user()->is_login == true){
                   Auth::logout();
                   Session::flash('multilog', 'Your account is log-in to another device!!');
                   return redirect('/')->withInput();
                 }
                $user = user::find(Auth::user()->id); 
                $user->is_login = true;
                $user->save();
                return redirect('admin/home');
                }
                Session::flash('unactivated', 'Your account is not activated!!');
                return redirect('/')->withInput();
            }
            Session::flash('unmatch', 'Invalid username or password!!');  
            return redirect('/')->withInput();
        }

/** **/

1 Answer 1

2

If you are not sure, you can use Laravel to create authentication. Write in command line:

php artisan make:auth

Then just look how the logic works in files. More you can read here: https://laravel.com/docs/5.5/authentication

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.