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