Skip to content

Commit a810012

Browse files
chore: lint file app/libs/Auth/AuthService.php
1 parent ca405e6 commit a810012

1 file changed

Lines changed: 36 additions & 33 deletions

File tree

app/libs/Auth/AuthService.php

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace Auth;
1+
<?php
2+
namespace Auth;
23
/**
34
* Copyright 2016 OpenStack Foundation
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -99,17 +100,16 @@ final class AuthService extends AbstractService implements IAuthService
99100
*/
100101
public function __construct
101102
(
102-
IUserRepository $user_repository,
103-
IOAuth2OTPRepository $otp_repository,
104-
IPrincipalService $principal_service,
105-
IUserService $user_service,
106-
IUserActionService $user_action_service,
107-
ICacheService $cache_service,
108-
IAuthUserService $auth_user_service,
103+
IUserRepository $user_repository,
104+
IOAuth2OTPRepository $otp_repository,
105+
IPrincipalService $principal_service,
106+
IUserService $user_service,
107+
IUserActionService $user_action_service,
108+
ICacheService $cache_service,
109+
IAuthUserService $auth_user_service,
109110
ISecurityContextService $security_context_service,
110-
ITransactionService $tx_service
111-
)
112-
{
111+
ITransactionService $tx_service
112+
) {
113113
parent::__construct($tx_service);
114114
$this->user_repository = $user_repository;
115115
$this->principal_service = $principal_service;
@@ -161,7 +161,7 @@ public function login(string $username, string $password, bool $remember_me): bo
161161
Log::debug("AuthService::login: clearing principal");
162162
$this->principal_service->clear();
163163
$current_user = $this->getCurrentUser();
164-
if(is_null($current_user) || !$current_user->canLogin())
164+
if (is_null($current_user) || !$current_user->canLogin())
165165
throw new AuthenticationException
166166
(
167167
"username or password does not match an existing record."
@@ -278,11 +278,13 @@ public function loginWithOTP(OAuth2OTP $otpClaim, ?Client $client = null, bool $
278278
throw new AuthenticationException("Single-use code mismatch.");
279279
}
280280

281-
if(!empty($otpClaim->getScope()) && !$otp->allowScope($otpClaim->getScope()))
281+
if (!empty($otpClaim->getScope()) && !$otp->allowScope($otpClaim->getScope()))
282282
throw new InvalidOTPException("Single-use code requested scopes escalates former scopes.");
283283

284-
if (($otp->hasClient() && is_null($client)) ||
285-
($otp->hasClient() && !is_null($client) && $client->getClientId() != $otp->getClient()->getClientId())) {
284+
if (
285+
($otp->hasClient() && is_null($client)) ||
286+
($otp->hasClient() && !is_null($client) && $client->getClientId() != $otp->getClient()->getClientId())
287+
) {
286288
throw new AuthenticationException("Single-use code audience mismatch.");
287289
}
288290

@@ -304,15 +306,14 @@ public function loginWithOTP(OAuth2OTP $otpClaim, ?Client $client = null, bool $
304306
],
305307
$otp
306308
);
307-
}
308-
else{
309-
if($user->isActive()) {
309+
} else {
310+
if ($user->isActive()) {
310311
// verify email
311312
$user->verifyEmail(false);
312313
}
313314
}
314315

315-
if(!$user->canLogin()){
316+
if (!$user->canLogin()) {
316317
Log::warning(sprintf("AuthService::loginWithOTP user %s cannot login ( is not active ).", $user->getId()));
317318
throw new AuthenticationException("username or password does not match an existing record.");
318319
}
@@ -328,7 +329,7 @@ public function loginWithOTP(OAuth2OTP $otpClaim, ?Client $client = null, bool $
328329
$client
329330
);
330331

331-
foreach ($grants2Revoke as $otp2Revoke){
332+
foreach ($grants2Revoke as $otp2Revoke) {
332333
try {
333334
Log::debug(sprintf("AuthService::loginWithOTP revoking otp %s ", $otp2Revoke->getValue()));
334335
if ($otp2Revoke->getValue() !== $otpClaim->getValue())
@@ -349,12 +350,12 @@ public function loginWithOTP(OAuth2OTP $otpClaim, ?Client $client = null, bool $
349350
* @param bool $clear_security_ctx
350351
* @return void
351352
*/
352-
public function logout(bool $clear_security_ctx = true):void
353+
public function logout(bool $clear_security_ctx = true): void
353354
{
354355
Log::debug("AuthService::logout");
355356
$current_user = $this->getCurrentUser();
356357
// check if we have user on session
357-
if(!is_null($current_user)) {
358+
if (!is_null($current_user)) {
358359
$ip = IPHelper::getUserIp();
359360
Log::debug(sprintf("AuthService::logout we have user %s from ip %s", $current_user->getId(), $ip));
360361
$this->user_action_service->addUserAction
@@ -368,7 +369,7 @@ public function logout(bool $clear_security_ctx = true):void
368369
// regular flow
369370
$this->invalidateSession();
370371
$this->principal_service->clear();
371-
if($clear_security_ctx)
372+
if ($clear_security_ctx)
372373
$this->security_context_service->clear();
373374
Auth::logout();
374375
// put in past
@@ -488,8 +489,7 @@ public function unwrapUserId(string $user_id): string
488489
$unwrapped_name = $this->decrypt($user_id);
489490
$parts = explode(':', $unwrapped_name);
490491
return intval($parts[1]);
491-
}
492-
catch (Exception $ex){
492+
} catch (Exception $ex) {
493493
Log::warning($ex);
494494
}
495495
return $user_id;
@@ -552,7 +552,8 @@ public function registerRPLogin(string $client_id): void
552552
$rps = $zlib->uncompress($rps);
553553
$rps .= '|';
554554
}
555-
if (is_null($rps)) $rps = "";
555+
if (is_null($rps))
556+
$rps = "";
556557

557558
if (!str_contains($rps, $client_id))
558559
$rps .= $client_id;
@@ -591,8 +592,7 @@ public function getLoggedRPs(): array
591592
$rps = $zlib->uncompress($rps);
592593
return explode('|', $rps);
593594
}
594-
}
595-
catch (Exception $ex){
595+
} catch (Exception $ex) {
596596
Log::warning($ex);
597597
}
598598
return [];
@@ -659,14 +659,17 @@ public function invalidateSession(): void
659659
public function postLoginUserActions(int $user_id): void
660660
{
661661
Log::debug(sprintf("AuthService::postLoginUserActions user %s", $user_id));
662-
$this->tx_service->transaction(function () use($user_id){
662+
$this->tx_service->transaction(function () use ($user_id) {
663663
$user = $this->user_repository->getById($user_id);
664-
if(!$user instanceof User) return;
664+
if (!$user instanceof User)
665+
return;
665666

666667
if (!$user->isActive()) {
667-
Log::warning(sprintf("AuthService::postLoginUserActions user %s is not active.", $user_id));
668-
throw new AuthenticationLockedUserLoginAttempt($user->getEmail(),
669-
sprintf("User %s is locked.", $user->getEmail()));
668+
Log::warning(sprintf("AuthService::postLoginUserActions user %s is not active.", $user_id));
669+
throw new AuthenticationLockedUserLoginAttempt(
670+
$user->getEmail(),
671+
sprintf("User %s is locked.", $user->getEmail())
672+
);
670673
}
671674

672675
//update user fields

0 commit comments

Comments
 (0)