feat: implement console command
Integration Tests / Integration Tests (pull_request) Successful in 59s
Integration Tests / Integration Tests (pull_request) Successful in 59s
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace KTXM\AuthenticationProviderPassword\Controllers;
|
||||
|
||||
use KTXC\Http\Response\JsonResponse;
|
||||
use KTXC\Service\UserAccountsService;
|
||||
use KTXC\SessionIdentity;
|
||||
use KTXC\SessionTenant;
|
||||
use KTXF\Controller\ControllerAbstract;
|
||||
@@ -18,7 +19,8 @@ class PasswordController extends ControllerAbstract
|
||||
private readonly SessionTenant $sessionTenant,
|
||||
private readonly CredentialStore $credentialStore,
|
||||
private readonly Provider $provider,
|
||||
private readonly Crypto $crypto
|
||||
private readonly Crypto $crypto,
|
||||
private readonly UserAccountsService $userAccountsService
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -62,7 +64,13 @@ class PasswordController extends ControllerAbstract
|
||||
|
||||
// TODO: Add permission check for admin operations
|
||||
|
||||
$hasCredentials = $this->provider->hasCredentials($tenantId, $uid);
|
||||
$user = $this->userAccountsService->fetchByIdentifier($uid);
|
||||
if (!$user) {
|
||||
return new JsonResponse(['error' => 'User not found'], 404);
|
||||
}
|
||||
|
||||
// Credentials are keyed by identity (email/username), not uid
|
||||
$hasCredentials = $this->provider->hasCredentials($tenantId, $user['identity']);
|
||||
|
||||
return new JsonResponse([
|
||||
'enrolled' => $hasCredentials,
|
||||
@@ -88,7 +96,13 @@ class PasswordController extends ControllerAbstract
|
||||
return new JsonResponse(['error' => 'Password must be at least 8 characters'], 400);
|
||||
}
|
||||
|
||||
$success = $this->provider->setCredential($tenantId, $uid, $password);
|
||||
$user = $this->userAccountsService->fetchByIdentifier($uid);
|
||||
if (!$user) {
|
||||
return new JsonResponse(['error' => 'User not found'], 404);
|
||||
}
|
||||
|
||||
// Credentials are keyed by identity (email/username), not uid
|
||||
$success = $this->provider->setCredential($tenantId, $user['identity'], $password);
|
||||
|
||||
if (!$success) {
|
||||
return new JsonResponse(['error' => 'Failed to set password'], 500);
|
||||
@@ -111,7 +125,13 @@ class PasswordController extends ControllerAbstract
|
||||
|
||||
// TODO: Add permission check for admin operations
|
||||
|
||||
$this->credentialStore->delete($tenantId, $uid);
|
||||
$user = $this->userAccountsService->fetchByIdentifier($uid);
|
||||
if (!$user) {
|
||||
return new JsonResponse(['error' => 'User not found'], 404);
|
||||
}
|
||||
|
||||
// Credentials are keyed by identity (email/username), not uid
|
||||
$this->credentialStore->delete($tenantId, $user['identity']);
|
||||
|
||||
return new JsonResponse(['success' => true]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user