webUsers derived from Users, with www dependent functionality to check if username already in use or email already in use

--HG--
branch : quitta-gsoc-2013
This commit is contained in:
Quitta 2013-06-29 05:02:54 +02:00
parent 76e46c9fc4
commit 4034c83382
5 changed files with 69 additions and 35 deletions

View file

@ -10,10 +10,10 @@ class Users{
public function check_Register($values){ public function check_Register($values){
// check values // check values
if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["Email"] ) ){ if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["Email"] ) ){
$user = Users :: checkUser( $values["Username"] ); $user = Users::checkUser( $values["Username"] );
$pass = Users :: checkPassword( $values["Password"] ); $pass = Users::checkPassword( $values["Password"] );
$cpass = Users :: confirmPassword($pass); $cpass = Users::confirmPassword($pass);
$email = Users :: checkEmail( $values["Email"] ); $email = Users::checkEmail( $values["Email"] );
}else{ }else{
$user = ""; $user = "";
$pass = ""; $pass = "";
@ -63,6 +63,9 @@ class Users{
} }
/** /**
* Function checkUser * Function checkUser
* *
@ -80,8 +83,8 @@ class Users{
return "Username can only contain numbers and letters."; return "Username can only contain numbers and letters.";
}else if ( $username == "" ){ }else if ( $username == "" ){
return "You have to fill in a username"; return "You have to fill in a username";
/*}elseif ($this->dbs->execute("SELECT * FROM user WHERE Login = :name",array('name' => $username))->rowCount()){ }elseif ($this->checkUserNameExists($username)){
return "Username " . $username . " is in use.";*/ return "Username " . $username . " is in use.";
}else{ }else{
return "success"; return "success";
} }
@ -90,29 +93,16 @@ class Users{
} }
/** /**
* Function checkUserAlreadyExists * Function checkUserNameExists
* *
* @takes $username * @takes $username
* @return string Info: Returns true or false if the user is in the lib+shard db. * @return string Info: Returns true or false if the user is in the www db.
* */
private function checkUserAlreadyExists( $username ) protected function checkUserNameExists($username){
{ //You should overwrite this method with your own version!
global $cfg; print('this is the base class!');
$dbl = new DBLayer($cfg['db']['lib']);
$dbs = new DBLayer($cfg['db']['shard']);
try{
if ($this->dbl->execute("SELECT * FROM user WHERE Login = :name",array('name' => $username))->rowCount()){
return true;
} }
if ($this->dbs->execute("SELECT * FROM user WHERE Login = :name",array('name' => $username))->rowCount()){
return true;
}
return false;
}catch (PDOException $e) {
//in case one of them is offline let it be hanled lateron with the
return true;
}
}*/
/** /**
@ -172,9 +162,9 @@ class Users{
return "Email address is not valid."; return "Email address is not valid.";
}else if($email == ""){ }else if($email == ""){
return "You have to fill in an email address"; return "You have to fill in an email address";
/*}elseif ( $this->dbs->execute("SELECT * FROM user WHERE Email = :email",array('email' => $email))->rowCount()){ }else if ($this->checkEmailExists($email)){
return "Email is in use.";*/} return "Email is in use.";
else{ }else{
return "success"; return "success";
} }
} }
@ -182,6 +172,18 @@ class Users{
} }
/**
* Function checkEmailExists
*
* @takes $username
* @return string Info: Returns true or false if the user is in the www db.
*/
protected function checkEmailExists($email){
//TODO: You should overwrite this method with your own version!
print('this is the base class!');
}
/** /**
* Function validEmail * Function validEmail

View file

@ -0,0 +1,29 @@
<?php
class WebUsers extends Users{
/**
* Function checkUserNameExists
*
* @takes $username
* @return string Info: Returns true or false if the user is in the web db.
*/
protected function checkUserNameExists($username){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
return $dbw->execute("SELECT * FROM ams_user WHERE Login = :name",array('name' => $username))->rowCount();
}
/**
* Function checkEmailExists
*
* @takes $username
* @return string Info: Returns true or false if the user is in the www db.
*/
protected function checkEmailExists($email){
global $cfg;
$dbw = new DBLayer($cfg['db']['web']);
return $dbw->execute("SELECT * FROM ams_user WHERE Email = :email",array('email' => $email))->rowCount();
}
}

View file

@ -3,7 +3,8 @@
function add_user(){ function add_user(){
$params = Array('Username' => $_POST["Username"], 'Password' => $_POST["Password"], 'Email' => $_POST["Email"]); $params = Array('Username' => $_POST["Username"], 'Password' => $_POST["Password"], 'Email' => $_POST["Email"]);
$result = Users::check_Register($params); $webUser = new WebUsers;
$result = $webUser->check_Register($params);
// if all are good then create user // if all are good then create user
if ( $result == "success"){ if ( $result == "success"){
@ -37,7 +38,7 @@ function add_user(){
function write_user($newUser){ function write_user($newUser){
//create salt here, because we want it to be the same on the web/server //create salt here, because we want it to be the same on the web/server
$hashpass = crypt($newUser["pass"], Users::generateSALT()); $hashpass = crypt($newUser["pass"], WebUsers::generateSALT());
$params = array( $params = array(
'name' => $newUser["name"], 'name' => $newUser["name"],
@ -51,7 +52,7 @@ function write_user($newUser){
//Create the user on the shard + in case shard is offline put copy of query in query db //Create the user on the shard + in case shard is offline put copy of query in query db
//returns: ok, shardoffline or liboffline //returns: ok, shardoffline or liboffline
$result = Users::createUser($values); $result = WebUsers::createUser($values);
try{ try{
//make connection with web db and put it in there //make connection with web db and put it in there

View file

@ -101,13 +101,13 @@
<li><a href="index.php?page=logout">Logout</a></li> <li><a href="index.php?page=logout">Logout</a></li>
</ul> </ul>
</div> </div>
{/if}
<div class="btn-group pull-right"> <div class="btn-group pull-right">
<div class="flags"> <div class="flags">
<img src="img/en.png" onclick="document.cookie='language=en';document.location.reload(true);"/> <img src="img/en.png" onclick="document.cookie='language=en';document.location.reload(true);"/>
<img src="img/fr.png" onclick="document.cookie='language=fr';document.location.reload(true);"/> <img src="img/fr.png" onclick="document.cookie='language=fr';document.location.reload(true);"/>
</div> </div>
</div> </div>
{/if}
<!-- user dropdown ends --> <!-- user dropdown ends -->
</div> </div>
</div> </div>
@ -245,6 +245,7 @@
<script src="js/charisma.js"></script> <script src="js/charisma.js"></script>
<!-- help script for page help --> <!-- help script for page help -->
<script src="js/help.js"></script> <script src="js/help.js"></script>
</div> </div>
</body> </body>
</html> </html>

View file

@ -13,6 +13,7 @@
</div> </div>
<div class="box-content"> <div class="box-content">
<p><strong>The shard/lib/web db user list</strong> You are about to see it here!</p> <p><strong>The shard/lib/web db user list</strong> You are about to see it here!</p>
<div id='test1'> lolbol</div>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>