我正在使用Laravel身份验证系统,虽然注册工作并将用户登录,并在数据库中创建条目,但登录并没有做任何事情。我已将Laravel项目文件夹包含在Google驱动器上,因此如果您设置了自己的数据库,则可以直接查看服务器配置之外的任何可能原因。请注意,在我添加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
答案 0 :(得分:0)
问题是您的登录表单已发布到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">
复制和粘贴错误/拼写错误的简单案例。