Skip to content

Commit 0ce1033

Browse files
committed
fix: improve UX on OTP request
Change-Id: I5aa9e7be727dd52eba4f3debef1e9400698679df
1 parent a686682 commit 0ce1033

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

app/Services/OAuth2/TokenService.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**/
1414

1515
use App\Http\Utils\IUserIPHelperProvider;
16+
use App\Jobs\AddUserAction;
1617
use App\libs\Auth\Models\IGroupSlugs;
1718
use App\libs\OAuth2\Repositories\IOAuth2OTPRepository;
1819
use App\Models\OAuth2\Factories\OTPFactory;
@@ -73,6 +74,7 @@
7374
use Utils\Db\ITransactionService;
7475
use Utils\Exceptions\ConfigurationException;
7576
use Utils\Exceptions\UnacquiredLockException;
77+
use Utils\IPHelper;
7678
use utils\json_types\JsonValue;
7779
use utils\json_types\NumericDate;
7880
use utils\json_types\StringOrURI;
@@ -1610,10 +1612,26 @@ public function createOTPFromRequest(OAuth2PasswordlessAuthenticationRequest $re
16101612
* @throws Exception
16111613
*/
16121614
public function createOTPFromPayload(array $payload, ?Client $client):OAuth2OTP{
1615+
16131616
$otp = $this->tx_service->transaction(function() use($payload, $client){
16141617

16151618
$otp = OTPFactory::buildFromPayload($payload, $this->identifier_generator, $client);
16161619

1620+
$user = $this->auth_service->getUserByUsername($otp->getUserName());
1621+
if(!is_null($user)){
1622+
Log::debug
1623+
(
1624+
sprintf
1625+
(
1626+
"TokenService::createOTPFromPayload requested OTP for existent user %s (%s)",
1627+
$user->getEmail(),
1628+
$user->getId()
1629+
)
1630+
);
1631+
AddUserAction::dispatch($user->getId(), IPHelper::getUserIp(), "Requested OTP");
1632+
if(!$user->isActive())
1633+
throw new ValidationException("User is not active.");
1634+
}
16171635
if(is_null($client)){
16181636
$this->otp_repository->add($otp);
16191637
}

resources/js/login/login.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ class LoginPage extends React.Component {
444444
});
445445
}, (error) => {
446446
let {response, status, message} = error;
447+
if(status == 412){
448+
const {message, errors} = response.body;
449+
Swal(message, errors[0], 'error')
450+
return;
451+
}
452+
447453
Swal('Oops...', 'Something went wrong!', 'error')
448454
});
449455
return false;

0 commit comments

Comments
 (0)