Skip to content

Commit

Permalink
updated account delete
Browse files Browse the repository at this point in the history
Signed-off-by: bidi <[email protected]>
  • Loading branch information
bidi47 committed Sep 5, 2024
1 parent 906530e commit 6ad7c05
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions config/autoload/authentication.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
'identity_property' => 'identity',
'credential_property' => 'password',
'messages' => [
'success' => 'Authenticated successfully.',
'not_found' => 'Identity not found.',
'invalid_credential' => 'Invalid credentials.',
'success' => Message::AUTHENTICATED_SUCCESSFULLY,
'not_found' => Message::ACCOUNT_NOT_FOUND,
'invalid_credential' => Message::INVALID_CREDENTIALS,
],
'options' => [
'status' => [
Expand All @@ -25,7 +25,7 @@
],
'isDeleted' => [
'value' => false,
'message' => Message::IS_DELETED,
'message' => Message::ACCOUNT_NOT_FOUND,
],
],
],
Expand Down
15 changes: 8 additions & 7 deletions config/autoload/local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ $databases = [
];

return [
'application' => [
'application' => [
'name' => 'DotKernel',
'url' => $baseUrl,
],
'databases' => $databases,
'doctrine' => [
'databases' => $databases,
'doctrine' => [
'connection' => [
'orm_default' => [
'params' => $databases['default'],
],
],
],
'uploads' => [
'uploads' => [
'user' => [
'url' => $baseUrl . '/uploads/user',
'path' => realpath(__DIR__ . '/../../public/uploads/user'),
],
],
'contact' => [
'contact' => [
'notification_receivers' => [],
'message_receivers' => [
'to' => [
Expand All @@ -55,16 +55,17 @@ return [
],
],
],
'recaptcha' => [
'recaptcha' => [
'scoreThreshold' => 0.5,
'siteKey' => '',
'secretKey' => '',
'verifyUrl' => 'https://www.google.com/recaptcha/api/siteverify',
],
'rememberMe' => [
'rememberMe' => [
'cookie' => [
'name' => 'rememberMe',
'lifetime' => 3600 * 24 * 30,
],
],
'userAnonymizeAppend' => '',
];
5 changes: 4 additions & 1 deletion src/App/src/Common/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Message
public const DUPLICATE_EMAIL = 'An account with this email address already exists.';
public const RESTRICTION_ROLES = 'User accounts must have at least one role.';
public const INVALID_ACTIVATION_CODE = 'Invalid activation code.';
public const AUTHENTICATED_SUCCESSFULLY = 'Authenticated successfully.';
public const INVALID_CREDENTIALS = 'Invalid credentials.';
public const MAIL_SENT_RESET_PASSWORD = 'If the provided email identifies an account in our system, '
. 'you will receive an email with further instructions on resetting your account\'s password.';
public const MISSING_PARAMETER = 'Missing parameter: \'%s\'';
Expand All @@ -23,5 +25,6 @@ class Message
public const PASSWORD_RESET_SUCCESSFULLY = 'Password Successfully reset.';
public const USER_NOT_ACTIVATED = 'User account must be activated first.';
public const DELETE_ACCOUNT = 'You must check delete option.';
public const IS_DELETED = 'User is deleted.';
public const ACCOUNT_IS_DELETED = 'Your account is deleted.';
public const ACCOUNT_NOT_FOUND = 'Account not found.';
}
1 change: 1 addition & 0 deletions src/Page/templates/page/home.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% block page_title %}{% endblock %}

{% block content %}
{{ messagesPartial('partial::alerts', {}, null, 'page-home') }}
<div class="page-intro home-intro">
<div class="container">
<p class="welcome">DotKernel is a collection of</p>
Expand Down
2 changes: 1 addition & 1 deletion src/User/src/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public function deleteAccountAction(): ResponseInterface
// logout and enter new password to login
$this->authenticationService->clearIdentity();

$this->messenger->addSuccess('Your account is deleted.', 'page-home');
$this->messenger->addSuccess(Message::ACCOUNT_IS_DELETED, 'page-home');
return new RedirectResponse($this->router->generateUri('page'));
} else {
$this->messenger->addData('shouldRebind', true);
Expand Down
11 changes: 11 additions & 0 deletions src/User/src/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Mezzio\Template\TemplateRendererInterface;
use Ramsey\Uuid\Uuid;

use function date;
use function file_exists;
use function is_readable;
use function mkdir;
Expand Down Expand Up @@ -134,6 +135,16 @@ public function updateUser(User $user, array $data = []): User

if (isset($data['isDeleted'])) {
$user->setIsDeleted((bool) $data['isDeleted']);

if ((bool) $data['isDeleted'] === true) {
// make user anonymous
$user->setIdentity('anonymous' . date('dmYHis') . $this->config['userAnonymizeAppend']);
$userDetails = $user->getDetail();
$userDetails->setFirstName('anonymous' . date('dmYHis'));
$userDetails->setLastName('anonymous' . date('dmYHis'));

$user->setDetail($userDetails);
}
}

if (isset($data['hash'])) {
Expand Down

0 comments on commit 6ad7c05

Please sign in to comment.