khanat-opennel-code/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php

160 lines
5.2 KiB
PHP
Raw Normal View History

<?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'];
}
/**
* Function checkUserNameExists
*
* @takes $username
* @return string Info: Returns true or false if the user is in the web db.
*/
protected function checkUserNameExists($username){
$dbw = new DBLayer("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){
$dbw = new DBLayer("web");
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){
$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-05 19:12:58 +00:00
//returns te id for a given username
2013-08-05 15:31:36 +00:00
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'];
}
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-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-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
}
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
$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;
}
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
$dbw = new DBLayer("web");
$dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values);
}
catch (PDOException $e) {
//ERROR: the web DB is offline
}
return $reply;
}
public function getUsers(){
$dbl = new DBLayer("web");
$data = $dbl->executeWithoutParams("SELECT * FROM ams_user");
return $data;
}
2013-08-05 19:12:58 +00:00
public static function getAllUsersQuery(){
return "SELECT * FROM ams_user";
}
}