Refactoring

This commit is contained in:
Bubka
2020-01-25 18:22:45 +01:00
parent ffaef86909
commit 2233f1119b
2 changed files with 25 additions and 33 deletions

View File

@ -37,7 +37,7 @@ class TwoFAccountController extends Controller
'uri' => 'required|regex:/^otpauth:\/\/[h,t]otp\//i',
]);
$this->validateOTP($request->uri);
OTP::get($request->uri);
$twofaccount = TwoFAccount::create([
'service' => $request->service,
@ -76,7 +76,7 @@ class TwoFAccountController extends Controller
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 @@ class TwoFAccountController extends Controller
}
}
/**
* 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;
}
}
}