update
This commit is contained in:
106
Admin/module/AuthDAL.mod.php
Normal file
106
Admin/module/AuthDAL.mod.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?
|
||||
|
||||
/**
|
||||
* $Id: AuthDAL.mod.php 708 2008-06-26 13:48:43Z pawy $
|
||||
* Klasa autoryzacji usera
|
||||
*
|
||||
*/
|
||||
class AuthDAL {
|
||||
/**
|
||||
* Pusty konstruktor
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza uzytkownika i haslo, loguje usera , zapisuje obiekt klasy User do sesji i zwraca 1/0
|
||||
*
|
||||
* @param string $login
|
||||
* @param string $password
|
||||
* @return boolean
|
||||
*/
|
||||
public static function Login($login, $password) {
|
||||
|
||||
$adminList = AdminDAL::GetResult(array("login" => $login, "password" => md5(trim($password))), array(), 1);
|
||||
//Utils::ArrayDisplay($adminList);
|
||||
|
||||
if(!empty($adminList)) {
|
||||
|
||||
$admin = $adminList[0];
|
||||
$admin->SetAuthorized(true);
|
||||
$lastLogin = $admin->GetLastLogin();
|
||||
$admin->SetLastLogin('NOW()');
|
||||
|
||||
AdminDAL::Save($admin);
|
||||
|
||||
$admin->SetLastLogin($lastLogin);
|
||||
$admin->GetAccess();
|
||||
|
||||
SessionProxy::SetValue(EnumSessionValue::ADMIN_OBJECT, $admin);
|
||||
return $admin->GetId();
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca obiekt klasy User lub 0
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function GetAdmin() {
|
||||
|
||||
$admin = SessionProxy::GetValue(EnumSessionValue::ADMIN_OBJECT);
|
||||
//Utils::ArrayDisplay($admin);
|
||||
$remember = Request::GetCookie('remember');
|
||||
if(is_object($admin) ){
|
||||
return $admin;
|
||||
} else if(isset($remember) && $remember == '1'){
|
||||
$adminList = AdminDAL::GetResult(array("hash" => Request::GetCookie('key')), array(), 1);
|
||||
|
||||
if(!empty($adminList)) {
|
||||
$admin = $adminList[0];
|
||||
|
||||
$admin->SetAuthorized(true);
|
||||
$admin->GetAccess();
|
||||
Registry::Set('admin', $admin);
|
||||
SessionProxy::SetValue(EnumSessionValue::ADMIN_OBJECT, $admin);
|
||||
return $admin;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Przeladowuje uzytkownika w sesji
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
public static function ReloadUser() {
|
||||
$admin = SessionProxy::GetValue(EnumSessionValue::ADMIN_OBJECT);
|
||||
$adminId = $admin->GetId();
|
||||
|
||||
$admin = AdminDAL::GetById($adminId);
|
||||
$admin->GetAccess();
|
||||
|
||||
$admin->SetAuthorized(true);
|
||||
SessionProxy::ClearValue(EnumSessionValue::ADMIN_OBJECT);
|
||||
SessionProxy::SetValue(EnumSessionValue::ADMIN_OBJECT, $admin);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Czysci sesje wylogowujac usera
|
||||
*
|
||||
*/
|
||||
public static function Logout() {
|
||||
SessionProxy::ClearValue(EnumSessionValue::ADMIN_OBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user