amdp3-metaforums/Application/Services/Authentication.php

31 lines
897 B
PHP
Raw Permalink Normal View History

2019-11-18 13:33:45 +00:00
<?php
namespace Application\Services;
2019-11-19 03:36:39 +00:00
use Application\Models\User;
2019-11-18 13:33:45 +00:00
class Authentication {
public function __construct() {
ServiceContainer::Session();
}
public function isLoggedIn() {
return ServiceContainer::Session()->has('user_id');
}
2019-11-19 03:36:39 +00:00
public function isModerator() {
if(!$this->isLoggedIn()) return false;
$id = ServiceContainer::Session()->get('user_id');
$user = User::find($id);
return ($user->is_moderator);
}
public function isAdmin() {
if(!$this->isLoggedIn()) return false;
$id = ServiceContainer::Session()->get('user_id');
$user = User::find($id);
return ($user->is_admin);
}
public function user() {
$id = ServiceContainer::Session()->get('user_id');
$user = User::find($id);
return $user;
}
2019-11-18 13:33:45 +00:00
}