summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-10-27 19:51:48 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-10-27 19:51:48 -0400
commit2d7a47a99be783c1933af0b24978dc2bbdfe9350 (patch)
tree8eefffd8cf1f3db2ce6efcb8e50846c943e6df61 /src/models
parentdb4376c0c1d5d2ea72696e6d73b469cb2dc30b91 (diff)
parent29a3ffb99435827d5a7ea6886ac22bd2ee18d593 (diff)
Merge branch 'master' into multiuser-viewmultiuser-view
Conflicts: src/controllers/Users.class.php
Diffstat (limited to 'src/models')
-rw-r--r--src/models/Auth.class.php42
-rw-r--r--src/models/ContactMethod.class.php3
2 files changed, 28 insertions, 17 deletions
diff --git a/src/models/Auth.class.php b/src/models/Auth.class.php
index 9017bd5..39f627e 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);
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