Skip to content

Commit d1a6c71

Browse files
committed
Improved Authentication layer
1 parent 61e4fb2 commit d1a6c71

File tree

6 files changed

+105
-209
lines changed

6 files changed

+105
-209
lines changed

app/Core/Middleware/ApiAuth.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Leantime\Core\Http\ApiRequest;
99
use Leantime\Core\Http\IncomingRequest;
1010
use Leantime\Domain\Api\Services\Api as ApiService;
11-
use Leantime\Domain\Auth\Models\Roles;
1211
use Leantime\Domain\Auth\Services\Auth as AuthService;
1312
use Leantime\Domain\Projects\Services\Projects as ProjectsService;
1413
use Symfony\Component\HttpFoundation\Response;
@@ -20,16 +19,15 @@ class ApiAuth
2019
/**
2120
* Handle an incoming request
2221
*
23-
* @param IncomingRequest $request
24-
* @param \Closure(IncomingRequest): Response $next
22+
* @param \Closure(IncomingRequest): Response $next
2523
**/
2624
public function handle(IncomingRequest $request, Closure $next): Response
2725
{
2826
if (! $request instanceof ApiRequest) {
2927
return $next($request);
3028
}
3129

32-
self::dispatch_event("before_api_request", ['application' => app()]);
30+
self::dispatchEvent('before_api_request', ['application' => app()]);
3331

3432
$apiKey = $request->getAPIKey();
3533
$apiUser = app()->make(ApiService::class)->getAPIKeyUser($apiKey);

app/Domain/Api/Services/Api.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function getAPIKeyUser(string $apiKey): bool|array
4747
$apiKeyParts = explode("_", $apiKey);
4848

4949
if (!is_array($apiKeyParts) || count($apiKeyParts) != 3) {
50-
report("Not a valid API Key format");
5150
return false;
5251
}
5352

@@ -56,8 +55,6 @@ public function getAPIKeyUser(string $apiKey): bool|array
5655
$key = $apiKeyParts[2];
5756

5857
if ($namespace != "lt") {
59-
report("Unknown namespace for API request");
60-
6158
return false;
6259
}
6360

@@ -200,7 +197,7 @@ public function jsonResponse(int $id, ?array $result): void
200197
*/
201198
public function getCaseCorrectPathFromManifest(string $filepath): string|false
202199
{
203-
$manifest = mix()->getManifest();
200+
$manifest = mix('')->getManifest();
204201
$clone = array_change_key_case(collect(Arr::dot($manifest))
205202
->mapWithKeys(fn ($value, $key) => [Str::of($key)->replaceFirst('./', '/')->lower()->toString() => $value])
206203
->all());

app/Domain/Auth/Controllers/Login.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ public function post(array $params): Response
104104

105105
//If login successful redirect to the correct url to avoid post on reload
106106
if ($this->authService->login($username, $password) === true) {
107+
108+
self::dispatch_event("successfulLogin", ['post' => $_POST]);
109+
107110
if ($this->authService->use2FA()) {
108111
return FrontcontrollerCore::redirect(BASE_URL . "/auth/twoFA");
109112
}
110113

111-
self::dispatch_event("afterAuthServiceCall", ['post' => $_POST]);
112-
113114
return FrontcontrollerCore::redirect($redirectUrl);
114115
} else {
115116
$this->tpl->setNotification("notifications.username_or_password_incorrect", "error");

app/Domain/Auth/Controllers/ResetPw.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function init(
5454
*/
5555
public function get(array $params): Response
5656
{
57-
if ((isset($_GET["id"]) === true && $this->authService->validateResetLink($_GET["id"]))) {
57+
if ((isset($params["id"]) === true && $this->authService->validateResetLink($params["id"]))) {
5858
return $this->tpl->display('auth.resetPw', 'entry');
5959
} else {
6060
return $this->tpl->display('auth.requestPwLink', 'entry');
@@ -90,11 +90,11 @@ public function post(array $params): Response
9090
if (strlen($_POST['password']) == 0 || $_POST['password'] != $_POST['password2']) {
9191
$this->tpl->setNotification($this->language->__('notification.passwords_dont_match'), "error");
9292

93-
return FrontcontrollerCore::redirect(BASE_URL . "/auth/resetPw/" . $_GET['id']);
93+
return FrontcontrollerCore::redirect(BASE_URL . "/auth/resetPw/" . $params['id']);
9494
}
9595

9696
if ($this->userService->checkPasswordStrength($_POST['password'])) {
97-
if ($this->authService->changePW($_POST['password'], $_GET['id'])) {
97+
if ($this->authService->changePW($_POST['password'], $params['id'])) {
9898
$this->tpl->setNotification(
9999
$this->language->__('notifications.passwords_changed_successfully'),
100100
"success",
@@ -109,22 +109,22 @@ public function post(array $params): Response
109109
"error"
110110
);
111111

112-
return FrontcontrollerCore::redirect(BASE_URL . "/auth/resetPw/" . $_GET['id']);
112+
return FrontcontrollerCore::redirect(BASE_URL . "/auth/resetPw/" . $params['id']);
113113
}
114114

115115
$this->tpl->setNotification(
116116
$this->language->__("notification.password_not_strong_enough"),
117117
'error'
118118
);
119119

120-
return FrontcontrollerCore::redirect(BASE_URL . "/auth/resetPw/" . $_GET['id']);
120+
return FrontcontrollerCore::redirect(BASE_URL . "/auth/resetPw/" . $params['id']);
121121
}
122122

123123
$this->tpl->setNotification(
124124
$this->language->__('notifications.problem_resetting_password'),
125125
"error"
126126
);
127127

128-
return FrontcontrollerCore::redirect(BASE_URL . '/auth/resetPw/' . $_GET["id"] ?? '');
128+
return FrontcontrollerCore::redirect(BASE_URL . '/auth/resetPw/' . $params["id"] ?? '');
129129
}
130130
}

0 commit comments

Comments
 (0)