These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @author Pierre-Henry Soria <[email protected]> |
||
4 | * @copyright (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved. |
||
5 | * @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
||
6 | * @package PH7 / App / System / Core / Form / Processing |
||
7 | */ |
||
8 | namespace PH7; |
||
9 | defined('PH7') or exit('Restricted access'); |
||
10 | |||
11 | use |
||
12 | PH7\Framework\Mvc\Model\DbConfig, |
||
13 | PH7\Framework\Mail\Mail, |
||
0 ignored issues
–
show
|
|||
14 | PH7\Framework\Mvc\Router\Uri, |
||
15 | PH7\Framework\Url\Header; |
||
16 | |||
17 | /** For "user" and "affiliate" modules **/ |
||
18 | class DeleteUserCoreFormProcess extends Form |
||
19 | { |
||
20 | private $sSessPrefix, $sUsername, $sEmail; |
||
21 | |||
22 | public function __construct() |
||
23 | { |
||
24 | parent::__construct(); |
||
25 | |||
26 | $this->sSessPrefix = ($this->registry->module == 'user') ? 'member' : 'affiliate'; |
||
27 | $this->sUsername = $this->session->get($this->sSessPrefix.'_username'); |
||
28 | $this->sEmail = $this->session->get($this->sSessPrefix.'_email'); |
||
29 | $sTable = ($this->registry->module == 'user') ? 'Members' : 'Affiliates'; |
||
30 | |||
31 | $mLogin = (new UserCoreModel)->login($this->sEmail, $this->httpRequest->post('password'), $sTable); |
||
32 | if ($mLogin === 'password_does_not_exist') { |
||
33 | \PFBC\Form::setError('form_delete_account',t('Oops! This password you entered is incorrect.')); |
||
34 | } else { |
||
35 | $this->session->regenerateId(); |
||
36 | $this->sendWarnEmail(); |
||
37 | $this->removeAccount(); |
||
38 | $this->session->destroy(); |
||
39 | $this->goSoon(); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Send an email to the admin saying the reason why a user wanted to delete their account. |
||
45 | * |
||
46 | * @return integer |
||
47 | */ |
||
48 | protected function sendWarnEmail() |
||
49 | { |
||
50 | $sMembershipType = ($this->registry->module == 'affiliate') ? t('Affiliate') : t('Member'); |
||
51 | |||
52 | $this->view->membership = t('Type of User: %0%.', $sMembershipType); |
||
53 | $this->view->message = nl2br($this->httpRequest->post('message')); |
||
54 | $this->view->why_delete = t('Reason why the user wanted to leave: %0%', $this->httpRequest->post('why_delete')); |
||
55 | $this->view->footer_title = t('User Information'); |
||
56 | $this->view->email = t('Email: %0%', $this->sEmail); |
||
57 | $this->view->username = t('Username: %0%', $this->sUsername); |
||
58 | $this->view->first_name = t('First Name: %0%', $this->session->get($this->sSessPrefix.'_first_name')); |
||
59 | $this->view->sex = t('Sex: %0%', $this->session->get($this->sSessPrefix.'_sex')); |
||
60 | $this->view->ip = t('User IP: %0%', $this->session->get($this->sSessPrefix.'_ip')); |
||
61 | $this->view->browser_info = t('Browser info: %0%', $this->session->get($this->sSessPrefix.'_http_user_agent')); |
||
62 | |||
63 | $sMessageHtml = $this->view->parseMail(PH7_PATH_SYS . 'global/' . PH7_VIEWS . PH7_TPL_MAIL_NAME . '/tpl/mail/sys/core/delete_account.tpl', DbConfig::getSetting('adminEmail')); |
||
64 | |||
65 | $sMembershipName = ($this->registry->module == 'user') ? t('Member') : t('Affiliate'); |
||
66 | |||
67 | /** |
||
68 | * Set the details for sending the email, then send it. |
||
69 | */ |
||
70 | $aInfo = [ |
||
71 | 'subject' => t('Unregister %0% - User: %1%', $sMembershipName, $this->sUsername) |
||
72 | ]; |
||
73 | |||
74 | return (new Mail)->send($aInfo, $sMessageHtml); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Remove the user/affiliate account. |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | protected function removeAccount() |
||
83 | { |
||
84 | $oUserModel = ($this->registry->module == 'user') ? new UserCore : new AffiliateCore; |
||
85 | $oUserModel->delete($this->session->get($this->sSessPrefix.'_id'), $this->sUsername); |
||
86 | unset($oUserModel); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Redirect now the user to the soon page (yesss he/she will be back soon... there is never "never"). |
||
91 | * |
||
92 | * @return void Header::redirect() will also exit the script. |
||
93 | */ |
||
94 | protected function goSoon() |
||
95 | { |
||
96 | Header::redirect(Uri::get('user','main','soon'), t('Your account has been removed successfully!')); |
||
97 | } |
||
98 | } |
||
99 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: