web.php (файл маршрута):
Код: Выделить всё
Route::post('login', array(
'uses' => 'UserController@doLogin'
));
Route::get('logout', array('uses' => 'UserController@doLogout'));
Route::group(['middleware' => 'AuthMiddleWare'], function () {
Route::get('/form', function () {
return view('form');
});
Route::get('/createUser', function () {
return view('users');
});
Route::get('logout', array(
'uses' => 'UserController@doLogout'
));
});
Код: Выделить всё
public function doLogin()
{
$rules = array(
'name' => 'required', // make sure the email is an actual email
'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
}
else {
// create our user data for the authentication
$userdata = array(
'name' => Input::get('name'),
'password' => Input::get('password')
);
$auth = DB::table('users')->where('name', '=', Input::get('name'))->where('password', '=', Input::get('password'))->get()->first();
// attempt to do the login
if (Auth::attempt($userdata)) {
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
echo 'SUCCESS!';
} else {
// validation not successful, send back to form
return Redirect::to('login');
}
}
}
Код: Выделить всё
LOGIN
Как я могу узнать, что не так?
Заранее спасибо.
Подробнее: https://stackoverflow.com/questions/488 ... -302-found
Мобильная версия