1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package CleverStyle CMS |
4
|
|
|
* @subpackage System module |
5
|
|
|
* @category modules |
6
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi |
8
|
|
|
* @license MIT License, see license.txt |
9
|
|
|
*/ |
10
|
|
|
namespace cs\modules\System; |
11
|
|
|
use |
12
|
|
|
cs\Config, |
13
|
|
|
cs\Event, |
14
|
|
|
cs\Language\Prefix, |
15
|
|
|
cs\Mail, |
16
|
|
|
cs\Page, |
17
|
|
|
cs\Route, |
18
|
|
|
cs\User; |
19
|
|
|
class Controller { |
20
|
|
|
static function profile_registration_confirmation () { |
21
|
|
|
$Config = Config::instance(); |
22
|
|
|
$L = new Prefix('system_profile_'); |
23
|
|
|
$Page = Page::instance(); |
24
|
|
|
$Route = Route::instance(); |
25
|
|
|
$User = User::instance(); |
26
|
|
|
if (_getcookie('reg_confirm')) { |
27
|
|
|
_setcookie('reg_confirm', ''); |
28
|
|
|
$Page->title($L->reg_success_title); |
29
|
|
|
$Page->success($L->reg_success); |
30
|
|
|
return; |
31
|
|
|
} elseif (!$User->guest()) { |
32
|
|
|
$Page->title($L->you_are_already_registered_title); |
33
|
|
|
$Page->warning($L->you_are_already_registered); |
34
|
|
|
return; |
35
|
|
|
} elseif (!isset($Route->route[2])) { |
36
|
|
|
$Page->title($L->invalid_confirmation_code); |
37
|
|
|
$Page->warning($L->invalid_confirmation_code); |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
$result = $User->registration_confirmation($Route->route[2]); |
41
|
|
|
if ($result === false) { |
42
|
|
|
$Page->title($L->invalid_confirmation_code); |
43
|
|
|
$Page->warning($L->invalid_confirmation_code); |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
$body = $L->reg_success_mail_body( |
47
|
|
|
strstr($result['email'], '@', true), |
48
|
|
|
get_core_ml_text('name'), |
49
|
|
|
$Config->core_url().'/profile/settings', |
50
|
|
|
$User->get('login', $result['id']), |
51
|
|
|
$result['password'] |
52
|
|
|
); |
53
|
|
|
if (Mail::instance()->send_to( |
54
|
|
|
$result['email'], |
55
|
|
|
$L->reg_success_mail(get_core_ml_text('name')), |
56
|
|
|
$body |
57
|
|
|
) |
58
|
|
|
) { |
59
|
|
|
_setcookie('reg_confirm', 1, 0, true); |
60
|
|
|
_header("Location: {$Config->base_url()}/System/profile/registration_confirmation"); |
61
|
|
|
} else { |
62
|
|
|
$User->registration_cancel(); |
63
|
|
|
$Page->title($L->sending_reg_mail_error_title); |
64
|
|
|
$Page->warning($L->sending_reg_mail_error); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
static function profile_restore_password_confirmation () { |
68
|
|
|
$Config = Config::instance(); |
69
|
|
|
$L = new Prefix('system_profile_'); |
70
|
|
|
$Page = Page::instance(); |
71
|
|
|
$Route = Route::instance(); |
72
|
|
|
$User = User::instance(); |
73
|
|
|
if (_getcookie('restore_password_confirm')) { |
74
|
|
|
_setcookie('restore_password_confirm', ''); |
75
|
|
|
$Page->title($L->restore_password_success_title); |
76
|
|
|
$Page->success($L->restore_password_success); |
77
|
|
|
return; |
78
|
|
|
} elseif (!$User->guest()) { |
79
|
|
|
$Page->title($L->you_are_already_registered_title); |
80
|
|
|
$Page->warning($L->you_are_already_registered); |
81
|
|
|
return; |
82
|
|
|
} elseif (!isset($Route->route[2])) { |
83
|
|
|
$Page->title($L->invalid_confirmation_code); |
84
|
|
|
$Page->warning($L->invalid_confirmation_code); |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
$result = $User->restore_password_confirmation($Route->route[2]); |
88
|
|
|
if ($result === false) { |
89
|
|
|
$Page->title($L->invalid_confirmation_code); |
90
|
|
|
$Page->warning($L->invalid_confirmation_code); |
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
if (Mail::instance()->send_to( |
94
|
|
|
$User->get('email', $result['id']), |
95
|
|
|
$L->restore_password_success_mail(get_core_ml_text('name')), |
96
|
|
|
$L->restore_password_success_mail_body( |
97
|
|
|
$User->username($result['id']), |
98
|
|
|
get_core_ml_text('name'), |
99
|
|
|
$Config->core_url().'/profile/settings', |
100
|
|
|
$User->get('login', $result['id']), |
101
|
|
|
$result['password'] |
102
|
|
|
) |
103
|
|
|
) |
104
|
|
|
) { |
105
|
|
|
_setcookie('restore_password_confirm', 1, 0, true); |
106
|
|
|
_header("Location: {$Config->base_url()}/System/profile/restore_password_confirmation"); |
107
|
|
|
} else { |
108
|
|
|
$Page->title($L->sending_restore_password_mail_error_title); |
109
|
|
|
$Page->warning($L->sending_restore_password_mail_error); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
static function robots_txt () { |
113
|
|
|
interface_off(); |
114
|
|
|
$text = file_get_contents(__DIR__.'/robots.txt'); |
115
|
|
|
Event::instance()->fire( |
116
|
|
|
'System/robots.txt', |
117
|
|
|
[ |
118
|
|
|
'text' => &$text |
119
|
|
|
] |
120
|
|
|
); |
121
|
|
|
$core_url = Config::instance()->core_url(); |
122
|
|
|
$core_url_without_protocol = explode('//', $core_url, 2)[1]; |
123
|
|
|
$host = explode('/', $core_url_without_protocol, 2)[0]; |
124
|
|
|
Page::instance()->Content = "{$text}Host: $host"; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|