ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.DeleteAccountGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\UI\Factory as UIFactory;
26use ILIAS\UI\Renderer as UIRenderer;
28
30{
31 public function __construct(
32 private readonly \ilCtrl $ctrl,
33 private readonly Language $lng,
34 private readonly \ilGlobalTemplateInterface $tpl,
35 private readonly UIFactory $ui_factory,
36 private readonly UIRenderer $ui_renderer,
37 private readonly \ilToolbarGUI $toolbar,
38 private readonly LoggingServices $log,
39 private readonly \ilMailMimeSenderFactory $mail_sender_factory,
40 private readonly \ilSetting $settings,
41 private readonly \ilAuthSession $auth_session,
42 private readonly \ilObjUser $current_user
43 ) {
44 }
45
46 public function executeCommand(): void
47 {
48 $this->tpl->setTitle($this->lng->txt('user_delete_own_account'));
49 $cmd = $this->ctrl->getCmd('showGeneralSettings');
50 $this->$cmd() . 'Cmd';
51 }
52
53 protected function deleteOwnAccountStep1(): void
54 {
55 if (!(bool) $this->settings->get('user_delete_own_account') ||
56 $this->current_user->getId() === SYSTEM_USER_ID) {
57 $this->ctrl->redirectByClass(
58 [\ilDashboardGUI::class, PersonalSettingsGUI::class],
59 'show'
60 );
61 }
62
63 // to make sure
64 $this->current_user->removeDeletionFlag();
65
66 $modal = $this->ui_factory->modal()->interruptive(
67 $this->lng->txt('user_delete_own_account'),
68 $this->lng->txt('user_delete_own_account_logout_confirmation'),
69 $this->ctrl->getFormActionByClass(self::class, 'deleteOwnAccountLogout')
70 )->withActionButtonLabel($this->lng->txt('user_delete_own_account_logout_button'));
71
72 $this->tpl->setOnScreenMessage('info', $this->lng->txt('user_delete_own_account_info'));
73 $this->toolbar->addComponent(
74 $this->ui_factory->button()->standard(
75 $this->lng->txt('btn_next'),
76 $modal->getShowSignal()
77 )
78 );
79
80 $this->tpl->setContent($this->ui_renderer->render($modal));
81
82 $this->tpl->printToStdout();
83 }
84
85 protected function abortDeleteOwnAccount(): void
86 {
87 $this->current_user->removeDeletionFlag();
88
89 $this->tpl->setOnScreenMessage('info', $this->lng->txt('user_delete_own_account_aborted'), true);
90 $this->ctrl->redirect($this, 'showGeneralSettings');
91 }
92
93 protected function deleteOwnAccountLogout(): void
94 {
95 $this->current_user->activateDeletionFlag();
96
98 $this->auth_session->logout();
99
100 $this->ctrl->redirectToURL(
101 'login.php?cmd=force_login&target=usr_'
103 );
104 }
105
106 protected function deleteOwnAccountStep2(): void
107 {
108 if (
109 !(bool) $this->settings->get('user_delete_own_account') ||
110 $this->current_user->getId() === SYSTEM_USER_ID ||
111 !$this->current_user->hasDeletionFlag()
112 ) {
113 $this->ctrl->redirect($this, 'showGeneralSettings');
114 }
115
116 $this->tpl->setOnScreenMessage(
117 'question',
118 $this->lng->txt('user_delete_own_account_final_confirmation')
119 );
120
121 $this->toolbar->addComponent(
122 $this->ui_factory->button()->standard(
123 $this->lng->txt('confirm'),
124 $this->ctrl->getLinkTargetByClass(self::class, 'deleteOwnAccountStep3')
125 )
126 );
127
128 $this->toolbar->addComponent(
129 $this->ui_factory->button()->standard(
130 $this->lng->txt('cancel'),
131 $this->ctrl->getLinkTargetByClass(self::class, 'abortDeleteOwnAccount')
132 )
133 );
134 $this->tpl->printToStdout();
135 }
136
137 protected function deleteOwnAccountStep3(): void
138 {
139 if (
140 !(bool) $this->settings->get('user_delete_own_account') ||
141 $this->current_user->getId() === SYSTEM_USER_ID ||
142 !$this->current_user->hasDeletionFlag()
143 ) {
144 $this->ctrl->redirect($this, 'showGeneralSettings');
145 }
146
147 // build notification
148
149 $ntf = new \ilSystemNotification();
150 $ntf->setLangModules(['user']);
151 $ntf->addAdditionalInfo('profile', $this->current_user->getProfileAsString($this->lng), true);
152
153 // mail message
155 $ntf->setIntroductionDirect(
156 sprintf(
157 $this->lng->txt('user_delete_own_account_email_body'),
158 $this->current_user->getLogin(),
159 ILIAS_HTTP_PATH,
161 )
162 );
163
164 $message = $ntf->composeAndGetMessage($this->current_user->getId(), null, 'read', true);
165 $subject = $this->lng->txt('user_delete_own_account_email_subject');
166
167 // send notification
168 $user_email = $this->current_user->getEmail();
169 $admin_mail = $this->settings->get('user_delete_own_account_email');
170
171 $mmail = new \ilMimeMail();
172 $mmail->From($this->mail_sender_factory->system());
173
174 if ($user_email !== '') {
175 $mmail->To($user_email);
176 $mmail->Bcc($admin_mail);
177 $mmail->Subject($subject, true);
178 $mmail->Body($message);
179 $mmail->Send();
180 } elseif ($admin_mail !== null || $admin_mail !== '') {
181 $mmail->To($admin_mail);
182 $mmail->Subject($subject, true);
183 $mmail->Body($message);
184 $mmail->Send();
185 }
186
187 $this->log->root()->log('Account deleted: ' . $this->current_user->getLogin() . ' (' . $this->current_user->getId() . ')');
188
189 $this->current_user->delete();
190
191 // terminate session
192 $this->auth_session->logout();
193 $this->ctrl->redirectToURL('login.php?accdel=1');
194 }
195}
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)
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