|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package CleverStyle Framework |
|
4
|
|
|
* @subpackage System module |
|
5
|
|
|
* @category modules |
|
6
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
|
7
|
|
|
* @license 0BSD |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace cs\modules\System; |
|
10
|
|
|
use |
|
11
|
|
|
cs\Config, |
|
12
|
|
|
cs\Event, |
|
13
|
|
|
cs\ExitException, |
|
14
|
|
|
cs\Language, |
|
15
|
|
|
cs\Mail, |
|
16
|
|
|
cs\Page, |
|
17
|
|
|
cs\Session, |
|
18
|
|
|
cs\User; |
|
19
|
|
|
|
|
20
|
|
|
class Controller { |
|
21
|
|
|
/** |
|
22
|
|
|
* @param \cs\Request $Request |
|
23
|
|
|
* @param \cs\Response $Response |
|
24
|
|
|
* |
|
25
|
|
|
* @throws ExitException |
|
26
|
|
|
*/ |
|
27
|
|
|
public static function profile_registration_confirmation ($Request, $Response) { |
|
28
|
|
|
$L = Language::prefix('system_profile_registration_'); |
|
29
|
|
|
$User = User::instance(); |
|
30
|
|
|
if (!$User->guest()) { |
|
31
|
|
|
static::redirect_with_notification($Response, $L->you_are_already_registered, 'notice'); |
|
|
|
|
|
|
32
|
|
|
} elseif (!isset($Request->route[2])) { |
|
33
|
|
|
static::redirect_with_notification($Response, $L->invalid_confirmation_code, 'warning'); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
$result = $User->registration_confirmation($Request->route[2]); |
|
36
|
|
|
if ($result === false) { |
|
|
|
|
|
|
37
|
|
|
static::redirect_with_notification($Response, $L->invalid_confirmation_code, 'warning'); |
|
38
|
|
|
} |
|
39
|
|
|
$Config = Config::instance(); |
|
40
|
|
|
if ($result['password']) { |
|
41
|
|
|
$body = $L->success_mail_with_password_body( |
|
42
|
|
|
strstr($result['email'], '@', true), |
|
43
|
|
|
$Config->core['site_name'], |
|
44
|
|
|
Config::instance()->core_url().'/profile/settings', |
|
45
|
|
|
$User->get('login', $result['id']), |
|
46
|
|
|
$result['password'] |
|
47
|
|
|
); |
|
48
|
|
|
} else { |
|
49
|
|
|
$body = $L->success_mail_body( |
|
50
|
|
|
strstr($result['email'], '@', true), |
|
51
|
|
|
$Config->core['site_name'], |
|
52
|
|
|
Config::instance()->core_url().'/profile/settings', |
|
53
|
|
|
$User->get('login', $result['id']) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
if (Mail::instance()->send_to( |
|
57
|
|
|
$result['email'], |
|
58
|
|
|
$L->success_mail($Config->core['site_name']), |
|
59
|
|
|
$body |
|
60
|
|
|
) |
|
61
|
|
|
) { |
|
62
|
|
|
static::redirect_with_notification($Response, $L->success, 'success'); |
|
63
|
|
|
} else { |
|
64
|
|
|
$User->registration_cancel(); |
|
65
|
|
|
static::redirect_with_notification($Response, $L->mail_sending_error, 'warning'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
/** |
|
69
|
|
|
* @param \cs\Response $Response |
|
70
|
|
|
* @param $content |
|
71
|
|
|
* @param string $type `success`, `notice` or `warning` |
|
72
|
|
|
* |
|
73
|
|
|
* @throws ExitException |
|
74
|
|
|
*/ |
|
75
|
|
|
protected static function redirect_with_notification ($Response, $content, $type) { |
|
76
|
|
|
Session::instance()->set_data('system_notification', [$content, $type]); |
|
77
|
|
|
$Response->redirect('/'); |
|
78
|
|
|
throw new ExitException; |
|
79
|
|
|
} |
|
80
|
|
|
/** |
|
81
|
|
|
* @param \cs\Request $Request |
|
82
|
|
|
* @param \cs\Response $Response |
|
83
|
|
|
* |
|
84
|
|
|
* @throws ExitException |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function profile_restore_password_confirmation ($Request, $Response) { |
|
87
|
|
|
$L = Language::prefix('system_profile_restore_password_'); |
|
88
|
|
|
$User = User::instance(); |
|
89
|
|
|
if (!$User->guest()) { |
|
90
|
|
|
static::redirect_with_notification($Response, $L->you_are_already_registered, 'notice'); |
|
|
|
|
|
|
91
|
|
|
} elseif (!isset($Request->route[2])) { |
|
92
|
|
|
static::redirect_with_notification($Response, $L->invalid_confirmation_code, 'warning'); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
$result = $User->restore_password_confirmation($Request->route[2]); |
|
95
|
|
|
if ($result === false) { |
|
|
|
|
|
|
96
|
|
|
static::redirect_with_notification($Response, $L->invalid_confirmation_code, 'warning'); |
|
97
|
|
|
} |
|
98
|
|
|
$Config = Config::instance(); |
|
99
|
|
|
if (Mail::instance()->send_to( |
|
100
|
|
|
$User->get('email', $result['id']), |
|
101
|
|
|
$L->success_mail($Config->core['site_name']), |
|
102
|
|
|
$L->success_mail_body( |
|
103
|
|
|
$User->username($result['id']), |
|
104
|
|
|
$Config->core['site_name'], |
|
105
|
|
|
Config::instance()->core_url().'/profile/settings', |
|
106
|
|
|
$User->get('login', $result['id']), |
|
107
|
|
|
$result['password'] |
|
108
|
|
|
) |
|
109
|
|
|
) |
|
110
|
|
|
) { |
|
111
|
|
|
static::redirect_with_notification($Response, $L->success, 'success'); |
|
112
|
|
|
} else { |
|
113
|
|
|
static::redirect_with_notification($Response, $L->mail_sending_error, 'warning'); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
public static function robots_txt () { |
|
117
|
|
|
$Page = Page::instance(); |
|
118
|
|
|
$Page->interface = false; |
|
119
|
|
|
$text = file_get_contents(__DIR__.'/robots.txt'); |
|
120
|
|
|
Event::instance()->fire( |
|
121
|
|
|
'System/robots.txt', |
|
122
|
|
|
[ |
|
123
|
|
|
'text' => &$text |
|
124
|
|
|
] |
|
125
|
|
|
); |
|
126
|
|
|
$core_url = Config::instance()->core_url(); |
|
127
|
|
|
$core_url_without_protocol = explode('//', $core_url, 2)[1]; |
|
128
|
|
|
$host = explode('/', $core_url_without_protocol, 2)[0]; |
|
129
|
|
|
$Page->Content = "{$text}Host: $host"; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|