[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * Register a new user. 4 * 5 * This file is part of the evoCore framework - {@link http://evocore.net/} 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 9 * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. 10 * 11 * {@internal License choice 12 * - If you have received this file as part of a package, please find the license.txt file in 13 * the same folder or the closest folder above for complete license terms. 14 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 15 * then you must choose one of the following licenses before using the file: 16 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 17 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 18 * }} 19 * 20 * {@internal Open Source relicensing agreement: 21 * Daniel HAHLER grants Francois PLANQUE the right to license 22 * Daniel HAHLER's contributions to this file and the b2evolution project 23 * under any OSI approved OSS license (http://www.opensource.org/licenses/). 24 * }} 25 * 26 * @package htsrv 27 * 28 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 29 * @author blueyed: Daniel HAHLER 30 * @author fplanque: Francois PLANQUE 31 * 32 * @version $Id: register.php,v 1.86 2007/06/25 10:58:50 fplanque Exp $ 33 */ 34 35 /** 36 * Includes: 37 */ 38 require_once dirname(__FILE__).'/../conf/_config.php'; 39 40 require_once $inc_path.'_main.inc.php'; 41 42 // Login is not required on the register page: 43 $login_required = false; 44 45 46 param( 'action', 'string', '' ); 47 param( 'login', 'string', '' ); 48 param( 'email', 'string', '' ); 49 param( 'locale', 'string', $Settings->get('default_locale') ); 50 param( 'redirect_to', 'string', '' ); // do not default to $admin_url; "empty" gets handled better in the end (uses $blogurl, if no admin perms). 51 52 locale_activate( $locale ); 53 54 if( ! $Settings->get('newusers_canregister') ) 55 { 56 $action = 'disabled'; 57 } 58 59 switch( $action ) 60 { 61 case 'register': 62 /* 63 * Do the registration: 64 */ 65 param( 'pass1', 'string', '' ); 66 param( 'pass2', 'string', '' ); 67 68 // Call plugin event to allow catching input in general and validating own things from DisplayRegisterFormFieldset event 69 $Plugins->trigger_event( 'RegisterFormSent', array( 70 'login' => & $login, 71 'email' => & $email, 72 'locale' => & $locale, 73 'pass1' => & $pass1, 74 'pass2' => & $pass2, 75 ) ); 76 77 if( $Messages->count( 'error' ) ) 78 { // a Plugin has added an error 79 break; 80 } 81 82 // Check profile params: 83 profile_check_params( array( 84 'login' => $login, 85 'pass1' => $pass1, 86 'pass2' => $pass2, 87 'email' => $email, 88 'pass_required' => true ) ); 89 90 // We want all logins to be lowercase to guarantee uniqueness regardless of the database case handling for UNIQUE indexes: 91 $login = strtolower( $login ); 92 93 $UserCache = & get_Cache( 'UserCache' ); 94 if( $UserCache->get_by_login( $login ) ) 95 { // The login is already registered 96 param_error( 'login', sprintf( T_('The login «%s» is already registered, please choose another one.'), $login ) ); 97 } 98 99 if( $Messages->count( 'error' ) ) 100 { 101 break; 102 } 103 104 $DB->begin(); 105 106 $new_User = & new User(); 107 $new_User->set( 'login', $login ); 108 $new_User->set( 'pass', md5($pass1) ); // encrypted 109 $new_User->set( 'nickname', $login ); 110 $new_User->set_email( $email ); 111 $new_User->set( 'ip', $Hit->IP ); 112 $new_User->set( 'domain', $Hit->get_remote_host( true ) ); 113 $new_User->set( 'browser', $Hit->user_agent ); 114 $new_User->set_datecreated( $localtimenow ); 115 $new_User->set( 'locale', $locale ); 116 $newusers_grp_ID = $Settings->get('newusers_grp_ID'); 117 // echo $newusers_grp_ID; 118 $GroupCache = & get_Cache( 'GroupCache' ); 119 $new_user_Group = & $GroupCache->get_by_ID( $newusers_grp_ID ); 120 // echo $new_user_Group->disp('name'); 121 $new_User->set_Group( $new_user_Group ); 122 123 // Determine if the user must validate before using the system: 124 $new_User->set( 'validated', ! $Settings->get('newusers_mustvalidate') ); 125 126 $new_User->dbinsert(); 127 128 $new_user_ID = $new_User->ID; // we need this to "rollback" user creation if there's no DB transaction support 129 130 // TODO: Optionally auto create a blog (handle this together with the LDAP plugin) 131 132 // TODO: Optionally auto assign rights 133 134 // Actions to be appended to the user registration transaction: 135 if( $Plugins->trigger_event_first_false( 'AppendUserRegistrTransact', array( 'User' => & $new_User ) ) ) 136 { 137 // TODO: notify the plugins that have been called before about canceling of the event?! 138 $DB->rollback(); 139 140 // Delete, in case there's no transaction support: 141 $new_User->dbdelete( $Debuglog ); 142 143 $Messages->add( T_('No user account has been created!'), 'error' ); 144 break; // break out to _reg_form.php 145 } 146 147 // User created: 148 $DB->commit(); 149 150 $UserCache->add( $new_User ); 151 152 // Send email to admin (using his locale): 153 /** 154 * @var User 155 */ 156 $AdminUser = & $UserCache->get_by_ID( 1 ); 157 locale_temp_switch( $AdminUser->get( 'locale' ) ); 158 159 $message = T_('New user registration on your blog').":\n" 160 ."\n" 161 .T_('Login:')." $login\n" 162 .T_('Email').": $email\n" 163 ."\n" 164 .T_('Edit user').': '.$admin_url.'?ctrl=users&user_ID='.$new_User->ID."\n"; 165 166 send_mail( $AdminUser->get( 'email' ), T_('New user registration on your blog'), $message, $notify_from ); // ok, if this may fail.. 167 168 locale_restore_previous(); 169 170 $Plugins->trigger_event( 'AfterUserRegistration', array( 'User' => & $new_User ) ); 171 172 173 if( $Settings->get('newusers_mustvalidate') ) 174 { // We want that the user validates his email address: 175 if( $new_User->send_validate_email($redirect_to) ) 176 { 177 $Messages->add( T_('An email has been sent to your email address. Please click on the link therein to validate your account.'), 'success' ); 178 } 179 else 180 { 181 $Messages->add( T_('Sorry, the email with the link to validate and activate your password could not be sent.') 182 .'<br />'.T_('Possible reason: the PHP mail() function may have been disabled on the server.'), 'error' ); 183 // fp> TODO: allow to enter a different email address (just in case it's that kind of problem) 184 } 185 } 186 187 // Autologin the user. This is more comfortable for the user and avoids 188 // extra confusion when account validation is required. 189 $Session->set_User( $new_User ); 190 191 // Display confirmation screen: 192 require $adminskins_path.'login/_reg_complete.main.php'; 193 194 exit(); 195 break; 196 197 198 case 'disabled': 199 /* 200 * Registration disabled: 201 */ 202 require $adminskins_path.'login/_reg_disabled.php'; 203 204 exit(); 205 } 206 207 208 /* 209 * Default: registration form: 210 */ 211 // Display reg form: 212 require $adminskins_path.'login/_reg_form.main.php'; 213 214 215 /* 216 * $Log: register.php,v $ 217 * Revision 1.86 2007/06/25 10:58:50 fplanque 218 * MODULES (refactored MVC) 219 * 220 * Revision 1.85 2007/06/19 23:10:25 blueyed 221 * Better redirect_to handling/fallback 222 * 223 * Revision 1.84 2007/04/26 00:11:14 fplanque 224 * (c) 2007 225 * 226 * Revision 1.83 2007/02/18 20:05:47 blueyed 227 * Use param_error() for "login already exists" error message 228 * 229 * Revision 1.82 2007/02/13 21:03:40 blueyed 230 * Improved login/register/validation process: 231 * - "Your account has been validated already." if an account had already been validated 232 * - "We have already sent you %d email(s) with a validation link." note 233 * - Autologin the user after he has registered (he just typed his credentials!) 234 * 235 * Revision 1.81 2007/01/28 23:58:46 blueyed 236 * - Added hook CommentFormSent 237 * - Re-ordered comment_post.php to: init, validate, process 238 * - RegisterFormSent hook can now filter the form values in a clean way 239 * 240 * Revision 1.80 2007/01/27 19:57:12 blueyed 241 * Use param_error() in profile_check_params() 242 * 243 * Revision 1.79 2007/01/25 22:03:37 blueyed 244 * Move hardcoded "$login_required = false" after include of _main.inc.php, so that it cannot get overridden in main init. There is no use case for this. 245 * 246 * Revision 1.78 2007/01/16 00:44:42 fplanque 247 * don't use $admin_email in the app 248 * 249 * Revision 1.77 2006/12/06 22:30:07 fplanque 250 * Fixed this use case: 251 * Users cannot register themselves. 252 * Admin creates users that are validated by default. (they don't have to validate) 253 * Admin can invalidate a user. (his email, address actually) 254 * 255 * Revision 1.76 2006/11/24 18:27:22 blueyed 256 * Fixed link to b2evo CVS browsing interface in file docblocks 257 * 258 * Revision 1.75 2006/11/19 16:17:37 blueyed 259 * Login cannot be required on the register page 260 * 261 * Revision 1.74 2006/09/10 18:14:24 blueyed 262 * Do report error, if sending email fails in message_send.php (msgform and opt-out) 263 * 264 * Revision 1.73 2006/08/19 08:50:25 fplanque 265 * moved out some more stuff from main 266 * 267 * Revision 1.72 2006/08/19 07:56:29 fplanque 268 * Moved a lot of stuff out of the automatic instanciation in _main.inc 269 * 270 * Revision 1.71 2006/07/17 01:33:13 blueyed 271 * Fixed account validation by email for users who registered themselves 272 * 273 * Revision 1.70 2006/06/18 01:14:03 blueyed 274 * lazy instantiate user's group; normalisation 275 * 276 * Revision 1.69 2006/05/19 18:15:04 blueyed 277 * Merged from v-1-8 branch 278 * 279 * Revision 1.68 2006/05/01 04:21:50 blueyed 280 * todo 281 * 282 * Revision 1.67 2006/04/24 21:01:07 blueyed 283 * just delete 284 * 285 * Revision 1.66 2006/04/24 20:52:30 fplanque 286 * no message 287 * 288 * Revision 1.65 2006/04/24 17:52:24 blueyed 289 * Manually delete user if no transaction-support 290 * 291 * Revision 1.64 2006/04/24 15:43:35 fplanque 292 * no message 293 * 294 * Revision 1.63 2006/04/22 02:36:38 blueyed 295 * Validate users on registration through email link (+cleanup around it) 296 * 297 * Revision 1.62 2006/04/21 17:05:08 blueyed 298 * cleanup 299 * 300 * Revision 1.61 2006/04/20 22:24:07 blueyed 301 * plugin hooks cleanup 302 * 303 * Revision 1.60 2006/04/19 20:13:48 fplanque 304 * do not restrict to :// (does not catch subdomains, not even www.) 305 * 306 * Revision 1.59 2006/04/11 21:22:25 fplanque 307 * partial cleanup 308 * 309 */ 310 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |