[英]Laravel 5.1 authentication login not working
我正在使用Laravel身份验证系统,虽然注册有效并且将用户登录,并在数据库中创建条目,但登录没有任何作用。 我已经在Google驱动器上压缩了Laravel项目文件夹,因此如果您设置自己的数据库,则可以直接查看服务器配置不足的任何潜在原因。 请注意,这个问题在我添加jQuery mobile之前就存在,因此不是AJAX加载。
https://drive.google.com/file/d/0BzXcUhw2pTQpQTM2ME9mU19lbkE/view?usp=sharing
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers;
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
protected $redirectPath = '/product';
/**
* 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, [
'name' => '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([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
和routes.php:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/*Route::get('/', function () {
return view('welcome');
});*/
Route::get('/', 'WelcomeController@index');
Route::get("home", function (){ return view('welcome');} );
Route::get("checkuser", function() {return Auth::user(); });
//Route::get('product', 'WelcomeController@product');
//Route::controller('WelcomeController');
//product routes
Route::get("products", 'ProductController@products');
Route::get("product/{id}", 'ProductController@product');
// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
login.blade.php:
@extends('master.master')
@section('content')
<div id='login-form'>
<form method="POST" action='{!! url("auth/register")!!}' data-ajax="false">
{!! csrf_field() !!}
<div id='emailBox'>
<label for='email'>Email:</label>
<input name='email' id='email' type='email' value="{{ old('email') }}"/>
</div>
<div id='passBox'>
<label for='password'>Password</label>
<input name='password' id='password' type='password' />
</div>
<div id='rememberBox'>
<label for='remember'>Remember Me!</label>
<input name='remember' id='remember' type='checkbox' />
</div>
<div id='loginBox'>
<input type="submit" value="Log In!" id='loginButton' class='cloudButton'>
</div>
</form>
</div>
@stop
register.blade.php:
@extends('master.master')
@section('content')
<div id='register'>
<form method="post" action='{!! url("auth/register")!!}' data-ajax="false">
{!! csrf_field() !!}
<div id='nameBox'>
<label for='name'>First Name:</label> <input name='name' id='name'
type='text'>
</div>
<div id='emailBox'>
<label for='email'>Email:</label> <input name='email' id='email'
type='email' value="{{ old('email') }}" />
</div>
<div id='passBox'>
<label for='password'>Password:</label> <input name='password'
id='password' type='password' />
</div>
<div id="confirmBox">
<label for='password'>Confirm Password:</label>
<input type="password" name="password_confirmation">
</div>
<div id='signUpBox'>
<input type="submit" value="Sign Up!" id='signUpButton' class='cloudButton'>
</div>
</form>
</div>
@stop
问题是您的登录表单正在发布到auth/register
页面:
<div id='login-form'>
<form method="POST" action='{!! url("auth/register")!!}' data-ajax="false">
应该:
<div id='login-form'>
<form method="POST" action='{!! url("auth/login")!!}' data-ajax="false">
复制和粘贴错误/错字的简单情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.