So i have some problem with laravel 5 login authentication.I'm have try everyway but the only result i get it's false when the code run to if($this-> auth -> attempt($auth))
statement .So what i have been missing.Here it's the code
UserController.php
<?php namespace App\Http\Controllers;
use App\Users;
use App\Http\Controllers\Controller;
use App\Http\Requests\FormValRequest;
use App\Http\Requests\Request;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Auth;
use Hash;
class UsersController extends Controller {
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Sign in function to validate input
*
* @return if success return to index page
* else return error message
*/
use AuthenticatesAndRegistersUsers;
public function login(FormValRequest $request)
{
$auth = array(
'username' => $request -> txtUsernameLogin,
'password' => $request -> txtPasswordLogin
);
if($this-> auth -> attempt($auth))
{
echo "success";
}
else
{
echo "fail";
}
}
}
Routes.php
Route::post('authen/login',['as' => 'login','uses'=>'UsersController@login']);
FormValRequest.php
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class FormValRequest 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 [
'txtUsernameLogin' => 'required',
'txtPasswordLogin' => 'required',
];
}
public function messages()
{
return [
'txtUsernameLogin.required' => 'Please input your username',
'txtPasswordLogin.required' => 'Please input your password',
];
}
}
And the view footer.blade.php(i'm using bootstrap popup modal )
<form action="{{ url('/authen/login') }}" method="POST" name="SignInForm">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
<ul class="social-login">
<li><a class="btn btn-facebook"><i class="fa fa-facebook"></i>Sign In with Facebook</a></li>
<li><a class="btn btn-google"><i class="fa fa-google-plus"></i>Sign In with Google</a></li>
<li><a class="btn btn-linkedin"><i class="fa fa-linkedin"></i>Sign In with LinkedIn</a></li>
</ul>
<hr>
<div class="form-group">
<label for="login-username">Username</label>
<input type="text" class="form-control" id="txtUsernameLogin" name="txtUsernameLogin">
{!! $errors -> first('txtUsernameLogin') !!}
</div>
<div class="form-group">
<label for="login-password">Password</label>
<input type="password" class="form-control" id="txtPasswordLogin" name="txtPasswordLogin">
{!! $errors -> first('txtPasswordLogin') !!}
</div>
<button type="submit" class="btn btn-primary">Sign In</button>
</form>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire