mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-04-16 21:48:36 +02:00
Refactoring
This commit is contained in:
parent
ffaef86909
commit
2233f1119b
@ -15,15 +15,10 @@ class OTP
|
|||||||
* @param \App\TwoFAccount $twofaccount
|
* @param \App\TwoFAccount $twofaccount
|
||||||
* @return an array that represent the totp code
|
* @return an array that represent the totp code
|
||||||
*/
|
*/
|
||||||
public static function get($uri)
|
public static function generate($uri)
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
$otp = $this->get($uri);
|
||||||
$otp = Factory::loadFromProvisioningUri($uri);
|
|
||||||
}
|
|
||||||
catch (AssertionFailedException $exception) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( get_class($otp) === 'OTPHP\TOTP' ) {
|
if( get_class($otp) === 'OTPHP\TOTP' ) {
|
||||||
|
|
||||||
@ -58,7 +53,27 @@ public static function get($uri)
|
|||||||
return $hotp;
|
return $hotp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if the provided uri is a valid OTP uri
|
||||||
|
*
|
||||||
|
* @param \App\TwoFAccount $twofaccount
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public static function get(String $uri) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Factory::loadFromProvisioningUri($uri);
|
||||||
|
}
|
||||||
|
catch (AssertionFailedException $exception) {
|
||||||
|
$error = \Illuminate\Validation\ValidationException::withMessages([
|
||||||
|
'qrcode' => __('errors.response.no_valid_totp')
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw $error;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public function store(Request $request)
|
|||||||
'uri' => 'required|regex:/^otpauth:\/\/[h,t]otp\//i',
|
'uri' => 'required|regex:/^otpauth:\/\/[h,t]otp\//i',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->validateOTP($request->uri);
|
OTP::get($request->uri);
|
||||||
|
|
||||||
$twofaccount = TwoFAccount::create([
|
$twofaccount = TwoFAccount::create([
|
||||||
'service' => $request->service,
|
'service' => $request->service,
|
||||||
@ -76,7 +76,7 @@ public function show($id)
|
|||||||
public function generateOTP(TwoFAccount $twofaccount)
|
public function generateOTP(TwoFAccount $twofaccount)
|
||||||
{
|
{
|
||||||
|
|
||||||
return response()->json(OTP::get($twofaccount->uri), 200);
|
return response()->json(OTP::generate($twofaccount->uri), 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,27 +142,4 @@ public function destroy($id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check if the provided uri is a valid OTP uri
|
|
||||||
*
|
|
||||||
* @param \App\TwoFAccount $twofaccount
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
private function validateOTP(String $uri) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
$otp = \OTPHP\Factory::loadFromProvisioningUri($uri);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (\Assert\AssertionFailedException $exception) {
|
|
||||||
$error = \Illuminate\Validation\ValidationException::withMessages([
|
|
||||||
'qrcode' => __('errors.response.no_valid_totp')
|
|
||||||
]);
|
|
||||||
|
|
||||||
throw $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user