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

This commit is contained in:
Quitta 2013-06-29 05:02:54 +02:00
parent 6df401280a
commit 193a5843b0
5 changed files with 69 additions and 35 deletions

View file

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

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(){
$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 ( $result == "success"){
@ -37,7 +38,7 @@ function add_user(){
function write_user($newUser){
//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(
'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
//returns: ok, shardoffline or liboffline
$result = Users::createUser($values);
$result = WebUsers::createUser($values);
try{
//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>
</ul>
</div>
{/if}
<div class="btn-group pull-right">
<div class="flags">
<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);"/>
</div>
</div>
{/if}
<!-- user dropdown ends -->
</div>
</div>
@ -245,6 +245,7 @@
<script src="js/charisma.js"></script>
<!-- help script for page help -->
<script src="js/help.js"></script>
</div>
</body>
</html>

View file

@ -13,6 +13,7 @@
</div>
<div class="box-content">
<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>