users_register.php
5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
class users_register{
private $error = false;
private $act = 'form';
function __construct(){
global $MAIN_PAGE;
define('M_PATH',MAIN_SOURCE_PATH.'/modules/'.$MAIN_PAGE -> dirname() );
define('M_URL',MAIN_SOURCE_URL.'/modules/'.$MAIN_PAGE -> dirname() );
include_once(M_PATH.'/inc/url.php');
include_once(MAIN_PATH.'/tmp/config/users.php');
include_once(MAIN_PATH.'/tmp/meta/users.php');
include_once(M_PATH.'/inc/class.users.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.html.php');
include_once(MAIN_SOURCE_PATH.'/ext/ajax/JsHttpRequest.php');
new JsHttpRequest($MAIN_PAGE -> charset());
$this -> act = !empty($_REQUEST['act']) ? $_REQUEST['act'] : $this -> act;
$GLOBALS['_RESULT']['id_request'] = !empty($_REQUEST['id_request']) ? $_REQUEST['id_request'] : 0;
}
public function get(){
global $MAIN_PAGE;
$func = $this -> act;
if ( !method_exists($this ,$func) ){
sys_error(ERROR_404);
}
$MAIN_PAGE -> set_key($func);
return $this -> $func();
}
/**
* Форма регистрации пользователей / сообщение о активации / итоговая регистрация
*
*/
private function form(){
global $MAIN_PAGE;
$t = new PHPTAL( false );
$t -> setSnippet( 'users','user_register_form');
$t -> row = $_POST['form'];
$t -> error = $this -> error;
$MAIN_PAGE -> set_title( 2, $MAIN_PAGE -> meta_title( 'form' ) );
return $t -> execute();
}
private function save(){
global $MAIN_PAGE;
$u = users::create();
// активация аккаунта
$active = $MAIN_PAGE -> config('users_active')==1 ? 0 : 1;
try{
foreach( $_POST['form'] as $k=>$v ){
$u -> set($k,$v);
}
$u -> set('u_active',$active);
$u -> set('u_time_reg',MAIN_TIME);
$u -> set('u_act_code', sys_str_rand(5));
$u -> set('g_id', $MAIN_PAGE -> config('users_register_group') );
//$u -> set_debug(1);
$id = $u -> insert() ;
}catch(Exception $e){
$this -> error = $e -> getMessage();
return $this -> form();
}
if ( empty($active) ){
include_once(MAIN_SOURCE_PATH.'/inc/class.mail.php');
$m = mail::load('register_confirm');
if ( false===$m ){
sys_error(ERROR_500);
}
$m -> set('MAIN_URL',MAIN_URL);
$m -> set('uname',$u -> name());
$m -> set('login',$u -> login());
$m -> set('URL_USERS_REGISTER_ACTIV', sys_url(URL_USERS_REGISTER_ACTIV,$u -> id(),$u -> act_code()) );
$m -> send_mail( $u -> email() );
}
$t = new PHPTAL( false );
$t -> setSnippet( 'users','users_register_save');
$t -> active = $active;
return $t -> execute();
}
/**
* Активация аккаунта
*
*/
private function active(){
global $MAIN_PAGE;
try{
$u = users::load_id($_GET['id']);
if ( false===$u ){
throw new Exception('Ошибка: пользователь не найден!');
}
if ( $u -> act_code()!=$_GET['code'] ){
throw new Exception('Ошибка: неверная ссылка!');
}
if ( $u -> active()==1){
throw new Exception('Ошибка: пользователь уже активирован!');
}
$u -> set('u_active',1);
$u -> set('u_act_code',sys_str_rand(5) );
$u -> update();
}catch( Exception $e ){
$error = $e -> getMessage();
}
// регистрация окончена
$t = new PHPTAL( false );
$t -> setSnippet( 'users','users_register_active');
$t -> error = $error;
//$MAIN_PAGE -> set_title( 2, $MAIN_PAGE -> meta_title( 'form' ) );
return $t -> execute();
}
private function ajax_form($end=0){
sys_block_disable();
$t = new PHPTAL( false );
$t -> setSnippet( 'users','ajax_register_form');
$captcha = captcha::show();
$t -> image_src = $captcha['img'];
$t -> register_end = 0;
$GLOBALS['_RESULT']['content'] = $t -> execute();
$GLOBALS['_RESULT']['title'] = 'Регистрация';
exit();
}
private function ajax_save($end=0){
sys_block_disable();
$u = users::create();
try{
foreach( $_POST['form'] as $k=>$v ){
$u -> set($k,$v);
}
$u -> set('u_active',0);
$u -> set('u_time_reg',MAIN_TIME);
$u -> set('u_act_code', sys_str_rand(5));
$u -> set('g_id',3);
if ( !captcha::check() ){
throw new Exception( 'Ошибка:Защитный код ведён неверно!' );
}
$id = $u -> insert();
}catch(Exception $e){
echo $e -> getMessage();
exit();
}
include_once(MAIN_SOURCE_PATH.'/inc/class.mail.php');
$m = mail::load('register_confirm');
$m -> set('uname',$u -> name());
$m -> set('URL_USER_REGISTER_ACTIV', sys_url(URL_USERS_REGISTER_ACTIV,$u -> id(),$u -> act_code()) );
$m -> send_mail( $u -> email() );
// спасибо за регисрацию ....
$t = new PHPTAL( false );
$t -> setSnippet( 'users','ajax_register_form');
$t -> register_end = 1;
$GLOBALS['_RESULT']['msg'] = $t -> execute();
exit();
}
}
?>