Skip to content

Commit ce39f37

Browse files
authored
Merge pull request #480 from dotkernel/issue-479
updated account delete
2 parents 7c5b620 + 479f129 commit ce39f37

File tree

6 files changed

+31
-13
lines changed

6 files changed

+31
-13
lines changed

config/autoload/authentication.global.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
'identity_property' => 'identity',
1515
'credential_property' => 'password',
1616
'messages' => [
17-
'success' => 'Authenticated successfully.',
18-
'not_found' => 'Identity not found.',
19-
'invalid_credential' => 'Invalid credentials.',
17+
'success' => Message::AUTHENTICATED_SUCCESSFULLY,
18+
'not_found' => Message::ACCOUNT_NOT_FOUND,
19+
'invalid_credential' => Message::INVALID_CREDENTIALS,
2020
],
2121
'options' => [
2222
'status' => [
@@ -25,7 +25,7 @@
2525
],
2626
'isDeleted' => [
2727
'value' => false,
28-
'message' => Message::IS_DELETED,
28+
'message' => Message::ACCOUNT_NOT_FOUND,
2929
],
3030
],
3131
],

config/autoload/local.php.dist

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ $databases = [
2626
];
2727

2828
return [
29-
'application' => [
29+
'application' => [
3030
'name' => 'DotKernel',
3131
'url' => $baseUrl,
3232
],
33-
'databases' => $databases,
34-
'doctrine' => [
33+
'databases' => $databases,
34+
'doctrine' => [
3535
'connection' => [
3636
'orm_default' => [
3737
'params' => $databases['default'],
3838
],
3939
],
4040
],
41-
'uploads' => [
41+
'uploads' => [
4242
'user' => [
4343
'url' => $baseUrl . '/uploads/user',
4444
'path' => realpath(__DIR__ . '/../../public/uploads/user'),
4545
],
4646
],
47-
'contact' => [
47+
'contact' => [
4848
'notification_receivers' => [],
4949
'message_receivers' => [
5050
'to' => [
@@ -55,16 +55,17 @@ return [
5555
],
5656
],
5757
],
58-
'recaptcha' => [
58+
'recaptcha' => [
5959
'scoreThreshold' => 0.5,
6060
'siteKey' => '',
6161
'secretKey' => '',
6262
'verifyUrl' => 'https://www.google.com/recaptcha/api/siteverify',
6363
],
64-
'rememberMe' => [
64+
'rememberMe' => [
6565
'cookie' => [
6666
'name' => 'rememberMe',
6767
'lifetime' => 3600 * 24 * 30,
6868
],
6969
],
70+
'userAnonymizeAppend' => '',
7071
];

src/App/src/Common/Message.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Message
99
public const DUPLICATE_EMAIL = 'An account with this email address already exists.';
1010
public const RESTRICTION_ROLES = 'User accounts must have at least one role.';
1111
public const INVALID_ACTIVATION_CODE = 'Invalid activation code.';
12+
public const AUTHENTICATED_SUCCESSFULLY = 'Authenticated successfully.';
13+
public const INVALID_CREDENTIALS = 'Invalid credentials.';
1214
public const MAIL_SENT_RESET_PASSWORD = 'If the provided email identifies an account in our system, '
1315
. 'you will receive an email with further instructions on resetting your account\'s password.';
1416
public const MISSING_PARAMETER = 'Missing parameter: \'%s\'';
@@ -23,5 +25,6 @@ class Message
2325
public const PASSWORD_RESET_SUCCESSFULLY = 'Password Successfully reset.';
2426
public const USER_NOT_ACTIVATED = 'User account must be activated first.';
2527
public const DELETE_ACCOUNT = 'You must check delete option.';
26-
public const IS_DELETED = 'User is deleted.';
28+
public const ACCOUNT_IS_DELETED = 'Your account is deleted.';
29+
public const ACCOUNT_NOT_FOUND = 'Account not found.';
2730
}

src/Page/templates/page/home.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{% block page_title %}{% endblock %}
66

77
{% block content %}
8+
{{ messagesPartial('partial::alerts', {}, null, 'page-home') }}
89
<div class="page-intro home-intro">
910
<div class="container">
1011
<p class="welcome">DotKernel is a collection of</p>

src/User/src/Controller/AccountController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public function deleteAccountAction(): ResponseInterface
438438
// logout and enter new password to login
439439
$this->authenticationService->clearIdentity();
440440

441-
$this->messenger->addSuccess('Your account is deleted.', 'page-home');
441+
$this->messenger->addSuccess(Message::ACCOUNT_IS_DELETED, 'page-home');
442442
return new RedirectResponse($this->router->generateUri('page'));
443443
} else {
444444
$this->messenger->addData('shouldRebind', true);

src/User/src/Service/UserService.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Mezzio\Template\TemplateRendererInterface;
2626
use Ramsey\Uuid\Uuid;
2727

28+
use function date;
2829
use function file_exists;
2930
use function is_readable;
3031
use function mkdir;
@@ -134,6 +135,18 @@ public function updateUser(User $user, array $data = []): User
134135

135136
if (isset($data['isDeleted'])) {
136137
$user->setIsDeleted((bool) $data['isDeleted']);
138+
139+
if ((bool) $data['isDeleted'] === true) {
140+
// make user anonymous
141+
$user->setIdentity(
142+
sprintf('anonymous%s@%s', date('dmYHis'), $this->config['userAnonymizeAppend'])
143+
);
144+
$userDetails = $user->getDetail();
145+
$userDetails->setFirstName('anonymous' . date('dmYHis'));
146+
$userDetails->setLastName('anonymous' . date('dmYHis'));
147+
148+
$user->setDetail($userDetails);
149+
}
137150
}
138151

139152
if (isset($data['hash'])) {

0 commit comments

Comments
 (0)