Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 131 lines (114 sloc) 7.165 kb
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
1 <?php if ( !defined('ABS_PATH') ) exit('ABS_PATH is not loaded. Direct access is not allowed.') ;
dee7fe2 - Created new business layer for users and login
devconquer authored
2
3 /**
4 * OSClass – software for creating and publishing online classified advertising platforms
5 *
6 * Copyright (C) 2010 OSCLASS
7 *
8 * This program is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU Affero General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 class CWebRegister extends BaseModel
21 {
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
22 function __construct()
23 {
dee7fe2 - Created new business layer for users and login
devconquer authored
24 parent::__construct() ;
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
25
b733dd3 @juanramon user settings are used now
juanramon authored
26 if( !osc_users_enabled() ) {
27 osc_add_flash_error_message( _m('Users not enabled') ) ;
dd331f5 @juanramon do not put index.php in osc_base_url if it is a redirect to the home
juanramon authored
28 $this->redirectTo( osc_base_url() ) ;
b733dd3 @juanramon user settings are used now
juanramon authored
29 }
30
31 if( !osc_user_registration_enabled() ) {
32 osc_add_flash_error_message( _m('User registration is not enabled') ) ;
dd331f5 @juanramon do not put index.php in osc_base_url if it is a redirect to the home
juanramon authored
33 $this->redirectTo( osc_base_url() ) ;
b733dd3 @juanramon user settings are used now
juanramon authored
34 }
5ea0fef @juanramon not show register view if the user is logged in
juanramon authored
35
36 if( osc_is_web_user_logged_in() ) {
37 $this->redirectTo( osc_base_url() ) ;
38 }
dee7fe2 - Created new business layer for users and login
devconquer authored
39 }
40
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
41 function doModel()
42 {
dee7fe2 - Created new business layer for users and login
devconquer authored
43 switch( $this->action ) {
44 case('register'): //register user
45 $this->doView('user-register.php') ;
46 break;
47 case('register_post'): //register user
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
48 if( !osc_users_enabled() ) {
49 osc_add_flash_error_message( _m('Users are not enabled') ) ;
50 $this->redirectTo( osc_base_url() ) ;
66cad5c @conejoninja users
conejoninja authored
51 }
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
52
53 osc_run_hook('before_user_register') ;
54
df575ac changed users.php for UserActions.php
devconquer authored
55 require_once LIB_PATH . 'osclass/UserActions.php' ;
a6b7aeb fixed work with users in oc-admin and website
devconquer authored
56 $userActions = new UserActions(false) ;
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
57 $success = $userActions->add() ;
58
a6b7aeb fixed work with users in oc-admin and website
devconquer authored
59 switch($success) {
dd0854d @conejoninja issue 340. added osc_add_flash_error_message, osc_add_flash_ok_message a...
conejoninja authored
60 case 1: osc_add_flash_ok_message( _m('The user has been created. An activation email has been sent')) ;
a6b7aeb fixed work with users in oc-admin and website
devconquer authored
61 $this->redirectTo( osc_base_url() ) ;
62 break;
dd0854d @conejoninja issue 340. added osc_add_flash_error_message, osc_add_flash_ok_message a...
conejoninja authored
63 case 2: osc_add_flash_ok_message( _m('Your account has been created successfully')) ;
a6b7aeb fixed work with users in oc-admin and website
devconquer authored
64 $this->doView('user-login.php') ;
65 break;
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
66 case 3: osc_add_flash_warning_message( _m('The specified e-mail is already in use')) ;
a6b7aeb fixed work with users in oc-admin and website
devconquer authored
67 $this->doView('user-register.php') ;
68 break;
dd0854d @conejoninja issue 340. added osc_add_flash_error_message, osc_add_flash_ok_message a...
conejoninja authored
69 case 4: osc_add_flash_error_message( _m('The reCAPTCHA was not introduced correctly')) ;
90d6cf5 @juanramon recaptcha is working fine now
juanramon authored
70 $this->doView('user-register.php') ;
71 break;
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
72 case 5: osc_add_flash_warning_message( _m('The email is not valid')) ;
73 $this->doView('user-register.php') ;
74 break;
75 case 6: osc_add_flash_warning_message( _m('The password cannot be empty')) ;
76 $this->doView('user-register.php') ;
77 break;
78 case 7: osc_add_flash_warning_message( _m("Passwords don't match")) ;
198312f @conejoninja check of email validity done in JS and PHP, also changed from plain JS t...
conejoninja authored
79 $this->doView('user-register.php') ;
80 break;
dee7fe2 - Created new business layer for users and login
devconquer authored
81 }
82 break;
83 case('validate'): //validate account
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
84 $id = intval( Params::getParam('id') ) ;
85 $code = Params::getParam('code') ;
dee7fe2 - Created new business layer for users and login
devconquer authored
86 $userManager = new User() ;
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
87 $user = $userManager->findByIdSecret($id, $code) ;
88
89 if ( !$user ) {
90 osc_add_flash_error_message( _m('The link is not valid anymore. Sorry for the inconvenience!') ) ;
91 $this->redirectTo( osc_base_url() ) ;
92 }
93
94 if ( $user['b_active'] == 1 ) {
95 osc_add_flash_error_message( _m('Your account has already been validated')) ;
96 $this->redirectTo( osc_base_url() ) ;
dee7fe2 - Created new business layer for users and login
devconquer authored
97 }
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
98
99 $userManager = new User() ;
100 $userManager->update(
101 array('b_active' => '1')
102 ,array('pk_i_id' => $id, 's_secret' => $code)
103 ) ;
104
105 osc_run_hook('hook_email_user_registration', $user);
106 osc_run_hook('validate_user', $user) ;
107
108 // Auto-login
109 Session::newInstance()->_set('userId', $user['pk_i_id']) ;
110 Session::newInstance()->_set('userName', $user['s_name']) ;
111 Session::newInstance()->_set('userEmail', $user['s_email']) ;
112 $phone = ($user['s_phone_mobile']) ? $user['s_phone_mobile'] : $user['s_phone_land'];
113 Session::newInstance()->_set('userPhone', $phone) ;
114
115 osc_add_flash_ok_message( _m('Your account has been validated')) ;
15e898d deleting and changing calls of deprecated functions
devconquer authored
116 $this->redirectTo( osc_base_url() ) ;
dee7fe2 - Created new business layer for users and login
devconquer authored
117 break;
118 }
119 }
120
54e7098 @juanramon check if the password is empty or is different from "re-type password" f...
juanramon authored
121 function doView($file)
122 {
123 osc_run_hook( 'before_html' );
124 osc_current_web_theme_path( $file ) ;
125 Session::newInstance()->_clearVariables() ;
126 osc_run_hook( 'after_html' ) ;
dee7fe2 - Created new business layer for users and login
devconquer authored
127 }
128 }
129
aec0c01 @juanramon code style guidelines + not usin slash in string to escape single quotes
juanramon authored
130 /* file end: ./register.php */
5fc77b6 @juanramon die if ABS_PATH does not exist and I have formatted a bit some files
juanramon authored
131 ?>
Something went wrong with that request. Please try again.