1313 **/
1414
1515use App \Http \Utils \IUserIPHelperProvider ;
16+ use App \Jobs \AddUserAction ;
1617use App \libs \Auth \Models \IGroupSlugs ;
1718use App \libs \OAuth2 \Repositories \IOAuth2OTPRepository ;
1819use App \Models \OAuth2 \Factories \OTPFactory ;
7374use Utils \Db \ITransactionService ;
7475use Utils \Exceptions \ConfigurationException ;
7576use Utils \Exceptions \UnacquiredLockException ;
77+ use Utils \IPHelper ;
7678use utils \json_types \JsonValue ;
7779use utils \json_types \NumericDate ;
7880use utils \json_types \StringOrURI ;
@@ -1587,6 +1589,21 @@ public function createOTPFromRequest(OAuth2PasswordlessAuthenticationRequest $re
15871589 $ this ->otp_repository ->add ($ otp );
15881590 }
15891591
1592+ $ user = $ this ->auth_service ->getUserByUsername ($ otp ->getUserName ());
1593+ if (!is_null ($ user )){
1594+ Log::debug
1595+ (
1596+ sprintf
1597+ (
1598+ "TokenService::createOTPFromRequest requested OTP for existent user %s (%s) " ,
1599+ $ user ->getEmail (),
1600+ $ user ->getId ()
1601+ )
1602+ );
1603+ AddUserAction::dispatch ($ user ->getId (), IPHelper::getUserIp (), "Requested OTP " );
1604+ if (!$ user ->isActive ())
1605+ throw new ValidationException ("User is not active. " );
1606+ }
15901607 return $ otp ;
15911608 });
15921609
@@ -1610,10 +1627,26 @@ public function createOTPFromRequest(OAuth2PasswordlessAuthenticationRequest $re
16101627 * @throws Exception
16111628 */
16121629 public function createOTPFromPayload (array $ payload , ?Client $ client ):OAuth2OTP {
1630+
16131631 $ otp = $ this ->tx_service ->transaction (function () use ($ payload , $ client ){
16141632
16151633 $ otp = OTPFactory::buildFromPayload ($ payload , $ this ->identifier_generator , $ client );
16161634
1635+ $ user = $ this ->auth_service ->getUserByUsername ($ otp ->getUserName ());
1636+ if (!is_null ($ user )){
1637+ Log::debug
1638+ (
1639+ sprintf
1640+ (
1641+ "TokenService::createOTPFromPayload requested OTP for existent user %s (%s) " ,
1642+ $ user ->getEmail (),
1643+ $ user ->getId ()
1644+ )
1645+ );
1646+ AddUserAction::dispatch ($ user ->getId (), IPHelper::getUserIp (), "Requested OTP " );
1647+ if (!$ user ->isActive ())
1648+ throw new ValidationException ("User is not active. " );
1649+ }
16171650 if (is_null ($ client )){
16181651 $ this ->otp_repository ->add ($ otp );
16191652 }
0 commit comments