如何使管理员忘记laravel中的密码功能?

时间:2019-07-11 06:43:41

标签: laravel laravel-5 eloquent

我想创建管理面板的忘记密码功能,但是现在我在AdminController中使用了自定义管理员登录功能。如何为管理面板创建带有令牌的忘记密码功能?

此处为我的AdminController代码...

登录方法

public function login(Request $request)
{
      if($request->isMethod('post')) {
        $data = $request->input();
        $adminCount = Admin::where([
           'username' => $data['username']
           'password'=> md5($data['password']),
           'status'=> 1
        ])->count();

        if($adminCount > 0){
            //echo "Success"; die;
            Session::put('adminSession', $data['username']);
            return redirect('/admin/dashboard');
        }else{
            //echo "failed"; die;
            return redirect('/admin')->with('flash_message_error','Invalid Username or Password');
        }
    }
    return view('admin.admin_login');
}

重置方法

public function reset(ResetPasswordRequest $request)
{
    $credentials = $request->only(
        'email', 'password', 'password_confirmation', 'token'
    );

    $response = Password::reset($credentials, function ($user, $password) {
        $this->resetPassword($user, $password);
    });

    switch ($response) {
        case Password::PASSWORD_RESET:
            return redirect($this->redirectPath())->with('status', trans($response));

        default:
            return redirect()->back()
                ->withInput($request->only('email'))
                ->withErrors(['email' => trans($response)]);
    }
}

1 个答案:

答案 0 :(得分:-1)

您应该尝试以下操作:

public function reset(ResetPasswordRequest $request)
    {
        $credentials = $request->only(
            'email', 'password', 'password_confirmation', 'token'
        );

        $response = Password::reset($credentials, function ($user, $password) {
            $this->resetPassword($user, $password);
        });

        switch ($response) {
            case Password::PASSWORD_RESET:
                return redirect($this->redirectPath())->with('status', trans($response));

            default:
                return redirect()->back()
                    ->withInput($request->only('email'))
                    ->withErrors(['email' => trans($response)]);
        }
    }