00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00058 class mosUser extends aliroDatabaseRow {
00059 protected $DBclass = 'aliroDatabase';
00060 protected $tableName = '#__users';
00061 protected $rowKey = 'id';
00062
00066 protected function getSessionData() {
00067
00068 $prefix = criticalInfo::getInstance()->isAdmin ? 'admin' : 'user';
00069
00070
00071 aliroSessionFactory::getSession();
00072 $this->id = isset($_SESSION["aliro_{$prefix}id"]) ? (int) $_SESSION["aliro_{$prefix}id"] : 0;
00073 $this->name = isset($_SESSION["aliro_{$prefix}name"]) ? $_SESSION["aliro_{$prefix}name"] : '';
00074 $this->username = isset($_SESSION["aliro_{$prefix}username"]) ? $_SESSION["aliro_{$prefix}username"] : '';
00075 $this->email = isset($_SESSION["aliro_{$prefix}email"]) ? $_SESSION["aliro_{$prefix}email"] : '';
00076 $this->sendEmail = isset($_SESSION["aliro_{$prefix}sendEmail"]) ? $_SESSION["aliro_{$prefix}sendEmail"] : '';
00077 $this->usertype = isset($_SESSION["aliro_{$prefix}type"]) ? $_SESSION["aliro_{$prefix}type"] : '';
00078 $this->gid = isset($_SESSION["aliro_{$prefix}gid"]) ? (int) $_SESSION["aliro_{$prefix}gid"] : 0;
00079 }
00080
00081
00082 public function userStore($password='', $activation='') {
00083 $salt = aliroAdminAuthenticator::getInstance()->makeSalt();
00084 if ($this->id) {
00085 $ret = $this->update();
00086 if ($password) {
00087 $database = aliroCoreDatabase::getInstance();
00088 $database->doSQL("UPDATE #__core_users SET salt = IF(salt='', '$salt', salt), password = MD5(CONCAT(salt, '$password')) WHERE id = $this->id");
00089 }
00090 }
00091 else {
00092 $database = aliroCoreDatabase::getInstance();
00093 $database->doSQL("INSERT INTO #__core_users (password, salt, activation) VALUES (MD5(CONCAT('$salt', '$password')), '$salt', '$activation')");
00094 $this->id = $database->insertid();
00095 $ret = $this->insert();
00096 }
00097 if ($ret) return true;
00098 $this->_error = T_('mosUser::store failed');
00099 return false;
00100 }
00101
00102 public function delete($oid=null) {
00103 if ($oid) $this->id = intval( $oid );
00104 aliroCoreDatabase::getInstance()->doSQL("DELETE FROM `#__core_users` WHERE `id` = '$this->id'");
00105 $database = aliroDatabase::getInstance();
00106 $database->doSQL("DELETE FROM `#__users` WHERE `id` = '$this->id'");
00107
00108 $database->setQuery( "DELETE FROM `#__messages_cfg` WHERE `user_id`='$this->id'" );
00109 $database->query();
00110 $database->setQuery( "DELETE FROM `#__messages` WHERE `user_id_to`='{$this->id}'" );
00111 $database->query();
00112 return true;
00113 }
00114
00115 public function check() {
00116 if ($this->name == '') $error = T_('Please enter your name');
00117 elseif ($this->username == '') $error = T_('Please enter a user name');
00118 elseif (strlen($this->username) < 3 OR preg_match("/[\\<\\>\\\"\\'\\%\\;\\(\\)\\&\\+\\-]/", $this->username)) $error = sprintf(T_('Please enter a valid %s. No spaces, more than %d characters and containing only the characters 0-9,a-z, or A-Z'), T_('Username'), 2 );
00119 elseif (($this->email == '') OR preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email ) == 0) $error = T_('Please enter a valid e-mail address');
00120 else {
00121
00122 $database = aliroDatabase::getInstance();
00123 $database->setQuery( "SELECT COUNT(id) FROM #__users WHERE LOWER(username)=LOWER('$this->username') AND id!='$this->id'");
00124 if ($database->loadResult()) $error = T_('This username/password is already in use. Please try another.');
00125 elseif (aliroCore::get('mosConfig_uniquemail')) {
00126
00127 $database->setQuery( "SELECT COUNT(id) FROM #__users WHERE email='$this->email' AND id!='$this->id'");
00128 if ($database->loadResult()) $error = T_('This e-mail is already registered. If you forgot the password click on "Password Reminder" and new password will be sent to you.');
00129 }
00130 }
00131 if (isset($error)) {
00132 aliroRequest::getInstance()->setErrorMessage($error, _ALIRO_ERROR_FATAL);
00133 return false;
00134 }
00135 return true;
00136 }
00137
00138 }
00139
00140 class aliroUser extends mosUser {
00141 private static $instance = __CLASS__;
00142
00143 private function __construct () {
00144 $this->getSessionData();
00145 }
00146
00147 private function __clone () {
00148
00149 }
00150
00151 public static function getInstance () {
00152 return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance());
00153 }
00154
00155 public function reset () {
00156 $this->getSessionData();
00157 }
00158 }