OTP是否應該存盤在會話或資料庫中。誰能告訴我OTP的流程?據我所知,當用戶提交必要的欄位時,用戶的詳細資料和OTP會被存盤在資料庫中,在注冊后會打開另一個表單來輸入OTP,然后注冊最終成功。但我不明白實際的邏輯。為了存盤otp,我們需要將所有的資料存盤在資料庫中,所有的資料被存盤(用戶資訊),然后我們才能驗證otp。我正在使用會話,但我不確定代碼是否正確。
public function otpVerify(Request $request)
{
$data = $request-> validate([
'verification_code' => ['required', ' numeric'],
'phone_number' => ['required', 'string'],
]);
$otp = $request->session()->get('otp') 。
$enteredOtp = $request->session()->get('otp') 。
if ($otp ==$enteredOtp) {
$user = tap(User::where('phone_number', $data['phone_number'])。
// ->update(['isVerified' => true]);
return success([
$success,
$otp.
], __('用戶創建成功'))。
} else {
return problem([], 500, 'OTP Doesnt Match');
}
public function register(RegisterUserRequest $request)
{
$user = new User($request-> validated())。
$otp = rand(10000, 99999)。
$otp_expires_time = Carbon::now()->addSeconds(20)。
if (!env('APP_ENV') === 'local') {
$sms = AWS::createClient('sns')。
$sms->發布([
'Message' => 'Your OTP code is: ' $otp,
'PhoneNumber' => $user-> phone_number,
'MessageAttributes' => [
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String'。
'StringValue' => 'Transactional',
]
],
]);
} else {
Log::channel('otplog')->info('您的OTP代碼是:'。$otp)。)
}
$status = $user-> save();
$user-> roles()->attach($request->role_id);
$user->brand()->attach($request->brand_id) 。
$user->appliances()->attach($request->appliance_id) 。
$success['token'] = $user-> createToken('MyAuthApp')-> plainTextToken;
$success['name'] = $user-> name;
Session::put('OTP', $otp, 'expiry_time',$otp_expires_time) 。
if ($status) {
return success([
$success,
$otp_expires_time,
$otp.
], __('用戶創建成功'))。
} else {
return problem([], 500, 'USER_REGISTER_FAIL');
}
uj5u.com熱心網友回復:
存盤在資料庫中是一個不錯的選擇
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/307785.html
標籤:
