Hey,
I'm looking for a way to create a custom login authentication with Laravel. I have a login form that look like this:
{!! Form::open(array('route' => array('login/post'), 'class' => 'form-horizontal')) !!}
<div class="form-group">
<div class="col-xs-12">
{!! Form::text('username-wl', '', ['class' => 'form-control', 'placeholder' => 'Your login name...']) !!}
@if ($errors->has('username-wl'))<span class="help-block" style="color:red;">{!!$errors->first('username-wl')!!}</span>@endif
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
{!! Form::password('password-wl', ['class' => 'form-control', 'placeholder' => 'Your password...']) !!}
@if ($errors->has('password-wl'))<span class="help-block" style="color:red;">{!!$errors->first('password-wl')!!}</span>@endif
</div>
</div>
<div class="form-group form-actions">
<div class="col-xs-8">
</div>
<div class="col-xs-12 text-right">
<button type="submit" id="login" class="btn btn-effect-ripple btn-sm btn-primary"><i class="fa fa-check"></i> Let's Go</button>
</div>
</div>
{!! Form::close() !!}
Now this above code works perfectly.
I'm also doing an error checking with Requests. So I have a file called: LoginRequest.php, that looks like this:
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class LoginRequest extends Request {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'user' => 'required',
'password' => 'required'
];
}
}
This validation works prefectly. When I pust the login button and nothing is filled, it gets me the error messages.
I'm calling this Request from one of my controller's method:
public function login(LoginRequest $request)
{
return $request;
}
Now, what I want to do is, checking when the post is submitted and there are no errors, I should be able to run custom functions on the user that's logged in.
I have tried to do this via a Middleware, however it seemd like that the Middleware is running before the Requests, so if the form is empty for example, the Middleware - and my custom functions - will still run.
I want something like this logic:
User submits info -> incorrect error messages shown (if applies) -> Custom functions run -> if username & password is correct then redirect and login, else -> redirect to login page.
Can someone give me any direction what am I missing here?
Would appreciate it a lot!