diff options
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/Auth.class.php | 42 | ||||
-rw-r--r-- | src/models/ContactMethod.class.php | 3 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/models/Auth.class.php b/src/models/Auth.class.php index 9017bd5..bb35be5 100644 --- a/src/models/Auth.class.php +++ b/src/models/Auth.class.php @@ -1,15 +1,19 @@ <?php -require_once('MessageManager.class.php'); +require_once('Model.class.php'); require_once('Login.class.php'); +require_once('Database.class.php'); + require_once('Group.class.php'); require_once('User.class.php'); -class Auth { - static $users = array(); - public static function getObj($uid) { +class Auth extends Model { + /**********************************************************************\ + * Multiton stuff * + \**********************************************************************/ + private static $users = array(); + public static function getInstance($uid) { if (!isset(self::$users[$uid])) { - global $mm; - $type = $mm->database()->getStatus($uid)<3; + $type = Database::getInstance()->getStatus($uid)<3; switch ($type) { case 0: // unactivated user case 1: // user @@ -21,7 +25,10 @@ class Auth { } return self::$users[$uid]; } - + + /**********************************************************************\ + * Static stuff * + \**********************************************************************/ public static function isNameLegal($name) { // Current rules: // * Not in "$illegal_names" @@ -34,12 +41,13 @@ class Auth { && (strpos($name,'!')===false) && (strlen($name)<256); } - - protected $db = null; + + /**********************************************************************\ + * Class stuff * + \**********************************************************************/ protected $uid = false; public function __construct($uid) { - global $mm; - $this->db = $mm->database(); + parent::__construct(); $this->uid = $uid; } public function getUID() { @@ -60,7 +68,7 @@ class Auth { } protected function setType($type) { $logged_in_uid = Login::isLoggedIn(); - $logged_in_obj = Auth::getObj($logged_in_uid); + $logged_in_obj = Auth::getInstance($logged_in_uid); $is_admin = $logged_in_obj->isAdmin(); if (!$is_admin) return false; return $this->db->setStatus($this->uid, $type); @@ -97,7 +105,7 @@ class Auth { $logged_in_uid = Login::isLoggedIn(); $is_me = ($logged_in_uid === $this->uid); - $logged_in_obj = Auth::getObj($logged_in_uid); + $logged_in_obj = Auth::getInstance($logged_in_uid); $is_user = $logged_in_obj->isUser(); return ($is_me || $is_user); @@ -106,7 +114,7 @@ class Auth { $logged_in_uid = Login::isLoggedIn(); $is_me = ($logged_in_uid === $this->uid); - $logged_in_obj = Auth::getObj($logged_in_uid); + $logged_in_obj = Auth::getInstance($logged_in_uid); $is_admin = $logged_in_obj->isAdmin(); return ($is_me || $is_admin); @@ -114,7 +122,11 @@ class Auth { // [user|group]name //////////////////////////////////////////////////// public function getName() { - return $this->db->getUsername($this->uid); + if ($this->db===null) { + return false; + } else { + return $this->db->getUsername($this->uid); + } } public function setName($new_name) { if (!$this->canEdit()) return false; diff --git a/src/models/ContactMethod.class.php b/src/models/ContactMethod.class.php index b01e7d3..1dd40ee 100644 --- a/src/models/ContactMethod.class.php +++ b/src/models/ContactMethod.class.php @@ -1,11 +1,10 @@ <?php - global $CONTACT_METHODS; if (!isset($CONTACT_METHODS)) { $CONTACT_METHODS = array(); } -class ContactMethod { +class ContactMethod extends Model { public $verb_slug = ''; // sms public $addr_slug = ''; // phone public $verb_text = ''; // text message |