updated template for registration and setting up add_user functions

--HG--
branch : rc-botanic-webdev
This commit is contained in:
Botanic 2013-06-07 04:05:28 -07:00
parent 40ba525e5a
commit 3e2278d692
7 changed files with 280 additions and 220 deletions

View file

@ -10,7 +10,7 @@ class Helpers{
$smarty = new Smarty; $smarty = new Smarty;
// turn smarty debugging on/off // turn smarty debugging on/off
$smarty -> debugging = false; $smarty -> debugging = true;
// caching must be disabled for multi-language support // caching must be disabled for multi-language support
$smarty -> caching = false; $smarty -> caching = false;
$smarty -> cache_lifetime = 120; $smarty -> cache_lifetime = 120;

View file

@ -1,180 +1,232 @@
<?php <?php
class Users { class Users{
/** function add_user(){
* // check if values exist
* Function checkUser if ( isset( $_POST["Username"] ) and isset( $_POST["Password"] ) and isset( $_POST["Email"] ) )
* {
* @takes $username // check values
* @return string $user = Users :: checkUser( $_POST["Username"] );
* $pass = Users :: checkPassword( $_POST["Password"] );
* Info: Returns a string based on if the username is valid, if valid then "success" is returned $cpass = Users :: confirmPassword();
* $email = Users :: checkEmail( $_POST["Email"] );
*/ }else{
public function checkUser($username) $user = "";
{ $pass = "";
if (isset($username)) { $cpass = "";
if (strlen($username) > 12) { $email = "";
return "Username must be no more than 12 characters."; }
} elseif (strlen($username) < 5) { // if all are good then create user
return "Username must be 5 or more characters."; if ( ( $user == "success" ) and ( $pass == "success" ) and ( $cpass == "success" ) and ( $email == "success" ) and ( isset( $_POST["TaC"] ) ) ){
} elseif (!preg_match('/^[a-z0-9\.]*$/', $username)) { $edit = array(
return "Username can only contain numbers and letters."; 'name' => $_POST["Username"],
} elseif (sql::db_query("SELECT COUNT(*) FROM {users} WHERE name = :name", array( 'pass' => $_POST["Password"],
':name' => $username 'mail' => $_POST["Email"],
))->fetchField()) { 'init' => $_POST["Email"],
return "Username " . $username . " is in use."; 'unhashpass' => $_POST["Password"],
} else { 'status' => 1,
return "success"; 'access' => REQUEST_TIME
} );
} else { user_save( NULL, $edit );
return "success"; header( 'Location: email_sent.php' );
} exit;
return "fail"; }else{
} $pageElements = array(
/** 'GAME_NAME' => variable_get( 'ryzommanage_game-name', '' ),
* 'WELCOME_MESSAGE' => variable_get( 'ryzommanage_register-welcome', '' ),
* Function checkPassword 'USERNAME' => $user,
* 'PASSWORD' => $pass,
* @takes $pass 'CPASSWORD' => $cpass,
* @return string 'EMAIL' => $email
* );
* Info: Returns a string based on if the password is valid, if valid then "success" is returned if ( $user != "success" ){
* $pageElements['USERNAME_ERROR'] = 'TRUE';
*/ }else{
public function checkPassword($pass) $pageElements['USERNAME_ERROR'] = 'FALSE';
{ }
if (isset($pass)) {
if (strlen($pass) > 20) { if ( $pass != "success" ){
return "Password must be no more than 20 characters."; $pageElements['PASSWORD_ERROR'] = 'TRUE';
} elseif (strlen($pass) < 5) { }else{
return "Password must be more than 5 characters."; $pageElements['PASSWORD_ERROR'] = 'FALSE';
} else { }
return "success"; if ( $cpass != "success" ){
} $pageElements['CPASSWORD_ERROR'] = 'TRUE';
} }else{
return "fail"; $pageElements['CPASSWORD_ERROR'] = 'FALSE';
} }
/** if ( $email != "success" ){
* $pageElements['EMAIL_ERROR'] = 'TRUE';
* Function confirmPassword }else{
* $pageElements['EMAIL_ERROR'] = 'FALSE';
* @takes $pass }
* @return string if ( isset( $_POST["TaC"] ) ){
* $pageElements['TAC_ERROR'] = 'FALSE';
* Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"] }else{
* $pageElements['TAC_ERROR'] = 'TRUE';
*/ }
public function confirmPassword() return $pageElements;
{ }
if (($_POST["Password"]) != ($_POST["ConfirmPass"])) {
return "Passwords do not match."; /**
} else { * Function checkUser
return "success"; *
} * @takes $username
return "fail"; * @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
} */
/** public function checkUser( $username )
* {
* Function checkEmail if ( isset( $username ) ){
* if ( strlen( $username ) > 12 ){
* @takes $email return "Username must be no more than 12 characters.";
* @return }elseif ( strlen( $username ) < 5 ){
* return "Username must be 5 or more characters.";
* }elseif ( !preg_match( '/^[a-z0-9\.]*$/', $username ) ){
* return "Username can only contain numbers and letters.";
*/ }elseif ( sql :: db_query( "SELECT COUNT(*) FROM {users} WHERE name = :name", array(
public function checkEmail($email) ':name' => $username
{ ) ) -> fetchField() ){
if (isset($email)) { return "Username " . $username . " is in use.";
if (!validEmail($email)) { }else{
return "Email address is not valid."; return "success";
} elseif (db_query("SELECT COUNT(*) FROM {users} WHERE mail = :mail", array( }
':mail' => $email }else{
))->fetchField()) { return "success";
return "Email is in use."; }
} else { return "fail";
return "success"; }
} /**
} else { * Function checkPassword
return "success"; *
} * @takes $pass
return "fail"; * @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
} */
public function validEmail($email) public function checkPassword( $pass )
{ {
$isValid = true; if ( isset( $pass ) ){
$atIndex = strrpos($email, "@"); if ( strlen( $pass ) > 20 ){
if (is_bool($atIndex) && !$atIndex) { return "Password must be no more than 20 characters.";
$isValid = false; }elseif ( strlen( $pass ) < 5 ){
} else { return "Password must be more than 5 characters.";
$domain = substr($email, $atIndex + 1); }else{
$local = substr($email, 0, $atIndex); return "success";
$localLen = strlen($local); }
$domainLen = strlen($domain); }
if ($localLen < 1 || $localLen > 64) { return "fail";
// local part length exceeded }
$isValid = false; /**
} else if ($domainLen < 1 || $domainLen > 255) { * Function confirmPassword
// domain part length exceeded *
$isValid = false; * @takes $pass
} else if ($local[0] == '.' || $local[$localLen - 1] == '.') { * @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"]
// local part starts or ends with '.' */
$isValid = false; public function confirmPassword()
} else if (preg_match('/\\.\\./', $local)) { {
// local part has two consecutive dots if ( ( $_POST["Password"] ) != ( $_POST["ConfirmPass"] ) ){
$isValid = false; return "Passwords do not match.";
} else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { }else{
// character not valid in domain part return "success";
$isValid = false; }
} else if (preg_match('/\\.\\./', $domain)) { return "fail";
// domain part has two consecutive dots }
$isValid = false; /**
} else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) { * Function checkEmail
// character not valid in local part unless *
// local part is quoted * @takes $email
if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) { * @return
$isValid = false; */
public function checkEmail( $email )
{
if ( isset( $email ) ){
if ( !validEmail( $email ) ){
return "Email address is not valid.";
}elseif ( db_query( "SELECT COUNT(*) FROM {users} WHERE mail = :mail", array(
':mail' => $email
) ) -> fetchField() ){
return "Email is in use.";
}else{
return "success";
}
}else{
return "success";
}
return "fail";
}
public function validEmail( $email )
{
$isValid = true;
$atIndex = strrpos( $email, "@" );
if ( is_bool( $atIndex ) && !$atIndex ){
$isValid = false;
}else{
$domain = substr( $email, $atIndex + 1 );
$local = substr( $email, 0, $atIndex );
$localLen = strlen( $local );
$domainLen = strlen( $domain );
if ( $localLen < 1 || $localLen > 64 ){
// local part length exceeded
$isValid = false;
}else if ( $domainLen < 1 || $domainLen > 255 ){
// domain part length exceeded
$isValid = false;
}else if ( $local[0] == '.' || $local[$localLen - 1] == '.' ){
// local part starts or ends with '.'
$isValid = false;
}else if ( preg_match( '/\\.\\./', $local ) ){
// local part has two consecutive dots
$isValid = false;
}else if ( !preg_match( '/^[A-Za-z0-9\\-\\.]+$/', $domain ) ){
// character not valid in domain part
$isValid = false;
}else if ( preg_match( '/\\.\\./', $domain ) ){
// domain part has two consecutive dots
$isValid = false;
}else if ( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace( "\\\\", "", $local ) ) ){
// character not valid in local part unless
// local part is quoted
if ( !preg_match( '/^"(\\\\"|[^"])+"$/', str_replace( "\\\\", "", $local ) ) ){
$isValid = false;
}
}
if ( $isValid && !( checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ) ) ){
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}
public function generateSALT( $length = 2 )
{
// start with a blank salt
$salt = "";
// define possible characters - any character in this string can be
// picked for use in the salt, so if you want to put vowels back in
// or add special characters such as exclamation marks, this is where
// you should do it
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
// we refer to the length of $possible a few times, so let's grab it now
$maxlength = strlen( $possible );
// check for length overflow and truncate if necessary
if ( $length > $maxlength ){
$length = $maxlength;
}
// set up a counter for how many characters are in the salt so far
$i = 0;
// add random characters to $salt until $length is reached
while ( $i < $length ){
// pick a random character from the possible ones
$char = substr( $possible, mt_rand( 0, $maxlength - 1 ), 1 );
// have we already used this character in $salt?
if ( !strstr( $salt, $char ) ){
// no, so it's OK to add it onto the end of whatever we've already got...
$salt .= $char;
// ... and increase the counter by one
$i++;
}
}
// done!
return $salt;
} }
} }
if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain, "A"))) {
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}
public function generateSALT($length = 2)
{
// start with a blank salt
$salt = "";
// define possible characters - any character in this string can be
// picked for use in the salt, so if you want to put vowels back in
// or add special characters such as exclamation marks, this is where
// you should do it
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
// we refer to the length of $possible a few times, so let's grab it now
$maxlength = strlen($possible);
// check for length overflow and truncate if necessary
if ($length > $maxlength) {
$length = $maxlength;
}
// set up a counter for how many characters are in the salt so far
$i = 0;
// add random characters to $salt until $length is reached
while ($i < $length) {
// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, $maxlength - 1), 1);
// have we already used this character in $salt?
if (!strstr($salt, $char)) {
// no, so it's OK to add it onto the end of whatever we've already got...
$salt .= $char;
// ... and increase the counter by one
$i++;
}
}
// done!
return $salt;
}
}

