1

我在使用 laravel 8.55 和使用 Statamic 3 时遇到问题。我刚刚在微风上进行了全新安装,当我尝试注册时,它会将名称、电子邮件和密码保存在用户表中,但不保存 remember_token 并且不让我登录系统. 当我尝试使用创建的用户登录时,它给了我无效的凭据错误。我试图在 auth.php 中更改路由及其名称,但没有成功。

路线/auth.php

Route::get('/user-register', [RegisteredUserController::class, 'create'])
                ->middleware('guest')
                ->name('user-register');

Route::post('/user-register', [RegisteredUserController::class, 'store'])
                ->middleware('guest');

Route::get('/user-login', [AuthenticatedSessionController::class, 'create'])
                ->middleware('guest')
                ->name('user-login');

Route::post('/user-login', [AuthenticatedSessionController::class, 'store'])
                ->middleware('guest');
class RegisteredUserController extends Controller
{
    /**
     * Display the registration view.
     *
     * @return \Illuminate\View\View
     */
    public function create()
    {
        return view('auth.register');
    }

    /**
     * Handle an incoming registration request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(Request $request)
    {
        $request->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'confirmed', Rules\Password::defaults()],
        ]);

        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password),
        ]);

        event(new Registered($user));

        Auth::login($user);

        return redirect(RouteServiceProvider::HOME);
    }
}

class AuthenticatedSessionController extends Controller
{
    /**
     * Display the login view.
     *
     * @return \Illuminate\View\View
     */
    public function create()
    {
        return view('auth.login');
    }

    /**
     * Handle an incoming authentication request.
     *
     * @param  \App\Http\Requests\Auth\LoginRequest  $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(LoginRequest $request)
    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect()->intended(RouteServiceProvider::HOME);
    }

    /**
     * Destroy an authenticated session.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function destroy(Request $request)
    {
        Auth::guard('web')->logout();

        $request->session()->invalidate();

        $request->session()->regenerateToken();

        return redirect('/');
    }
}
4

0 回答 0