plop
This commit is contained in:
commit
3ec7bb774a
48
User.php
Normal file
48
User.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
class User
|
||||
{
|
||||
protected $is_connected = false;
|
||||
protected $id, $display_name, $auth_method;
|
||||
protected $groups =array();
|
||||
|
||||
protected $db;
|
||||
|
||||
public function __sleep(){
|
||||
return array('is_connected','id','display_name','auth_method','groups');
|
||||
}
|
||||
|
||||
public function get_id()
|
||||
{
|
||||
if($this->is_connected){
|
||||
return $this->id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function is_connected()
|
||||
{
|
||||
return $this->is_connected;
|
||||
}
|
||||
public function get_auth_method()
|
||||
{
|
||||
if($this->is_connected){
|
||||
return $this->auth_method;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function get_groups()
|
||||
{
|
||||
return $this->groups;
|
||||
}
|
||||
public function set_db_obj($db){
|
||||
$this->db = $db;
|
||||
return $this;
|
||||
}
|
||||
public function __construct($db){
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
5
User_Ldap.php
Normal file
5
User_Ldap.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
class User_Ldap extends User {
|
||||
|
||||
|
||||
}
|
14
User_Manager.php
Normal file
14
User_Manager.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class User_Manager
|
||||
{
|
||||
|
||||
public function authentificate($db,$login, $password){
|
||||
$user = new User_Sql($db);
|
||||
if($user->authentificate($login,$password)){
|
||||
return $user;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
33
User_Sql.php
Normal file
33
User_Sql.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
class User_Sql extends User {
|
||||
|
||||
public function authentificate($login,$password)
|
||||
{
|
||||
|
||||
$sql =
|
||||
"SELECT id,display_name,
|
||||
FROM users
|
||||
WHERE login='". mysqli_real_escape_string($this->db,$login) . "'
|
||||
AND password=SHA2('". mysqli_real_escape_string($this->db,$password) . "',512)
|
||||
AND auth_method='local';";
|
||||
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
if($r = $rs->fetch_array(MYSQLI_ASSOC)){
|
||||
$this->is_connected = true;
|
||||
$this->display_name = $r["display_name"];
|
||||
$this->id = $r['id'];
|
||||
$this->auth_method = 'sql';
|
||||
|
||||
return $this;
|
||||
|
||||
}else{
|
||||
$this->is_connected = false;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user