Skip to content

Commit 5e40c49

Browse files
committed
Give more data when authentication issues appear
1 parent a097ade commit 5e40c49

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/WebApp/Auth/AuthError.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ class AuthError {
1212
public $errorCode;
1313
public $errorMessage;
1414

15-
public function __construct($errorCode, $errorMessage) {
15+
public function __construct($errorCode, $errorMessage, $data = NULL) {
1616
$this->errorCode = $errorCode;
1717
$this->errorMessage = $errorMessage;
18+
$this->data = $data;
1819
}
1920

2021
public function getMessage() {
2122
return \TgI18n\I18N::_($this->errorMessage);
2223
}
24+
25+
public function getData() {
26+
return $data;
27+
}
2328
}
2429

src/WebApp/Auth/UserDatabaseAuthenticator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ public function authenticate($id, SecretData $secretData) {
4444
if (!($user->verifyPassword($secretData->password))) {
4545
$user->registerFailedLoginAttempt();
4646
$this->dao->save($user);
47-
return new AuthError(AuthError::PASSWORD_INVALID, 'user_password_invalid');
47+
return new AuthError(AuthError::PASSWORD_INVALID, 'user_password_invalid', $user->email);
4848
} else {
4949
$user->registerSuccessfulLogin();
5050
$this->dao->save($user);
5151
return $user;
5252
}
5353
} else if ($user->isPermanentlyBlocked()) {
54-
return new AuthError(AuthError::USER_BLOCKED, 'user_blocked');
54+
return new AuthError(AuthError::USER_BLOCKED, 'user_blocked', $user->email);
5555
}
56-
return new AuthError(AuthError::USER_TEMPORARILY_BLOCKED, 'user_temporarily_blocked');
56+
return new AuthError(AuthError::USER_TEMPORARILY_BLOCKED, 'user_temporarily_blocked', $user->email);
5757
}
58-
return new AuthError(AuthError::USER_NOT_FOUND, 'user_not_found');
58+
return new AuthError(AuthError::USER_NOT_FOUND, 'user_not_found', $id);
5959
}
6060

6161
/**

src/WebApp/Page.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ protected function processLoginAction() {
167167
// Login failed
168168
Log::register(new Error($result->getMessage()));
169169
Log::error('Authentication error: '.$result->errorCode);
170+
$data = $result->getData();
171+
if ($data != NULL) {
172+
if (is_object($data)) $data = json_encode($data);
173+
Log::error('Authentication Data: '.$data);
174+
}
170175
} else {
171176
// Return to uri if required
172177
$return = $this->request->getPostParam('return');

0 commit comments

Comments
 (0)