芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/myvyralapp.com/bck/app/Http/Controllers/User/AuthorizationController.php
first(); $page_title = "Email Verification"; return view('user.auth.authorize.verify-email',compact("page_title","token","data")); } public function showSmsFrom() { if (auth()->check()) { $user = auth()->user(); if (!$user->status) { Auth::logout(); return redirect()->route('user.login')->with(['error' => ['Your account disabled,please contact with admin!!']]); }elseif (!$user->sms_verified) { $page_title = 'SMS Authorization'; $firbase_token = $user->firebase_token??""; $phone = "+".$user->full_mobile??''; return view('user.auth.authorize.verify-sms-auth',compact("page_title","firbase_token",'phone')); }else{ return redirect()->route('user.dashboard'); } } return redirect()->route('user.login'); } /** * Verify authorizaation code. * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function mailVerify(Request $request,$token) { $request->merge(['token' => $token]); $request->validate([ 'token' => "required|string|exists:user_authorizations,token", // 'code' => "required|numeric|exists:user_authorizations,code", 'code' => "required|array", 'code.*' => "required|numeric", ]); $code = $request->code; $code = implode("",$code); $otp_exp_sec = BasicSettingsProvider::get()->otp_exp_seconds ?? GlobalConst::DEFAULT_TOKEN_EXP_SEC; $auth_column = UserAuthorization::where("token",$request->token)->where("code",$code)->first(); if(!$auth_column){ return back()->with(['error' => ['Verification code does not match']]); } if($auth_column->created_at->addSeconds($otp_exp_sec) < now()) { $this->authLogout($request); return redirect()->route('index')->with(['error' => ['Session expired. Please try again']]); } try{ $auth_column->user->update([ 'email_verified' => true, ]); $auth_column->delete(); }catch(Exception $e) { $this->authLogout($request); return redirect()->route('user.login')->with(['error' => ['Something went worng! Please try again']]); } return redirect()->intended(route("user.dashboard"))->with(['success' => ['Account successfully verified']]); } public function resendCode() { $user = auth()->user(); $resend = UserAuthorization::where("user_id",$user->id)->first(); if( $resend){ if(Carbon::now() <= $resend->created_at->addMinutes(GlobalConst::USER_VERIFY_RESEND_TIME_MINUTE)) { throw ValidationException::withMessages([ 'code' => 'You can resend verification code after '.Carbon::now()->diffInSeconds($resend->created_at->addMinutes(GlobalConst::USER_VERIFY_RESEND_TIME_MINUTE)). ' seconds', ]); } } $data = [ 'user_id' => $user->id, 'code' => generate_random_code(), 'token' => generate_unique_string("user_authorizations","token",200), 'created_at' => now(), ]; DB::beginTransaction(); try{ UserAuthorization::where("user_id",$user->id)->delete(); DB::table("user_authorizations")->insert($data); $user->notify(new SendAuthorizationCode((object) $data)); DB::commit(); }catch(Exception $e) { DB::rollBack(); return back()->with(['error' => ['Something went worng! Please try again']]); } return redirect()->route('user.authorize.mail',$data['token'])->with(['success' => ['Varification code resend success!']]); } public function authLogout(Request $request) { auth()->guard("web")->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); } public function showKycFrom() { $user = auth()->user(); if($user->kyc_verified == GlobalConst::VERIFIED) return back()->with(['success' => ['You are already KYC Verified User']]); $page_title = "KYC Verification"; $user_kyc = SetupKyc::userKyc()->first(); if(!$user_kyc) return back(); $kyc_data = $user_kyc->fields; $kyc_fields = []; if($kyc_data) { $kyc_fields = array_reverse($kyc_data); } return view('user.auth.authorize.verify-kyc',compact("page_title","kyc_fields")); } public function kycSubmit(Request $request) { $user = auth()->user(); if($user->kyc_verified == GlobalConst::VERIFIED) return back()->with(['success' => ['You are already KYC Verified User']]); $user_kyc_fields = SetupKyc::userKyc()->first()->fields ?? []; $validation_rules = $this->generateValidationRules($user_kyc_fields); $validated = Validator::make($request->all(),$validation_rules)->validate(); $get_values = $this->placeValueWithFields($user_kyc_fields,$validated); $create = [ 'user_id' => auth()->user()->id, 'data' => json_encode($get_values), 'created_at' => now(), ]; DB::beginTransaction(); try{ DB::table('user_kyc_data')->updateOrInsert(["user_id" => $user->id],$create); $user->update([ 'kyc_verified' => GlobalConst::PENDING, ]); DB::commit(); }catch(Exception $e) { DB::rollBack(); $user->update([ 'kyc_verified' => GlobalConst::DEFAULT, ]); $this->generatedFieldsFilesDelete($get_values); return back()->with(['error' => ['Something went worng! Please try again']]); } return redirect()->route("user.profile.index")->with(['success' => ['KYC information successfully submited']]); } public function showGoogle2FAForm() { $page_title = "Authorize Google Two Factor"; return view('user.auth.authorize.verify-google-2fa',compact('page_title')); } public function google2FASubmit(Request $request) { $request->validate([ 'code' => "required|array", 'code.*' => "required|numeric", ]); $code = $request->code; $code = implode("",$code); $user = auth()->user(); if(!$user->two_factor_secret) { return back()->with(['warning' => ['Your secret key not stored properly. Please contact with system administrator']]); } if(google_2fa_verify($user->two_factor_secret,$code)) { $user->update([ 'two_factor_verified' => true, ]); return redirect()->intended(route('user.dashboard')); } return back()->with(['warning' => ['Faild to login. Please try again']]); } }