forked from osclass/Osclass
/
register.php
118 lines (107 loc) · 7.11 KB
/
register.php
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
<?php
/**
* OSClass – software for creating and publishing online classified advertising platforms
*
* Copyright (C) 2010 OSCLASS
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class CWebRegister extends BaseModel
{
function __construct() {
parent::__construct() ;
}
//Business Layer...
function doModel() {
switch( $this->action ) {
case('register'): //register user
$this->doView('user-register.php') ;
break;
case('register_post'): //register user
require_once LIB_PATH . 'osclass/UserActions.php' ;
$userActions = new UserActions(false) ;
$success = $userActions->add() ;
switch($success) {
case 1: osc_add_flash_message( _m('The user has been created. An activation email has been sent')) ;
$this->redirectTo( osc_base_url() ) ;
break;
case 2: osc_add_flash_message( _m('Your account has been created successfully')) ;
$this->doView('user-login.php') ;
break;
case 3: osc_add_flash_message( _m('The specified e-mail is already in use')) ;
$this->doView('user-register.php') ;
break;
case 4: osc_add_flash_message( _m('The reCAPTCHA was not introduced correctly')) ;
$this->doView('user-register.php') ;
break;
}
break;
case('validate'): //validate account
$id = intval( Params::getParam('id') ) ;
$code = Params::getParam('code') ;
$userManager = new User() ;
$user = $userManager->findByIdSecret($id, $code) ;
if ($user) {
if (!$user['b_enabled']) {
$userManager = new User() ;
$userManager->update(
array('b_enabled' => '1')
,array('pk_i_id' => $id, 's_secret' => $code)
) ;
$pageManager = new Page() ;
$locale = osc_current_user_locale() ;
$aPage = $pageManager->findByInternalName('email_user_registration') ;
$content = array() ;
if(isset($aPage['locale'][$locale]['s_title'])) {
$content = $aPage['locale'][$locale] ;
} else {
$content = current($aPage['locale']) ;
}
if (!is_null($content)) {
$words = array();
$words[] = array('{USER_NAME}', '{USER_EMAIL}', '{WEB_TITLE}', '{WEB_URL}') ;
$words[] = array($user['s_name'], $user['s_email'], osc_page_title(), osc_base_url() ) ;
$title = osc_mailBeauty($content['s_title'], $words) ;
$body = osc_mailBeauty($content['s_text'], $words) ;
$emailParams = array(
'subject' => $title
,'to' => $user['s_email']
,'to_name' => $user['s_name']
,'body' => $body
,'alt_body' => $body
);
osc_sendMail($emailParams) ;
}
osc_run_hook('validate_user', $user) ;
osc_add_flash_message( _m('Your account has been validated')) ;
// Auto-login
Session::newInstance()->_set('userId', $user['pk_i_id']) ;
Session::newInstance()->_set('userName', $user['s_name']) ;
Session::newInstance()->_set('userEmail', $user['s_email']) ;
$phone = ($user['s_phone_mobile']) ? $user['s_phone_mobile'] : $user['s_phone_land'];
Session::newInstance()->_set('userPhone', $phone) ;
} else {
osc_add_flash_message( _m('Your account has already been activated')) ;
}
} else {
osc_add_flash_message( _m('The link is not valid anymore. Sorry for the inconvenience!')) ;
}
$this->redirectTo( osc_base_url() ) ;
break;
}
}
//hopefully generic...
function doView($file) {
osc_current_web_theme_path($file) ;
}
}
?>