ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.DeleteAccountGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\UI\Factory as UIFactory;
27use ILIAS\UI\Renderer as UIRenderer;
29
31{
32 public function __construct(
33 private readonly \ilCtrl $ctrl,
34 private readonly Language $lng,
35 private readonly \ilGlobalTemplateInterface $tpl,
36 private readonly UIFactory $ui_factory,
37 private readonly UIRenderer $ui_renderer,
38 private readonly \ilToolbarGUI $toolbar,
39 private readonly LoggingServices $log,
40 private readonly \ilMailMimeSenderFactory $mail_sender_factory,
41 private readonly \ilSetting $settings,
42 private readonly \ilAuthSession $auth_session,
43 private readonly \ilObjUser $current_user
44 ) {
45 }
46
47 public function executeCommand(): void
48 {
49 $this->tpl->setTitle($this->lng->txt('user_delete_own_account'));
50 $cmd = $this->ctrl->getCmd('deleteOwnAccountStep1');
51 $this->$cmd();
52 }
53
54 protected function deleteOwnAccountStep1(): void
55 {
56 if (!(bool) $this->settings->get('user_delete_own_account') ||
57 $this->current_user->getId() === SYSTEM_USER_ID) {
58 $this->ctrl->redirectByClass(
59 [\ilDashboardGUI::class, PersonalSettingsGUI::class],
60 'show'
61 );
62 }
63
64 // to make sure
65 $this->current_user->removeDeletionFlag();
66
67 $modal = $this->ui_factory->modal()->interruptive(
68 $this->lng->txt('user_delete_own_account'),
69 $this->lng->txt('user_delete_own_account_logout_confirmation'),
70 $this->ctrl->getFormActionByClass(
71 self::class,
72 'deleteOwnAccountLogout'
73 )
74 )->withActionButtonLabel(
75 $this->lng->txt('user_delete_own_account_logout_button')
76 );
77
78 $this->tpl->setOnScreenMessage(
79 'info',
80 $this->lng->txt('user_delete_own_account_info')
81 );
82 $this->toolbar->addComponent(
83 $this->ui_factory->button()->standard(
84 $this->lng->txt('btn_next'),
85 $modal->getShowSignal()
86 )
87 );
88
89 $this->tpl->setContent($this->ui_renderer->render($modal));
90
91 $this->tpl->printToStdout();
92 }
93
94 protected function abortDeleteOwnAccount(): void
95 {
96 $this->current_user->removeDeletionFlag();
97
98 $this->tpl->setOnScreenMessage(
99 'info',
100 $this->lng->txt('user_delete_own_account_aborted'),
101 true
102 );
103 $this->ctrl->redirectByClass(
104 [\ilDashboardGUI::class, PersonalSettingsGUI::class],
105 'show'
106 );
107 }
108
109 protected function deleteOwnAccountLogout(): void
110 {
111 $this->current_user->activateDeletionFlag();
112
114 $this->auth_session->logout();
115
116 $this->ctrl->redirectToURL(
117 'login.php?cmd=force_login&target=usr_'
119 );
120 }
121
122 protected function deleteOwnAccountStep2(): void
123 {
124 if (
125 !(bool) $this->settings->get('user_delete_own_account') ||
126 $this->current_user->getId() === SYSTEM_USER_ID ||
127 !$this->current_user->hasDeletionFlag()
128 ) {
129 $this->ctrl->redirect($this, 'showGeneralSettings');
130 }
131
132 $this->tpl->setOnScreenMessage(
133 'question',
134 $this->lng->txt('user_delete_own_account_final_confirmation')
135 );
136
137 $this->toolbar->addComponent(
138 $this->ui_factory->button()->standard(
139 $this->lng->txt('confirm'),
140 $this->ctrl->getLinkTargetByClass(
141 self::class,
142 'deleteOwnAccountStep3'
143 )
144 )
145 );
146
147 $this->toolbar->addComponent(
148 $this->ui_factory->button()->standard(
149 $this->lng->txt('cancel'),
150 $this->ctrl->getLinkTargetByClass(
151 self::class,
152 'abortDeleteOwnAccount'
153 )
154 )
155 );
156 $this->tpl->printToStdout();
157 }
158
159 protected function deleteOwnAccountStep3(): void
160 {
161 if (
162 !(bool) $this->settings->get('user_delete_own_account') ||
163 $this->current_user->getId() === SYSTEM_USER_ID ||
164 !$this->current_user->hasDeletionFlag()
165 ) {
166 $this->ctrl->redirect($this, 'showGeneralSettings');
167 }
168
169 // build notification
170
171 $ntf = new \ilSystemNotification();
172 $ntf->setLangModules(['user']);
173 $ntf->addAdditionalInfo(
174 'profile',
175 $this->current_user->getProfileAsString($this->lng),
176 true
177 );
178
179 // mail message
181 $ntf->setIntroductionDirect(
182 sprintf(
183 $this->lng->txt('user_delete_own_account_email_body'),
184 $this->current_user->getLogin(),
185 ILIAS_HTTP_PATH,
187 new \ilDateTime(
188 time(),
190 )
191 )
192 )
193 );
194
195 $message = $ntf->composeAndGetMessage(
196 $this->current_user->getId(),
197 null,
198 'read',
199 true
200 );
201 $subject = $this->lng->txt('user_delete_own_account_email_subject');
202
203 // send notification
204 $user_email = $this->current_user->getEmail();
205 $admin_mail = $this->settings->get('user_delete_own_account_email');
206
207 $mmail = new \ilMimeMail();
208 $mmail->From($this->mail_sender_factory->system());
209
210 if ($user_email !== '') {
211 $mmail->To($user_email);
212 $mmail->Bcc($admin_mail);
213 $mmail->Subject($subject, true);
214 $mmail->Body($message);
215 $mmail->Send();
216 } elseif ($admin_mail !== null || $admin_mail !== '') {
217 $mmail->To($admin_mail);
218 $mmail->Subject($subject, true);
219 $mmail->Body($message);
220 $mmail->Send();
221 }
222
223 $this->log->root()->log(
224 'Account deleted: ' . $this->current_user->getLogin()
225 . ' (' . $this->current_user->getId() . ')'
226 );
227
228 $this->current_user->delete();
229
230 // terminate session
231 $this->auth_session->logout();
232 $this->ctrl->redirectToURL('login.php?accdel=1');
233 }
234}
Provides fluid interface to LoggingServices.
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
__construct(private readonly \ilCtrl $ctrl, private readonly Language $lng, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly \ilToolbarGUI $toolbar, private readonly LoggingServices $log, private readonly \ilMailMimeSenderFactory $mail_sender_factory, private readonly \ilSetting $settings, private readonly \ilAuthSession $auth_session, private readonly \ilObjUser $current_user)
@ilCtrl_Calls ILIAS\User\Settings\PersonalSettingsGUI: ILIAS\User\Account\DeleteAccountGUI @ilCtrl_Ca...
const IL_CAL_UNIX
Class ilCtrl provides processing control methods.
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
User class.
static setClosingContext(int $a_context)
set closing context (for statistics)
const int SESSION_CLOSE_USER
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
An entity that renders components to a string output.
Definition: Renderer.php:31
$log
Definition: ltiresult.php:34
global $lng
Definition: privfeed.php:31