【问题标题】:Laravel 8 Jetstream / livewire. Have Password reset form accept username instead of emailLaravel 8 Jetstream / livewire。让密码重置表单接受用户名而不是电子邮件
【发布时间】:2021-06-24 21:02:23
【问题描述】:

删除电子邮件字段并添加用户名字段很容易。 (在使用登录视图之后)它使用用户名字段进行身份验证就好了,我做了同样的事情。

\resources\views\auth\reset-password.blade.php ```

    <form method="POST" action="{{ route('password.update') }}">
        @csrf

        <input type="hidden" name="token" value="{{ $request->route('token') }}">

        <div class="block">
            <x-jet-label for="username" value="{{ __('User name') }}" />
            <x-jet-input id="username" class="block mt-1 w-full" type="text" name="username" :value="old('username')" required autofocus autocomplete="username" />
        </div> 

        {{-- <div class="block">
            <x-jet-label for="email" value="{{ __('Email') }}" />
            <x-jet-input id="email" class="block mt-1 w-full" type="email" name="email" :value="old('email', $request->email)" required autofocus />
        </div> --}}

        <div class="mt-4">
            <x-jet-label for="password" value="{{ __('Password') }}" />
            <x-jet-input id="password" class="block mt-1 w-full" type="password" name="password" required autocomplete="new-password" />
        </div>

        <div class="mt-4">
            <x-jet-label for="password_confirmation" value="{{ __('Confirm Password') }}" />
            <x-jet-input id="password_confirmation" class="block mt-1 w-full" type="password" name="password_confirmation" required autocomplete="new-password" />
        </div>

        <div class="flex items-center justify-end mt-4">
            <x-jet-button>
                {{ __('Reset Password') }}
            </x-jet-button>
        </div>
    </form>

但是当我尝试使用它时,我得到:

Whoops! Something went wrong.
The email field is required.

我无法弄清楚输入的验证位置,以便我进行所需的更改以期望用户名代替电子邮件地址。

【问题讨论】:

    标签: authentication laravel-8 laravel-livewire change-password jetstream


    【解决方案1】:

    Jetsteam 使用 fortify 作为后端。换config\fortify.php

        /*
        |--------------------------------------------------------------------------
        | Username / Email
        |--------------------------------------------------------------------------
        |
        | This value defines which model attribute should be considered as your
        | application's "username" field. Typically, this might be the email
        | address of the users but you are free to change this value here.
        |
        | Out of the box, Fortify expects forgot password and reset password
        | requests to have a field named 'email'. If the application uses
        | another name for the field you may define it below as needed.
        |
        */
    
        'username' => 'username', // change this to username
    
        'email' => 'email',
    

    【讨论】:

    • 我这样做了,这就是允许我使用用户名进行身份验证的原因,但是当使用更改密码电子邮件中的链接时,它会要求提供电子邮件地址和新密码,并且是确认。跨度>
    • 更改resources/views/auth/reset-password.blade.php 代码以使用用户名
    • 我也这样做了,这是我首先粘贴的文件。如果您仔细观察,电子邮件地址已被注释掉,并且我添加了一个用户名字段。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2021-06-22
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    相关资源
    最近更新 更多