Support the ongoing development of Laravel.io →
Authentication Input
Last updated 2 years ago.
0

Have you actually tryed searching the Authentication / Security section where there are tons and tons of threads on the subject already? But here we go again:

<?php namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller {

	/*
	|--------------------------------------------------------------------------
	| Registration & Login Controller
	|--------------------------------------------------------------------------
	|
	| This controller handles the registration of new users, as well as the
	| authentication of existing users. By default, this controller uses
	| a simple trait to add these behaviors. Why don't you explore it?
	|
	*/

	use AuthenticatesAndRegistersUsers;

	/**
	 * Create a new authentication controller instance.
	 *
	 * @param  \Illuminate\Contracts\Auth\Guard  $auth
	 * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
	 * @return void
	 */
	public function __construct(Guard $auth, Registrar $registrar)
	{
		$this->auth = $auth;
		$this->registrar = $registrar;

		$this->middleware('guest', ['except' => 'getLogout']);
	}
        
        
           public function getLogin()
	{
		return view('auth.login');
                //return view('auth.testview');
	}
        
        public function postLogin(Request $request)
	{
		$this->validate($request, [
			'userid' => 'required', 'password' => 'required',
		]);
                
                //added
                
             $tvar = $request->input('userid');
             $pw = $request->input('password');
            if ($this->auth->attempt(['userid' => $tvar, 'password' => $pw]))
		{
                    //echo 'logged in========'.$request->user->userid;
                    echo 'logged in========'.$request->user()->userid;
                    $yourvar = $request->user()->userid;
                    echo $yourvar;
                    echo "====loggin in now";
                    return redirect('pets');
		}
            else
                {
                    echo ' not logged in';
                }

                //added

		/*$credentials = $request->only('email', 'password');

		if ($this->auth->attempt($credentials, $request->has('remember')))
		{
			return redirect($this->redirectPath());
		}

		return redirect('/auth/login')
					->withInput($request->only('email'))
					->withErrors([
						'email' => 'These credentials do not match our records.',
					]);*/
	}
        
        public function getLogout()
	{
		$this->auth->logout();

		return redirect('/');
	}



}//end class

Like this, nothing else. I use userid, NOT email.
By the way docs are not up to date on auth.

Last updated 9 years ago.
0

Thanks a lot

0

Sign in to participate in this thread!

Eventy

Your banner here too?

hectacon hectacon Joined 15 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.