I have created a new Laravel 5.2 installation. And I have run the following command to install the default Laravel authentication;
php artisan make:auth
The registration form works but the login just redirects home without logging in. And displays no errors when when I enter the wrong credentials.
This is my routes file:
Route::get('/', 'BaseController@index');
Route::get('/tutors', 'TutorsController@Index');
Route::get('/tutors/myrequest', 'TutorsController@RequestTutor');
Route::get('/tutors/{id}', 'TutorsController@show')->where(['id' => '[0-9]+']);
Route::get('/tutors/{GUID}', 'TutorsController@TutorByGUID')->where(['id' => '[A-Za-z]+[0-9]+']);
/********************Authentication routes**********************************/
Route::group(['middleware' => ['web']], function () {
Route::auth();
});
This is code from the AuthController
:
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
protected $redirectTo = '/';
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
This is the BaseController
which contains the home method;
<?php namespace App\Http\Controllers;
use App\Services\InterfaceService;
use App\Repositories\TutorRepository;
use App\Http\Requests;
use Illuminate\Http\Request;
class BaseController extends Controller {
protected $TutorRepository;
protected $InterfaceService;
public function __construct(InterfaceService $InterfaceService, TutorRepository $TutorRepository)
{
//$this->middleware('guest');
$this->InterfaceService = $InterfaceService;
$this->TutorRepository = $TutorRepository;
}
public function index()
{
$tutors = $this->TutorRepository->all();
$page_info = \Config::get('constants.App.Pages.home');
$this->InterfaceService->SetPageInfo($page_info);
return view('home', ['TopTutors'=>$tutors]);
}
} ?>
This is code from the login view.
<form role="form" method="POST" action="{{ url('/login') }}" id="login_form">
{!! csrf_field() !!}
<div class="mj_login_form">
<div class="form-group">
<input type="text" placeholder="Email" id="email" name="email" class="form-control" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block"><strong>{{ $errors->first('email') }}</strong></span>
@endif
</div>
<div class="form-group">
<input type="password" placeholder="Your Password" id="password" class="form-control" name="password">
@if ($errors->has('password'))
<span class="help-block"><strong>{{ $errors->first('password') }}</strong></span>
@endif
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 mj_toppadder20">
<div class="form-group pull-left">
<div class="mj_checkbox">
<input type="checkbox" value="1" id="check2" name="remember">
<label for="check2"></label>
</div>
<span> remember me</span>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 mj_toppadder20">
<div class="form-group pull-right">
<span><a href="{{ url('/password/reset') }}">forget password ?</a></span>
</div>
</div>
</div>
</div>
<div class="mj_pricing_footer">
<a href="#" onclick="$('#login_form').submit()">login Now</a>
</div>
</form>