第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

laravel 重置密碼不重置密碼

laravel 重置密碼不重置密碼

PHP
慕容3067478 2022-06-17 16:57:58
我正在使用 laravel 6。我第一次嘗試為我的 laravel 項(xiàng)目實(shí)現(xiàn)忘記密碼。我已經(jīng)自定義了登錄、忘記密碼、重置密碼頁(yè)面的默認(rèn)設(shè)計(jì)。我已經(jīng)集成mailtrap用于發(fā)送電子郵件。我已經(jīng)成功實(shí)現(xiàn)了流程,例如-點(diǎn)擊忘記密碼鏈接獲取用戶輸入電子郵件并單擊以發(fā)送重置鏈接的頁(yè)面獲取重置鏈接和數(shù)據(jù)的電子郵件,例如email, token , created_at存儲(chǔ)在password_reset表中單擊帶有令牌和電子郵件 url 的重置鏈接頁(yè)面在新選項(xiàng)卡中打開(打開帶有電子郵件、新密碼、確認(rèn)密碼的重置密碼頁(yè)面)此外,當(dāng)我輸入新密碼并確認(rèn)密碼并單擊時(shí)Reset Password,沒有任何反應(yīng)。我的reset.blade.php<form id="sign_in" name="sign_in" method="POST" action="{{ route('password.update') }}" data-parsley-validate >              <input type="hidden" name="_token" value="{{ csrf_token() }}">            <h1>Reset Password</h1>            <div class="col-md-12 col-sm-12 form-group has-feedback">              {{-- <label for="login_id"><span style="color:red;">*</span>Login ID</label> --}}              <input id="email" type="email" class="form-control has-feedback-left @error('email') is-invalid @enderror" placeholder="Email" name="email" value="{{ $email ?? old('email') }}" required autocomplete="email" autofocus/>              <span class="fa fa-envelope form-control-feedback left" aria-hidden="true"></span>               @error('email')                                    <span class="invalid-feedback" role="alert">                                        <strong>{{ $message }}</strong>                                    </span>                                @enderror            </div>              <div class="col-md-12 col-sm-12 form-group has-feedback">                  <input id="password" type="password" class="form-control has-feedback-left @error('password') is-invalid @enderror" placeholder="Password" name="password" required autocomplete="new-password" />                  <span class="fa fa-pencil form-control-feedback left" aria-hidden="true"></span>                </div>                <div class="col-md-12 col-sm-12 form-group has-feedback">我為auth“ConfirmPasswordController、ForgotPasswordController、ResetPasswordController、VerificationController”生成了默認(rèn)控制器
查看完整描述

2 回答

?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

Laravel 中的密碼重置

第 1 步 — 創(chuàng)建路由和控制器

創(chuàng)建兩個(gè)路由、一個(gè)控制器和方法,通過(guò)這些路由,需要密碼重置的電子郵件地址將通過(guò)密碼重置表單提交。這些路由、控制器和方法的名稱完全取決于您。


Route::post('reset_password_without_token', 'AccountsController@validatePasswordRequest');

Route::post('reset_password_with_token', 'AccountsController@resetPassword');

第 2 步 — 更改默認(rèn)密碼重置表單上的操作屬性

<form method="POST" action="{{ url('/reset_password_without_token') }}">

默認(rèn)密碼重置表單可以在這里找到: resources/views/auth/passwords/email.blade.php


第 3 步 — 創(chuàng)建令牌并通過(guò)電子郵件發(fā)送密碼重置鏈接

然后在下面的代碼中添加validatePasswordRequest方法AccountsController并使用或修改。


//You can add validation login here

$user = DB::table('users')->where('email', '=', $request->email)

    ->first();

//Check if the user exists

if (count($user) < 1) {

    return redirect()->back()->withErrors(['email' => trans('User does not exist')]);

}


//Create Password Reset Token

DB::table('password_resets')->insert([

    'email' => $request->email,

    'token' => str_random(60),

    'created_at' => Carbon::now()

]);

//Get the token just created above

$tokenData = DB::table('password_resets')

    ->where('email', $request->email)->first();


if ($this->sendResetEmail($request->email, $tokenData->token)) {

    return redirect()->back()->with('status', trans('A reset link has been sent to your email address.'));

} else {

    return redirect()->back()->withErrors(['error' => trans('A Network Error occurred. Please try again.')]);

}

該sendResetEmail方法是一種私有方法,它向用戶發(fā)送帶有重置鏈接的電子郵件。在這里,您可以使用您選擇使用的任何電子郵件應(yīng)用程序。也許,你有一個(gè)為你的組織定制的電子郵件服務(wù),你可以在這里使用它,而不是依賴 Laravel 默認(rèn)的選項(xiàng)。


private function sendResetEmail($email, $token)

{

//Retrieve the user from the database

$user = DB::table('users')->where('email', $email)->select('firstname', 'email')->first();

//Generate, the password reset link. The token generated is embedded in the link

$link = config('base_url') . 'password/reset/' . $token . '?email=' . urlencode($user->email);


    try {

    //Here send the link with CURL with an external email API 

        return true;

    } catch (\Exception $e) {

        return false;

    }

}

單擊時(shí)生成并發(fā)送給用戶的鏈接會(huì)將用戶定向到您的 domain.com/password/reset/token?email='user@email.com'。你可以在這里找到視圖:resources/views/auth/passwords/reset.blade.php


第 4 步 - 重置用戶密碼

將此方法添加到AccountsController. 瀏覽評(píng)論,他們解釋每個(gè)步驟。


public function resetPassword(Request $request)

{

    //Validate input

    $validator = Validator::make($request->all(), [

        'email' => 'required|email|exists:users,email',

        'password' => 'required|confirmed'

        'token' => 'required' ]);


    //check if payload is valid before moving on

    if ($validator->fails()) {

        return redirect()->back()->withErrors(['email' => 'Please complete the form']);

    }


    $password = $request->password;

// Validate the token

    $tokenData = DB::table('password_resets')

    ->where('token', $request->token)->first();

// Redirect the user back to the password reset request form if the token is invalid

    if (!$tokenData) return view('auth.passwords.email');


    $user = User::where('email', $tokenData->email)->first();

// Redirect the user back if the email is invalid

    if (!$user) return redirect()->back()->withErrors(['email' => 'Email not found']);

//Hash and update the new password

    $user->password = \Hash::make($password);

    $user->update(); //or $user->save();


    //login the user immediately they change password successfully

    Auth::login($user);


    //Delete the token

    DB::table('password_resets')->where('email', $user->email)

    ->delete();


    //Send Email Reset Success Email

    if ($this->sendSuccessEmail($tokenData->email)) {

        return view('index');

    } else {

        return redirect()->back()->withErrors(['email' => trans('A Network Error occurred. Please try again.')]);

    }

}

你有它。這應(yīng)該足以讓事情正常進(jìn)行。


查看完整回答
反對(duì) 回復(fù) 2022-06-17
?
至尊寶的傳說(shuō)

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊

我有同樣的問題,我能夠通過(guò)這種方式解決它,

首先我添加一條路線:

Route::get('password/reset/{token}', [App\Http\Controllers\Auth\ResetPasswordController::class, 'showResetForm'])->name('password.reset');

接下來(lái)我添加reset.blade.php

<input type="hidden" name="token" value="{{$token}}">

就是這樣,它對(duì)我有用。也許有人也需要它


查看完整回答
反對(duì) 回復(fù) 2022-06-17
  • 2 回答
  • 0 關(guān)注
  • 257 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)