当前位置: 首页 > 知识库问答 >
问题:

Laravel 5.1身份验证登录不工作

邹书
2023-03-14

我正在开发一个Laravel身份验证系统,当注册生效时,用户会登录,并在数据库中创建条目,但登录不起任何作用。我已经包括了谷歌硬盘上压缩的Laravel项目文件夹,因此如果您设置自己的数据库,您可以直接查看服务器配置不足的任何潜在原因。注意,这个问题在我添加jquerymobile之前就存在了,所以它不是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']),
        ]);
    }
}

和路线。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');

登录。刀身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

登记刀身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

共有1个答案

柯鸿云
2023-03-14

问题是您的登录表单正在发布到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">

复制粘贴错误/打字错误的简单案例。

 类似资料:
  • 使用,https://github.com/firebase/FirebaseUI-Android/tree/master/codelabs/chat作为登录的参考,我在键入时似乎遇到了问题 我只能键入Auth的提供者,而不能键入,为什么会这样,它提示我键入社会提供者。

  • 我已经在我的xamarin Android应用程序中实现了脸书认证,一切都很好。我从facebook获得令牌,并使用firebase rest Api的sigin方法,我能够sigin到firebase,并从firebase Api收到一个访问令牌,作为JWT。但是,当我想在我的Web Api核心上使用这个访问令牌时,它总是返回not authenticated。我的Web Api核心使用下面基于

  • 当使用Firebase身份验证匿名帐户时,它偶尔会在系统中创建一个新的用户ID,有时它会使用相同的用户ID。我真的希望每次都能创建相同的用户ID,这样匿名用户仍然可以在应用程序中维护相同的进度/数据。这实际上是我开始使用Firebase的原因。即使在重新启动应用程序等之后,我如何始终维护一个匿名帐户来保持相同的用户ID? 我希望用户每次以访客身份玩游戏时都能获得相同的ID。我看到有些应用程序在卸载

  • 本文向大家介绍firebase-authentication Google Plus登录身份验证,包括了firebase-authentication Google Plus登录身份验证的使用技巧和注意事项,需要的朋友参考一下 示例 使用Plus登录验证用户 onCreate onStart() 获取资料信息 使用Firebase进行身份验证, onActivityResult 登出      

  • 问题内容: 我正在开发Flask应用程序,并使用Flask-security进行用户身份验证(反过来又在下面使用Flask-login)。 我有一条需要身份验证的路由。我正在尝试编写一个单元测试,该测试对经过身份验证的用户返回适当的响应。 在单元测试中,我正在创建一个用户并以该用户身份登录,如下所示: 在测试内返回正确的用户。但是,请求的视图始终返回的。 所述路线定义为: 我可以肯定我只是不完全了

  • 我用Spring Security做了一个概念验证,以便使用PRE_AUTH_FILTER过滤器执行预认证。它工作正常,但我想知道如果这个过滤器不起作用,我是否可以重定向到登录页面,因为我得到HTTP 403。< br >我的意思是,如果初始请求的头中不包含SM_USER字段,我如何重定向到登录页面?我需要考虑这两种情况(当它包含字段- SM_USER -和不包含时),但我无法让它工作。有什么想法