use a separate UserSessionModel in Session
This commit is contained in:
		
							parent
							
								
									92075f4b39
								
							
						
					
					
						commit
						a8bba12107
					
				| @ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| final class UserModel | ||||
| final class UserModel extends UserSessionModel | ||||
| { | ||||
| 
 | ||||
|     public function createUser($S_email, $S_username, $S_password_hash){ | ||||
| @ -57,30 +57,6 @@ final class UserModel | ||||
|         if ($row === false) return null; | ||||
|         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){ | ||||
|         $O_model = Model::get(); | ||||
|  | ||||
| @ -47,8 +47,8 @@ final class Session | ||||
|         } | ||||
|          | ||||
|         // ensure account has not been deleted/disabled in the meantime
 | ||||
|         $O_userModel = new UserModel(); | ||||
|         $B_userActive = $O_userModel->isUserActive($_SESSION["ID"]); | ||||
|         $O_userSessionModel = new UserSessionModel(); | ||||
|         $B_userActive = $O_userSessionModel->isUserActive($_SESSION["ID"]); | ||||
|         return $B_userActive; | ||||
|     } | ||||
| 
 | ||||
| @ -68,8 +68,8 @@ final class Session | ||||
|     public static function is_admin(){ | ||||
|         if (!self::is_login()) return false; | ||||
| 
 | ||||
|         $O_userModel = new UserModel(); | ||||
|         return $O_userModel->isUserAdmin($_SESSION["ID"]); | ||||
|         $O_userSessionModel = new UserSessionModel(); | ||||
|         return $O_userSessionModel->isUserAdmin($_SESSION["ID"]); | ||||
|     } | ||||
|      | ||||
|     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