use a separate UserSessionModel in Session
This commit is contained in:
parent
92075f4b39
commit
a8bba12107
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class UserModel
|
final class UserModel extends UserSessionModel
|
||||||
{
|
{
|
||||||
|
|
||||||
public function createUser($S_email, $S_username, $S_password_hash){
|
public function createUser($S_email, $S_username, $S_password_hash){
|
||||||
@ -58,30 +58,6 @@ final class UserModel
|
|||||||
return $row["USERNAME"];
|
return $row["USERNAME"];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isUserActive($I_id)
|
|
||||||
{
|
|
||||||
$O_model = Model::get();
|
|
||||||
$stmt = $O_model->prepare("SELECT DISABLED FROM USER WHERE ID=:id");
|
|
||||||
$stmt->bindParam("id", $I_id);
|
|
||||||
$stmt->execute();
|
|
||||||
|
|
||||||
$row = $stmt->fetch();
|
|
||||||
if ($row === false) return false;
|
|
||||||
return $row["DISABLED"] !== 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isUserAdmin($I_id)
|
|
||||||
{
|
|
||||||
$O_model = Model::get();
|
|
||||||
$stmt = $O_model->prepare("SELECT ADMIN FROM USER WHERE ID=:id");
|
|
||||||
$stmt->bindParam("id", $I_id);
|
|
||||||
$stmt->execute();
|
|
||||||
|
|
||||||
$row = $stmt->fetch();
|
|
||||||
if ($row === false) return false;
|
|
||||||
return $row["ADMIN"] === 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateEmailByID($I_id, $S_newEmail){
|
public function updateEmailByID($I_id, $S_newEmail){
|
||||||
$O_model = Model::get();
|
$O_model = Model::get();
|
||||||
$stmt = $O_model->prepare("UPDATE USER SET EMAIL=:new_email WHERE ID=:id");
|
$stmt = $O_model->prepare("UPDATE USER SET EMAIL=:new_email WHERE ID=:id");
|
||||||
|
|||||||
@ -47,8 +47,8 @@ final class Session
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure account has not been deleted/disabled in the meantime
|
// ensure account has not been deleted/disabled in the meantime
|
||||||
$O_userModel = new UserModel();
|
$O_userSessionModel = new UserSessionModel();
|
||||||
$B_userActive = $O_userModel->isUserActive($_SESSION["ID"]);
|
$B_userActive = $O_userSessionModel->isUserActive($_SESSION["ID"]);
|
||||||
return $B_userActive;
|
return $B_userActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,8 +68,8 @@ final class Session
|
|||||||
public static function is_admin(){
|
public static function is_admin(){
|
||||||
if (!self::is_login()) return false;
|
if (!self::is_login()) return false;
|
||||||
|
|
||||||
$O_userModel = new UserModel();
|
$O_userSessionModel = new UserSessionModel();
|
||||||
return $O_userModel->isUserAdmin($_SESSION["ID"]);
|
return $O_userSessionModel->isUserAdmin($_SESSION["ID"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function admin_or_die(){
|
public static function admin_or_die(){
|
||||||
|
|||||||
30
Modules/Session/UserSessionModel.php
Normal file
30
Modules/Session/UserSessionModel.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class UserSessionModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function isUserActive($I_id)
|
||||||
|
{
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("SELECT DISABLED FROM USER WHERE ID=:id");
|
||||||
|
$stmt->bindParam("id", $I_id);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$row = $stmt->fetch();
|
||||||
|
if ($row === false) return false;
|
||||||
|
return $row["DISABLED"] !== 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isUserAdmin($I_id)
|
||||||
|
{
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("SELECT ADMIN FROM USER WHERE ID=:id");
|
||||||
|
$stmt->bindParam("id", $I_id);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$row = $stmt->fetch();
|
||||||
|
if ($row === false) return false;
|
||||||
|
return $row["ADMIN"] === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user