View file

@ -27,7 +27,7 @@
</tr> </tr>
<tr> <tr>
<td width="33%" <?php if ($PASSWORD_ERROR == "TRUE"){ echo 'class="error"';}?> id="caption-Password">Desired Password:</td> <td width="33%" {if isset($PASSWORD_ERROR) && $PASSWORD_ERROR eq "TRUE"}class="error"{/if} id="caption-Password">{$password_tag}</td>
<td width="25%"> <td width="25%">
<input type="password" <input type="password"
@ -36,27 +36,27 @@
maxlength="20" maxlength="20"
onkeyup= onkeyup=
"testPassword(document.Page1.Password.value, 'comment-Password')" "testPassword(document.Page1.Password.value, 'comment-Password')"
onfocus="javascript:showTooltip(' 5-20 characters.', this);" /> onfocus="javascript:showTooltip('{$password_message}', this);" />
</td> </td>
<td id="comment-Password" <?php if ($PASSWORD_ERROR == "TRUE"){ echo 'class="error"';}?> width="42%"><?php if ($PASSWORD_ERROR == "TRUE"){ echo $PASSWORD;}?></td> <td id="comment-Password" {if isset($PASSWORD_ERROR) && $PASSWORD_ERROR eq "TRUE"}class="error"{/if} width="42%">{if isset($PASSWORD_ERROR) && $PASSWORD_ERROR eq "TRUE"}{$Password}{/if}</td>
</tr> </tr>
<tr> <tr>
<td width="33%"<?php if ($CPASSWORD_ERROR == "TRUE"){ echo 'class="error"';}?> id="caption-ConfirmPass">Confirm Password:</td> <td width="33%" {if isset($CPASSWORD_ERROR) && $CPASSWORD_ERROR eq "TRUE"}class="error"{/if} id="caption-ConfirmPass">{$cpassword_tag}</td>
<td width="25%"><input type="password" <td width="25%"><input type="password"
name="ConfirmPass" name="ConfirmPass"
value="" value=""
maxlength="20" maxlength="20"
onfocus="javascript:showTooltip('Retype your Password', this);" /> onfocus="javascript:showTooltip('{$cpassword_message}', this);" />
</td> </td>
<td id="comment-ConfirmPass" <?php if ($CPASSWORD_ERROR == "TRUE"){ echo 'class="error"';}?>width="42%"><?php if ($CPASSWORD_ERROR == "TRUE"){ echo $CPASSWORD;}?></td> <td id="comment-ConfirmPass" {if isset($CPASSWORD_ERROR) && $CPASSWORD_ERROR eq "TRUE"}class="error"{/if} width="42%">{if isset($CPASSWORD_ERROR) && $CPASSWORD_ERROR eq "TRUE"}{$ConfirmPass}{/if}</td>
</tr> </tr>
<tr> <tr>
<td width="33%" <?php if ($EMAIL_ERROR == "TRUE"){ echo 'class="error"';}?> id="caption-Email">Email Address (to which a confirmation email will be sent):</td> <td width="33%" {if isset($CPASSWORD_ERROR) && $CPASSWORD_ERROR eq "TRUE"}class="error"{/if} id="caption-Email">{$email_tag}</td>
<td width="25%"> <td width="25%">
<input type="text" <input type="text"
@ -64,24 +64,22 @@
value="" value=""
maxlength="255" maxlength="255"
onfocus= onfocus=
"javascript:showTooltip('Please verify that the e-mail address you enter here is valid and will remain valid in the future. It will only be used to manage your <?php echo $GAME_NAME; ?> account.', this);" /> "javascript:showTooltip('{$email_message}', this);" />
</td> </td>
<td id="comment-Email" <?php if ($EMAIL_ERROR == "TRUE"){ echo 'class="error"';}?> width="42%"><?php if ($EMAIL_ERROR == "TRUE"){ echo $EMAIL;}?></td> <td id="comment-Email" {if isset($EMAIL_ERROR) && $EMAIL_ERROR eq "TRUE"}class="error"{/if} width="42%">{if isset($EMAIL_ERROR) && $EMAIL_ERROR eq "TRUE"}{$Email}{/if}</td>
</tr> </tr>
<tr> <tr>
<td width= <td width=
"33%" <?php if ($TAC_ERROR == "TRUE"){ echo 'class="error"';}?> "33%" {if isset($TAC_ERROR) && $TAC_ERROR eq "TRUE"}class="error"{/if}
colspan="2"><input type="checkbox" colspan="2"><input type="checkbox"
name="TaC" name="TaC"
value="1" value="1"
onfocus="javascript:showTooltip('', this);" /><span id= onfocus="javascript:showTooltip('', this);" /><span id=
"caption-TaC">YES, I agree to the terms of "caption-TaC">{$tac_tag}</span></td>
service</span></td><?php if ($TAC_ERROR == "TRUE"){ <td id="comment-TaC" {if isset($TAC_ERROR) && $TAC_ERROR eq "TRUE"}class="error"{/if} width="42%">{$tac_message}</td>
echo '<td id="comment-TaC" class="error" width="42%">You must accept the Terms of Service</td>';}
else {
echo '<td width="42%" id="comment-TaC" >';}; ?>
</tr> </tr>
</table> </table>
@ -98,22 +96,20 @@
inset=""></div> inset=""></div>
<div id="tooltip-Username"> <div id="tooltip-Username">
5-12 lower-case characters and numbers. The login (username) you create here will be {$username_tooltip}
your login name. The name of your game characters will be chosen later on.
</div> </div>
<div id="tooltip-Password"> <div id="tooltip-Password">
5-20 characters. {$password_message}
</div> </div>
<div id="tooltip-ConfirmPass"> <div id="tooltip-ConfirmPass">
Retype your Password {$cpassword_message}
</div> </div>
<div id="tooltip-Email"> <div id="tooltip-Email">
Please verify that the e-mail address you enter here is valid and will remain valid {$email_message}
in the future. It will be used to manage your <?php echo $GAME_NAME; ?> account.
</div> </div>
<div id="tooltip-TaC"></div> <div id="tooltip-TaC"></div>

View file

@ -4,5 +4,19 @@
[register] [register]
title = "RYZOM CORE INGAME REGISTRATION" title = "RYZOM CORE INGAME REGISTRATION"
welcome_message = "Welcome! Please fill in the following fields to get your new Ryzom Core account:" welcome_message = "Welcome! Please fill in the following fields to get your new Ryzom Core account:"
username_tag = "Desired Username:" username_tag = "Desired Username:"
username_tooltip = "5-12 lower-case characters and numbers. The login (username) you create here will be your login name. The name of your game characters will be chosen later on." username_tooltip = "5-12 lower-case characters and numbers. The login (username) you create here will be your login name. The name of your game characters will be chosen later on."
password_tag = "Desired Password:"
password_message = "Password must be 5-20 characters."
cpassword_tag = "Confirm Password:"
cpassword_message = "Retype your Password"
email_tag = "Email Address (to which a confirmation email will be sent):"
email_message = "Please verify that the e-mail address you enter here is valid and will remain valid in the future. It will only be used to manage your Ryzom Core account."
tac_tag = "YES, I agree to the terms of service."
tac_message = "You must accept the Terms of Service."

View file

@ -17,9 +17,7 @@ $DBHOST = 'localhost' ;
$NTDBName = 'nel_tool' ; $NTDBName = 'nel_tool' ;
$NTUserName = 'shard' ; $NTUserName = 'shard' ;
$NTPassword = '' ; $NTPassword = '' ;
$SITETITLE = 'Ryzom Core AMS' ;
$LOGRELATIVEPATH = 'logs/' ; $LOGRELATIVEPATH = 'logs/' ;
// If true= the server will add automatically unknown user in the database // If true= the server will add automatically unknown user in the database
@ -82,6 +80,4 @@ $NELDB_CONFIG_TABLE = $NELDB_PREFIX . 'config';
$LOCK_TIMEOUT = 1800 ; $LOCK_TIMEOUT = 1800 ;
$BG_IMG = 'imgs/bg_live.png' ; $BG_IMG = 'imgs/bg_live.png' ;
$DEFAULT_LANGUAGE = 'en'; $DEFAULT_LANGUAGE = 'en';
$TEMPLATE_DIR = "";

View file

@ -1,6 +1,10 @@
<?php <?php
function add_user(){ function add_user(){
echo "test";
//add user locally here
$return = users::add_user();
return $return;
} }
function checkUser(){ function checkUser(){

View file

@ -3,20 +3,18 @@
require( '../config.php' ); require( '../config.php' );
require( '../../ams_lib/libinclude.php' ); require( '../../ams_lib/libinclude.php' );
if (isset($_POST["function"])){ if ( isset( $_POST["function"] ) ){
require("inc/".$_POST["function"].".php"); require( "inc/" . $_POST["function"] . ".php" );
$_POST["function"](); $return = $_POST["function"]();
} }
function loadpage ($page){ function loadpage ( $page ){
require_once('autoload/'.$page.'.php'); require_once( 'autoload/' . $page . '.php' );
} }
$page = 'home'; $page = 'home';
if (isset($_GET["page"])) { if ( isset( $_GET["page"] ) ){
$page = $_GET["page"]; $page = $_GET["page"];
} }
$pageElements = array();
$pageElements['USERNAME_ERROR'] = 'TRUE'; helpers :: loadTemplate( 'register' , $return );
$pageElements['Username'] = 'testuser';
helpers::loadTemplate( 'register' , $pageElements);