<?php
namespace App\Http\Controllers\User;
use Exception;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Constants\GlobalConst;
use App\Models\UserAuthorization;
use App\Http\Controllers\Controller;
use App\Traits\ControlDynamicInputFields;
use App\Providers\Admin\BasicSettingsProvider;
use Illuminate\Validation\ValidationException;
use App\Notifications\User\Auth\SendAuthorizationCode;
class AuthorizationController extends Controller
{
use ControlDynamicInputFields;
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function showMailFrom($token)
{
$page_title = "Mail Authorization";
$user_authorize = UserAuthorization::where("token",$token)->first();
$resend_time = 0;
if(Carbon::now() <= $user_authorize->created_at->addMinutes(GlobalConst::USER_PASS_RESEND_TIME_MINUTE)) {
$resend_time = Carbon::now()->diffInSeconds($user_authorize->created_at->addMinutes(GlobalConst::USER_PASS_RESEND_TIME_MINUTE));
}
$email = $user_authorize->user->email;
return view('user.auth.authorize.verify-mail',compact("page_title","token","resend_time","email"));
}
/**
* Verify authorization 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|integer",
]);
$code = implode("",$request->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' => ['invalid Token!']]);
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('index')->with(['error' => ['Something went wrong! Please try again']]);
}
return redirect()->intended(route("user.dashboard"))->with(['success' => ['Account successfully verified']]);
}
/**
* Method for resend mail using token
*/
public function mailResend($token) {
$user_authorize = UserAuthorization::where("token",$token)->first();
if(!$user_authorize) return back()->with(['error' => ['Request token is invalid']]);
if(Carbon::now() <= $user_authorize->created_at->addMinutes(GlobalConst::USER_PASS_RESEND_TIME_MINUTE)) {
throw ValidationException::withMessages([
'code' => 'You can resend verification code after '.Carbon::now()->diffInSeconds($user_authorize->created_at->addMinutes(GlobalConst::USER_PASS_RESEND_TIME_MINUTE)). ' seconds',
]);
}
$resend_code = generate_random_code();
try{
$user_authorize->update([
'code' => $resend_code,
'created_at' => now(),
]);
$data = $user_authorize->toArray();
try{
$user_authorize->user->notify(new SendAuthorizationCode((object) $data));
}catch(Exception $e){}
}catch(Exception $e) {
throw ValidationException::withMessages([
'code' => "Something went wrong! Please try again.",
]);
}
return redirect()->route('user.authorize.mail',$token)->with(['success' => ['Mail Resend Success!']]);
}
public function authLogout(Request $request) {
auth()->guard("web")->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
}
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|integer",
]);
$code = implode($request->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' => ['Failed to login. Please try again']]);
}
}
About Section
NFC Pay was founded with a vision to transform the way people handle transactions. Our journey is defined by a commitment to innovation, security, and convenience. We strive to deliver seamless, user-friendly payment solutions that make everyday transactions effortless and secure. Our mission is to empower you to pay with ease and confidence, anytime, anywhere.
FAQ Section
Here are answers to some common questions about NFC Pay. We aim to provide clear and concise information to help you understand how our platform works and how it can benefit you. If you have any further inquiries, please don’t hesitate to contact our support team.
Download the app and sign up using your email or phone number, then complete the verification process.
Yes, we use advanced encryption and security protocols to protect your payment details.
Absolutely, you can link multiple debit or credit cards to your wallet.
Go to the transfer section, select the recipient, enter the amount, and authorize the transfer.
Use the “Forgot PIN” feature in the app to reset it following the provided instructions.
Sign up for a merchant account through the app and follow the setup instructions to start accepting payments.
Yes, you can view and track your payment status in the account dashboard