Hello i am new to laravel i made login form using Auth .. when i attempt to login i get redirected to homepage but i use Auth::check()
it return false
for example
@if (Auth::check())
<h1>Welcome you are loggeding</h1>
@else
<h1>No you are not loggedin</h1>
@endif
So when i login i see No you are not loggedin and when i intend to use wrong username or password to make login fails it really fail and return error message These credentials do not match our records. But when i login and get redirected to homepage without seeing any error message this means that login is working so how come Auth::check()
return false and i see No you are not loggedin
Even Auth::user()
return null
P.S: the login was working fine until i tried php artisan session:table
then migrated the table and changed the SESSION_DRIVER
to database inside session.php and even the sessions table was not actually saving data in it so i rolled back everything when i found that login isn't working anymore i removed the table and changed the driver to file and removed session files in storage\framework\sessions
.env file
APP_NAME=Eshows
APP_ENV=local
APP_KEY=base64:wG+6H+MFxNXa2mTw+UPhCkBIXmL5CMCE11sudm51kyE=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://eshows.dev/
APP_DOMAIN=eshows.dev
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=eshows
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
Controllers\Auth\LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
/*public function authenticated($request, $user)
{
return redirect('/profile/' . $user->username);
}*/
}
App\User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'username', 'email', 'password', 'phone', 'mobile', 'city', 'country', 'about',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function user()
{
return $this->hasMany('App\User');
}
}
route\web.php
//Authentication routes
Auth::routes();
Route::get('logout', ['as' => 'logout', 'uses' => 'Auth\LoginController@logout']);
Route::get('/','Frontend\HomeController@index');
Http\Middleware\RedirectIfAuthenticated.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
switch($guard) {
case 'admin':
if(Auth::guard($guard)->check()) {
return redirect()->route('admin.dashboard');
}
break;
default:
if (Auth::guard($guard)->check()) {
return redirect('/');
}
break;
}
return $next($request);
}
}
view\auth\login.blade.php
@extends('frontend.layouts.master')
@section('body-attrs')
class="page-template-default page page-id-12 contact-us"
@endsection
@section('csrf-meta')
<!-- CSRF Token -->
<meta name="csrf-token" content="">
@endsection
@section('csrf-script')
<script>
window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
]) !!};
</script>
@endsection
@section('title')
Login to your account
@endsection
@section('styles')
<!-- BEGIN PAGE STYLE -->
{!! Html::style('assets/common/css/parsley.css') !!}
<!-- END PAGE STYLE -->
@endsection
@section('content')
<div class="banner">
<div class="heading-wrapper"><h1>Login to your account or create new one.</h1></div>
</div>
<section class="two-columns">
<div class="container-fluid narrow">
<div class="row">
<div class="col-sm-6 matchHeight column bg-image">
<h2 class="text-center">Login to your account</h2><hr>
<h4>Explore big community of talented people or begin branding for your own talent to everyone</h4>
<article>
{!! Form::open(['route' => 'login', 'role' => 'form', 'data-parsely-validate' => '', 'id' => 'wpcf7-f6-o1', 'class' => 'wpcf7 form-validation']) !!}
@if (count($errors))
<ul>
@foreach($errors->all() as $error)
<li style="color:red;"></li>
@endforeach
</ul>
@endif
<div class="form-group">
<p>
<span class="wpcf7-form-control-wrap your-name">
<div class="append-icon">
{!! Form::text('username', old('username'), array('class' => 'form-control form-white', 'id' => 'username', 'placeholder' => 'Enter your username...', 'autofocus' => '', 'required' => '')) !!}
<i class="icon-envelope"></i>
@if ($errors->has('username'))
<span class="help-block">
<strong></strong>
</span>
@endif
</div>
</span>
</p>
</div>
<div class="form-group">
<p>
<span class="wpcf7-form-control-wrap your-name">
<div class="append-icon">
{!! Form::password('password', array('class' => 'form-control form-white', 'id' => 'password', 'required' => '')) !!}
<i class="icon-lock"></i>
@if ($errors->has('password'))
<span class="help-block">
<strong></strong>
</span>
@endif
</div>
<br>
<input id="remember" type="checkbox" style="float:left;margin:8px 3px 0 0" name="remember" > <span style="display:block;padding-top:3px;">Remember me </span>
<br><hr><a href="" style="margin:0" class="forgot-password">Forgot your password?</a>
</span>
</p>
</div>
<div class="form-group">
<p>
<span class="wpcf7-form-control-wrap your-name">
<button type="submit" style="color:#FFFFFF;margin-top:15px" class="btn btn-rounded btn-white btn-signup hover-effect">Login to my account</button>
</span>
</p>
</div>
{!! Form::close() !!}
</article>
</div>
<div class="col-sm-6 matchHeight column bg-image">
<div class="create-account">
<h2 class="text-center">Create an Account</h2>
<h3>Don't have an account yet?</h3>
<p>You can create your acount quickly to save your wishlist, your address and other usefull info.</p>
<div class="text-center m-t-40">
<a href="" class="btn btn-rounded btn-white btn-signup hover-effect">Create my Account <i class="fa fa-chevron-right"></i></a>
</div>
</div>
</div>
</div>
</div>
</section>
@endsection
@section('scripts')
<!-- BEGIN PAGE SCRIPTS -->
{!! Html::script('assets/frontend/plugins/parallax/scripts/jquery.parallax-1.1.3.js') !!}
{!! Html::script('assets/common/js/parsley.min.js') !!}
<!-- END PAGE SCRIPTS -->
@endsection
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire