From fb622a9eb73df51d536235e8be3817e07acce35a Mon Sep 17 00:00:00 2001 From: Quitta Date: Wed, 19 Jun 2013 06:50:08 +0200 Subject: [PATCH] register refactoring + small bug fixes that went unnoticed before --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/users.php | 88 ++++++++++++++++--- .../ryzom_ams/www/html/inc/add_user.php | 88 +++++-------------- .../ryzom_ams/www/html/templates/register.tpl | 10 +-- 3 files changed, 107 insertions(+), 79 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index 2d28119f7..69dd98ccc 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -6,6 +6,62 @@ class Users{ helpers :: loadtemplate( 'register', $pageElements ); } + + public function check_Register(){ + // check values + if ( isset( $_POST["Username"] ) and isset( $_POST["Password"] ) and isset( $_POST["Email"] ) ){ + $user = Users :: checkUser( $_POST["Username"] ); + $pass = Users :: checkPassword( $_POST["Password"] ); + $cpass = Users :: confirmPassword($pass); + $email = Users :: checkEmail( $_POST["Email"] ); + }else{ + $user = ""; + $pass = ""; + $cpass = ""; + $email = ""; + } + + if ( ( $user == "success" ) and ( $pass == "success" ) and ( $cpass == "success" ) and ( $email == "success" ) and ( isset( $_POST["TaC"] ) ) ){ + return "success"; + }else{ + $pageElements = array( + //'GAME_NAME' => $GAME_NAME, + // 'WELCOME_MESSAGE' => $WELCOME_MESSAGE, + 'USERNAME' => $user, + 'PASSWORD' => $pass, + 'CPASSWORD' => $cpass, + 'EMAIL' => $email + ); + if ( $user != "success" ){ + $pageElements['USERNAME_ERROR'] = 'TRUE'; + }else{ + $pageElements['USERNAME_ERROR'] = 'FALSE'; + } + + if ( $pass != "success" ){ + $pageElements['PASSWORD_ERROR'] = 'TRUE'; + }else{ + $pageElements['PASSWORD_ERROR'] = 'FALSE'; + } + if ( $cpass != "success" ){ + $pageElements['CPASSWORD_ERROR'] = 'TRUE'; + }else{ + $pageElements['CPASSWORD_ERROR'] = 'FALSE'; + } + if ( $email != "success" ){ + $pageElements['EMAIL_ERROR'] = 'TRUE'; + }else{ + $pageElements['EMAIL_ERROR'] = 'FALSE'; + } + if ( isset( $_POST["TaC"] ) ){ + $pageElements['TAC_ERROR'] = 'FALSE'; + }else{ + $pageElements['TAC_ERROR'] = 'TRUE'; + } + return $pageElements; + } + + } /** * Function checkUser @@ -22,6 +78,9 @@ class Users{ return "Username must be 5 or more characters."; }elseif ( !preg_match( '/^[a-z0-9\.]*$/', $username ) ){ return "Username can only contain numbers and letters."; + }elseif ( $username == "" ){ + return "You have to fill in a username"; + /*}elseif ( sql :: db_query( "SELECT COUNT(*) FROM {users} WHERE name = :name", array( ':name' => $username ) ) -> fetchField() ){ @@ -47,6 +106,8 @@ class Users{ return "Password must be no more than 20 characters."; }elseif ( strlen( $pass ) < 5 ){ return "Password must be more than 5 characters."; + }elseif ( $pass == ""){ + return "You have to fill in a password"; }else{ return "success"; } @@ -59,15 +120,19 @@ class Users{ * @takes $pass * @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"] */ - public function confirmPassword() + public function confirmPassword($pass_result) { - if ( ( $_POST["Password"] ) != ( $_POST["ConfirmPass"] ) ){ + if ( ( $_POST["Password"] ) != ( $_POST["ConfirmPass"] ) ){ return "Passwords do not match."; - }else{ + }else if ($_POST["ConfirmPass"]==""){ + return "You have to fill in the confirmation password."; + }else if($pass_result != "success"){ + return; + }else{ return "success"; - } - return "fail"; - } + } + return "fail"; + } /** * Function checkEmail * @@ -77,13 +142,16 @@ class Users{ public function checkEmail( $email ) { if ( isset( $email ) ){ - if ( !Users::validEmail( $email ) ){ - return "Email address is not valid."; + if ( !Users::validEmail( $email ) ){ + return "Email address is not valid."; + }else if($email == ""){ + return "You have to fill in an email address"; + } /*}elseif ( db_query( "SELECT COUNT(*) FROM {users} WHERE mail = :mail", array( ':mail' => $email ) ) -> fetchField() ){ - return "Email is in use.";*/ - }else{ + return "Email is in use.";}*/ + else{ return "success"; } }else{ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php index f0611058e..da92e14f9 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php @@ -1,70 +1,30 @@ $_POST["Username"], - 'pass' => $_POST["Password"], - 'mail' => $_POST["Email"], - 'init' => $_POST["Email"], - 'unhashpass' => $_POST["Password"], - 'status' => 1, - 'access' => REQUEST_TIME - ); - header( 'Location: email_sent.php' ); - write_user( $edit ); - exit; + $result = Users :: check_Register(); + //print_r($result); + // if all are good then create user + if ( $result == "success"){ + $edit = array( + 'name' => $_POST["Username"], + 'pass' => $_POST["Password"], + 'mail' => $_POST["Email"], + 'init' => $_POST["Email"], + 'unhashpass' => $_POST["Password"], + 'status' => 1, + 'access' => REQUEST_TIME + ); + //header( 'Location: email_sent.php' ); + write_user( $edit ); + exit; }else{ - $pageElements = array( - //'GAME_NAME' => $GAME_NAME, - // 'WELCOME_MESSAGE' => $WELCOME_MESSAGE, - // 'USERNAME' => $user, - // 'PASSWORD' => $pass, - // 'CPASSWORD' => $cpass, - // 'EMAIL' => $email - ); - if ( $user != "success" ){ - $pageElements['USERNAME_ERROR'] = 'TRUE'; - }else{ - $pageElements['USERNAME_ERROR'] = 'FALSE'; - } - - if ( $pass != "success" ){ - $pageElements['PASSWORD_ERROR'] = 'TRUE'; - }else{ - $pageElements['PASSWORD_ERROR'] = 'FALSE'; - } - if ( $cpass != "success" ){ - $pageElements['CPASSWORD_ERROR'] = 'TRUE'; - }else{ - $pageElements['CPASSWORD_ERROR'] = 'FALSE'; - } - if ( $email != "success" ){ - $pageElements['EMAIL_ERROR'] = 'TRUE'; - }else{ - $pageElements['EMAIL_ERROR'] = 'FALSE'; - } - if ( isset( $_POST["TaC"] ) ){ - $pageElements['TAC_ERROR'] = 'FALSE'; - }else{ - $pageElements['TAC_ERROR'] = 'TRUE'; - } - helpers :: loadtemplate( 'register', $pageElements ); + // pass error + $result['prevUsername'] = $_POST["Username"]; + $result['prevPassword'] = $_POST["Password"]; + $result['prevConfirmPass'] = $_POST["ConfirmPass"]; + $result['prevEmail'] = $_POST["Email"]; + $result['no_visible_elements'] = 'TRUE'; + helpers :: loadtemplate( 'register', $result); } } @@ -73,6 +33,6 @@ function write_user(){ // add user locally here - users :: add_user(); + print('Awesome'); } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl index 2ebdd67a9..bd5e92788 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl @@ -21,7 +21,7 @@
- +
@@ -33,7 +33,7 @@
- +
@@ -44,7 +44,7 @@
- +
@@ -55,7 +55,7 @@
- +
@@ -84,7 +84,7 @@ {/if} - {if isset($CPASSWORD_ERROR) and $CPASSWORD_ERROR eq "TRUE"} + {if isset($CPASSWORD_ERROR) and $CPASSWORD_ERROR eq "TRUE" and $CPASSWORD != ""}
Confirmation Password Error {$CPASSWORD}