2013-06-29 03:02:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class WebUsers extends Users{
|
2013-08-05 15:31:36 +00:00
|
|
|
|
|
|
|
private $uId;
|
|
|
|
private $login;
|
|
|
|
private $email;
|
|
|
|
private $firstname;
|
|
|
|
private $lastname;
|
|
|
|
private $gender;
|
|
|
|
private $country;
|
|
|
|
|
|
|
|
function __construct($UId = 0) {
|
|
|
|
$this->uId = $UId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set($values){
|
|
|
|
$this->uId = $values['UId'];
|
|
|
|
$this->login = $values['Login'];
|
|
|
|
$this->email = $values['Email'];
|
|
|
|
$this->firstname = $values['FirstName'];
|
|
|
|
$this->lastname = $values['LastName'];
|
|
|
|
$this->gender = $values['Gender'];
|
|
|
|
$this->country = $values['Country'];
|
|
|
|
}
|
2013-06-29 03:02:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function checkUserNameExists
|
|
|
|
*
|
|
|
|
* @takes $username
|
|
|
|
* @return string Info: Returns true or false if the user is in the web db.
|
|
|
|
*/
|
|
|
|
protected function checkUserNameExists($username){
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbw = new DBLayer("web");
|
2013-06-29 03:02:54 +00:00
|
|
|
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){
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbw = new DBLayer("web");
|
2013-06-29 03:02:54 +00:00
|
|
|
return $dbw->execute("SELECT * FROM ams_user WHERE Email = :email",array('email' => $email))->rowCount();
|
|
|
|
}
|
2013-07-01 16:28:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function checkUserPassMatch
|
|
|
|
*
|
|
|
|
* @takes $username,$password
|
|
|
|
* @return string Info: Returns true or false if a login match is found in the web db
|
|
|
|
*/
|
|
|
|
public function checkLoginMatch($username,$password){
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbw = new DBLayer("web");
|
2013-07-01 16:28:37 +00:00
|
|
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username));
|
|
|
|
$row = $statement->fetch();
|
|
|
|
|
|
|
|
$salt = substr($row['Password'],0,2);
|
|
|
|
$hashed_input_pass = crypt($password, $salt);
|
|
|
|
if($hashed_input_pass == $row['Password']){
|
|
|
|
return $row;
|
|
|
|
}else{
|
|
|
|
return "fail";
|
|
|
|
}
|
|
|
|
}
|
2013-08-12 21:56:58 +00:00
|
|
|
|
|
|
|
//returns te id for a given username
|
|
|
|
public static function getId($username){
|
|
|
|
$dbw = new DBLayer("web");
|
|
|
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
|
|
|
|
$row = $statement->fetch();
|
|
|
|
return $row['UId'];
|
|
|
|
}
|
|
|
|
|
|
|
|
//returns te id for a given username
|
|
|
|
public static function getIdFromEmail($email){
|
|
|
|
$dbw = new DBLayer("web");
|
|
|
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email));
|
|
|
|
$row = $statement->fetch();
|
2013-08-17 17:07:00 +00:00
|
|
|
if(!empty($row)){
|
|
|
|
print "shouldn't be here!" . $row . "seee";
|
|
|
|
|
2013-08-17 01:06:22 +00:00
|
|
|
return $row['UId'];
|
|
|
|
}else{
|
|
|
|
return "FALSE";
|
|
|
|
}
|
2013-08-12 21:56:58 +00:00
|
|
|
}
|
2013-07-06 16:27:25 +00:00
|
|
|
|
2013-08-05 19:12:58 +00:00
|
|
|
public function getUId(){
|
|
|
|
return $this->uId;
|
|
|
|
}
|
|
|
|
|
2013-08-05 15:31:36 +00:00
|
|
|
public function getUsername(){
|
|
|
|
$dbw = new DBLayer("web");
|
|
|
|
if(! isset($this->login) || $this->login == ""){
|
|
|
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
|
|
|
$row = $statement->fetch();
|
|
|
|
$this->set($row);
|
|
|
|
}
|
|
|
|
return $this->login;
|
2013-07-01 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
2013-08-05 15:31:36 +00:00
|
|
|
public function getEmail(){
|
|
|
|
$dbw = new DBLayer("web");
|
|
|
|
if(! isset($this->email) || $this->email == ""){
|
|
|
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
|
|
|
$row = $statement->fetch();
|
|
|
|
$this->set($row);
|
|
|
|
}
|
|
|
|
return $this->email;
|
2013-07-02 02:42:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-05 15:31:36 +00:00
|
|
|
public function getInfo(){
|
|
|
|
$dbw = new DBLayer("web");
|
|
|
|
if(! (isset($this->firstname) && isset($this->lastname) && isset($this->gender) && isset($this->country) ) ||
|
|
|
|
$this->firstname == "" || $this->lastname == "" || $this->gender == "" || $this->country == ""){
|
|
|
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
|
|
|
$row = $statement->fetch();
|
|
|
|
$this->set($row);
|
|
|
|
}
|
|
|
|
$result = Array('FirstName' => $this->firstname, 'LastName' => $this->lastname, 'Gender' => $this->gender, 'Country' => $this->country);
|
|
|
|
return $result;
|
2013-07-02 14:07:55 +00:00
|
|
|
}
|
2013-07-02 02:42:12 +00:00
|
|
|
|
2013-07-01 21:29:16 +00:00
|
|
|
public function isLoggedIn(){
|
|
|
|
if(isset($_SESSION['user'])){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-02 01:36:49 +00:00
|
|
|
public function setPassword($user, $pass){
|
|
|
|
$reply = WebUsers::setAmsPassword($user, $pass);
|
|
|
|
$values = Array('user' => $user, 'pass' => $pass);
|
|
|
|
try {
|
|
|
|
//make connection with and put into shard db
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbw = new DBLayer("web");
|
2013-07-02 01:36:49 +00:00
|
|
|
$dbw->execute("UPDATE ams_user SET Password = :pass WHERE Login = :user ",$values);
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
|
|
|
//ERROR: the web DB is offline
|
|
|
|
}
|
|
|
|
return $reply;
|
|
|
|
}
|
|
|
|
|
2013-07-02 02:42:12 +00:00
|
|
|
public function setEmail($user, $mail){
|
|
|
|
$reply = WebUsers::setAmsEmail($user, $mail);
|
|
|
|
$values = Array('user' => $user, 'mail' => $mail);
|
|
|
|
try {
|
|
|
|
//make connection with and put into shard db
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbw = new DBLayer("web");
|
2013-07-02 02:42:12 +00:00
|
|
|
$dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values);
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
|
|
|
//ERROR: the web DB is offline
|
|
|
|
}
|
|
|
|
return $reply;
|
|
|
|
}
|
|
|
|
|
2013-07-03 03:57:50 +00:00
|
|
|
public function getUsers(){
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbl = new DBLayer("web");
|
2013-07-03 03:57:50 +00:00
|
|
|
$data = $dbl->executeWithoutParams("SELECT * FROM ams_user");
|
|
|
|
return $data;
|
|
|
|
}
|
2013-07-18 19:12:03 +00:00
|
|
|
|
2013-08-05 19:12:58 +00:00
|
|
|
public static function getAllUsersQuery(){
|
|
|
|
return "SELECT * FROM ams_user";
|
|
|
|
}
|
|
|
|
|
2013-06-29 03:02:54 +00:00
|
|
|
}
|