plip
This commit is contained in:
parent
1ab397af86
commit
07d17b0a4d
2
User.php
2
User.php
|
@ -11,8 +11,6 @@ class User
|
|||
|
||||
protected $db;
|
||||
|
||||
|
||||
|
||||
public function get_id()
|
||||
{
|
||||
if($this->is_connected){
|
||||
|
|
|
@ -6,6 +6,8 @@ class User_Manager
|
|||
private static $table_users = 'users';
|
||||
private static $table_groups = 'groups';
|
||||
|
||||
//could append 'ldap', 'cas':
|
||||
private static $available_auth_methods = array('local');
|
||||
|
||||
const QUERY_CREATE_TABLE_USERS = "
|
||||
CREATE TABLE %table_users% (
|
||||
|
@ -55,7 +57,15 @@ class User_Manager
|
|||
";
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Erase the list of avaliable methods
|
||||
* @ input methods: Array (non associative)
|
||||
* return true
|
||||
*/
|
||||
public static function set_available_auth_methods($methods)
|
||||
{
|
||||
self::$available_auth_methods = $methods;
|
||||
}
|
||||
public static function create_local_tables(PDO $db)
|
||||
{
|
||||
$searched = array('%table_users%','%table_groups%');
|
||||
|
@ -76,12 +86,27 @@ class User_Manager
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public function authentificate($db,$login, $password){
|
||||
$user = new User_Sql($db);
|
||||
if($user->authentificate($login,$password)){
|
||||
return $user;
|
||||
|
||||
foreach(self::$available_auth_methods as $method){
|
||||
|
||||
switch($method)
|
||||
{
|
||||
case "local":
|
||||
case "sql'":
|
||||
$user = new User_Sql($db);
|
||||
if($user->authentificate($login,$password)){
|
||||
return $user;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
$user = new User();
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
25
User_Sql.php
25
User_Sql.php
|
@ -1,6 +1,31 @@
|
|||
<?php
|
||||
class User_Sql extends User {
|
||||
|
||||
|
||||
public static function create_user(PDO $db,$table_users,$login, $display_name,
|
||||
$password,$admin = false,$active = true)
|
||||
{
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO " . $table_users . "
|
||||
(login, display_name, auth_method,password,admin,active)
|
||||
VALUES
|
||||
(:login, :display_name, 'local', :password, :admin, :active)"
|
||||
);
|
||||
|
||||
$stmt->bindParam(':login', $login);
|
||||
$stmt->bindParam(':display_name', $display_name);
|
||||
$stmt->bindParam(':password',$hashed_password);
|
||||
$stmt->bindParam(':admin', $adminInt);
|
||||
$stmt->bindParam(':active', $activeInt);
|
||||
|
||||
$hashed_password = password_hash($password, PASSWORD_BCRYPT);
|
||||
$adminInt = $admin? 1 : 0;
|
||||
$activeInt = $activeInt? 1 : 0;
|
||||
$stmt->execute();
|
||||
|
||||
return $db->lastInsertId();
|
||||
}
|
||||
|
||||
public function authentificate($login,$password)
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user