4 /* Registered user, but not logged in */
5 class reguser
extends anonuser
9 function __construct($userid, $prefetch = null)
11 parent
::__construct();
13 $this->userid
= $userid;
14 $this->attrcache
= array();
16 $fields = array('`alias`', '`level`', '`timezone`', '`theme`');
18 $fields = array_merge($fields, $prefetch);
20 $this->attrcache
= $GLOBALS['DB']->query('SELECT '.implode(', ', $fields).'
21 FROM `users` WHERE `userid` = '.$userid)->fetch_assoc();
22 $this->namecache
[$userid] = $this->alias
;
25 function __get($varname)
27 if ( !array_key_exists($varname, $this->attrcache
) ) {
32 $fieldname = 'INET_NTOA(`'.$varname.'`)';
35 $fieldname = 'AES_DECRYPT(`'.$varname.'`, `reg_ip`)';
38 $fieldname = '`'.$varname.'`';
42 $q = $GLOBALS['DB']->query('SELECT '.$fieldname.' AS `'.$varname.'` FROM `users` WHERE `userid` = '.$this->userid
);
43 if ( $GLOBALS['DB']->error
)
44 throw new OutOfBoundsException('MySQL error in authuser::_get('.$varname.'): '.$GLOBALS['DB']->error
);
46 $this->attrcache
[$varname] = $q->fetch_object()->$varname;
48 if ( array_key_exists($varname, $this->attrcache
) ) {
49 return $this->attrcache
[$varname];
51 throw new OutOfBoundsException('Error in $user->_get('.$varname.' => '.$fieldname.'): attribute not available.');
54 function __set($varname, $value)
56 $this->attrcache
[$varname] = $value;
61 if ( strpos($value, ':') !== false ) {
65 $value = 'INET_ATON(\''.$value.'\')';
68 $value = 'AES_ENCRYPT(\''.$value.'\', `reg_ip`)';
71 if ( $value > 20 && sqrt($value) == floor(sqrt($value))
72 && $GLOBALS['DB']->query('SELECT COUNT(*) AS `c` FROM `invites`
73 WHERE `userid` = '.$this->userid
)->fetch_object()->c
< 5 )
74 $GLOBALS['DB']->query('INSERT INTO `invites` VALUES (NULL, '.$this->userid
.', UUID())');
78 $value = '\''.$GLOBALS['DB']->escape_string($value).'\'';
81 $GLOBALS['DB']->query('UPDATE `users` SET `'.$varname.'` = '.$value.' WHERE `userid` = '.$this->userid
);
82 if ( $GLOBALS['DB']->error
)
83 throw new UnexpectedValueException('MySQL error in authuser::_set('.$varname.' = '.$value.'): '.$GLOBALS['DB']->error
);