I have a registration form which works to register and login user. I use $this->middleware('auth'); in the controllers on protected routes to prompt users to login. The login form passes a POST request to Laravel's AuthController w/ username and password:
<input type="hidden" name="_token" value="XXXXXXXXXX">
<div class="widget-content">
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password" name="password">
<input class="btn btn-blue pull-right" type="submit" />
</div>
</form>
Routes:
//authentication routes
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
I've tried using the authentication system's off-the-shelf postLogin() functionality, tried passing username, name, email to it without any luck. I tried overriding the parent method like this:
public function postLogin(Request $request)
{
$username = $request->input('username');
$password = $request->input('password');
if (Auth::attempt(['name' => $username, 'password' => $password])) {
// Authentication passed...
return redirect('dashboard');
} else {
return redirect()->intended('auth/login');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire