更改默认用户名和密码后,Laravel登录无法正常工作

时间:2019-01-16 05:13:55

标签: laravel

我有一个名为'iw_users'的用户的自定义表,内部还有一个名为'iu_email'和'iu_password'的电子邮件和密码的自定义列。我在这里要做的是将iu_email设置为电子邮件,将iu_password设置为loginregisterforgot password上的密码(基本上是所有功能) laravel Auth提供的内容。

我已遵循此线程的答案:Laravel: How can i change the default Auth Password field name

但是,当我尝试使用正确的凭据登录时,页面只是刷新并再次将我重定向到登录页面(我可以确定laravel没有使用Auth::check()授权我)。

此外,每当我尝试使用错误的凭据登录时,错误和输入的颜色都不是红色。

这是我的App\User代码:

class User extends Authenticatable
{
    use Notifiable;


    protected $table = 'iw_users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'iu_user_id', 'iu_last_name', 'iu_first_name', 'iu_email', 'iu_mobile_no', 'iu_password', 'iu_gender', 'iu_country', 'iu_role', 'iu_photo', 'iu_status', 'iu_ipaddress'
    ];


    public function getAuthPassword()
    {
        return $this->iu_password;
    }

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    // Commented. i don't have 'password' and 'remember_token' in iw_users
    // protected $hidden = [
    //     'password', 'remember_token',
    // ];
}

这是我的LoginController.php

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function username()
    {
        return 'iu_email';
    }
}

这是我的login.blade.php表单

<form class="form-horizontal" method="POST" action="{{ route('login') }}">
    {{ csrf_field() }}

    <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
        <label for="email" class="col-md-4 control-label">E-Mail Address</label>

        <div class="col-md-6">
            <input id="email" type="email" class="form-control" name="iu_email" value="{{ old('iu_email') }}" required autofocus>

            @if ($errors->has('iu_email'))
                <span class="help-block">
                    <strong>{{ $errors->first('iu_email') }}</strong>
                </span>
            @endif
        </div>
    </div>

    <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
        <label for="password" class="col-md-4 control-label">Password</label>

        <div class="col-md-6">
            <input id="password" type="password" class="form-control" name="password" required>

            @if ($errors->has('password'))
                <span class="help-block">
                    <strong>{{ $errors->first('password') }}</strong>
                </span>
            @endif
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
                </label>
            </div>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-8 col-md-offset-4">
            <button type="submit" class="btn btn-primary">
                Login
            </button>

            <a class="btn btn-link" href="{{ route('password.request') }}">
                Forgot Your Password?
            </a>
        </div>
    </div>
</form>

1 个答案:

答案 0 :(得分:0)

我建议您检查https://scotch.io/@sukelali/how-to-create-multi-table-authentication-in-laravel

调试此程序时是否遇到任何错误?我怀疑,它无法覆盖其默认字段。