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
|
<?php
/**
* Register a new user
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package htsrv
*/
/**
* Includes:
*/
require_once( dirname(__FILE__).'/../conf/_config.php' );
require_once( dirname(__FILE__)."/$htsrv_dirout/$core_subdir/_main.php" );
param( 'action', 'string', '' );
param( 'login', 'string', '' );
param( 'email', 'string', '' );
param( 'locale', 'string', $Settings->get('default_locale') );
locale_activate( $locale );
if(!$Settings->get('newusers_canregister'))
{
$action = 'disabled';
}
switch( $action )
{
case 'register':
/*
* Do the registration:
*/
param( 'redirect_to', 'string', $admin_url.'/b2edit.php' );
param( 'pass1', 'string', '' );
param( 'pass2', 'string', '' );
// checking login has been typed:
if( $login == '' )
{
$error = '<strong>'.T_('ERROR').'</strong>: '.T_('please enter a Login');
break;
}
// checking the password has been typed twice
if( $pass1 == '' || $pass2 == '' )
{
$error = '<strong>'.T_('ERROR').'</strong>: '.T_('please enter your password twice');
break;
}
// checking the password has been typed twice the same:
if( $pass1 != $pass2 )
{
$error = '<strong>'.T_('ERROR').'</strong>: '.T_('please type the same password in the two password fields');
break;
}
// checking password length
if( strlen($pass1) < $Settings->get('user_minpwdlen') )
{
$error = sprintf( T_('The mimimum password length is %d characters.'), $Settings->get('user_minpwdlen'));
break;
}
$user_nickname = $login;
// checking e-mail address:
if($email == '')
{
$error = '<strong>'.T_('ERROR').'</strong>: '.T_('please type your e-mail address');
break;
}
elseif (!is_email($email))
{
$error = '<strong>'.T_('ERROR').'</strong>: '.T_('the email address is invalid');
break;
}
// TODO: START TRANSACTION !!
// checking the login isn't already used by another user:
if( $DB->get_var( "SELECT count(*)
FROM $tableusers
WHERE user_login = '".$DB->escape($login)."'" ) )
{
$error = '<strong>'. T_('ERROR'). "</strong>: ". T_('this login is already registered, please choose another one');
break;
}
$new_User = & new User();
$new_User->set( 'login', $login );
$new_User->set( 'pass', md5($pass1) ); // encrypted
$new_User->set( 'nickname', $user_nickname );
$new_User->set( 'email', $email );
$new_User->set( 'ip', '127.0.0.1' );
$new_User->set( 'domain', 'localhost' );
$new_User->set( 'ip', isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '' );
$new_User->set( 'domain', isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : '' );
$new_User->set( 'browser', isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '' );
$new_User->set_datecreated( $localtimenow );
$new_User->set( 'level', $Settings->get('newusers_level') );
$new_User->set( 'locale', $locale );
$newusers_grp_ID = $Settings->get('newusers_grp_ID');
// echo $newusers_grp_ID;
$new_user_Group = $GroupCache->get_by_ID( $newusers_grp_ID );
// echo $new_user_Group->disp('name');
$new_User->setGroup( $new_user_Group );
$new_User->dbinsert();
// TODO: END TRANSACTION !!
// switch to admins locale
$admin_data = get_userdata(1);
locale_temp_switch( $admin_data['user_locale'] );
$message = T_('new user registration on your blog'). ":\n\n";
$message .= T_('Login:'). " $login\n\n". T_('Email'). ": $email\n\n";
$message .= T_('Manage users'). ": $admin_url/b2users.php\n\n";
send_mail( $admin_email, T_('new user registration on your blog'), $message, $notify_from );
locale_restore_previous();
// Display confirmation screen:
require( dirname(__FILE__).'/_reg_complete.php' );
exit();
break; // case 'register'
case 'disabled':
/*
* Registration disabled:
*/
require( dirname(__FILE__).'/_reg_disabled.php' );
exit();
break; // case 'disabled'
} // switch
/*
* Default: registration form:
*/
param( 'redirect_to', 'string', $admin_url.'/b2edit.php' );
// Display reg form:
require( dirname(__FILE__).'/_reg_form.php' );
?>
|