For some reason, I'm unable to login with the correct username/password combination. I'm using flash messages to show when the login information is incorrect.
I've tried creating multiple accounts to make sure I wasn't actually entering the wrong login credentials, but after about an hour of fiddling it's still not working.
Any help would be greatly appreciated! Thank you!
Here's what I got.
UsersController.php (postCreate) - Function that creates my user account (working perfectly fine)
public function postCreate() {
$rules = array(
'username'=>'required|unique:users,username|alpha_dash|min:4',
'password'=>'required|min:8|confirmed',
'password_confirmation'=>'required|min:8',
'email'=>'required|email|unique:users,email'
);
$input = Input::only(
'username',
'password',
'password_confirmation',
'email'
);
$validator = Validator::make($input, $rules);
if($validator->fails())
{
return Redirect::to('register')->withErrors($validator)->withInput();
}
//$confirmation_code = str_random(30);
User::create(array(
'username'=>Input::get('username'),
'password'=>Hash::make(Input::get('password')),
'email'=>Input::get('email')
//'comfirmation_code' => $confirmation_code
));
// Mail::send('email.verify', function($message) {
// $message->to(Input::get('email'), Input::get('username'))
// ->subject('Verify your email address');
// });
// Flash::message('Thanks for signing up! Please check your email.');
return Redirect::to('login')->with('message', 'Thanks for signing up! Please check your email.');
}
UsersController.php (postLogin) - Function that logs me into account
public function postLogin() {
$user = array(
'email'=>Input::get('email'),
'password'=>Input::get('password')
);
if (Auth::attempt($user)){
return Redirect::intended('account')->with('message', 'Welcome back!');
} else {
return Redirect::to('login')
->with('message', 'Your username/password was incorrect')
->withInput();
}
}
Routes.php
Route::get('login', array('as'=>'login', 'uses'=>'UsersController@getLogin'));
Route::post('login', array('before'=>'csrf', 'uses'=>'UsersController@postLogin'));
login.blade.php - My login Page
@if($errors->has())
<p>The following errors have occured:</p>
<ul id="form-errors">
{{ $errors->first('username', '<li>:message</li>') }}
{{ $errors->first('password', '<li>:message</li>') }}
</ul>
@endif
@if (Session::has('message'))
<p>{{ Session::get('message') }}</p>
@endif
{{ Form::open(array('action'=>'login')) }}
<p>
{{ Form::label('username', 'Username') }}<br />
{{ Form::text('username', Input::old('username')) }}
</p>
<p>
{{ Form::label('password', 'Password') }}<br />
{{ Form::password('password') }}
</p>
<p>
{{ Form::submit('Login') }}
</p>
{{ Form::close() }}