]>
src.bluestatic.org Git - bugdar.git/blob - includes/api_user.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 $GLOBALS [ 'isso:callback' ]-> load ( 'api' , null );
24 require_once ( './includes/functions_datastore.php' );
29 * @author Iris Studios, Inc.
30 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
35 class UserAPI
extends API
43 'userid' => array ( TYPE_UINT
, REQ_AUTO
, 'verify_nozero' ),
44 'email' => array ( TYPE_STR
, REQ_YES
, ':self' ),
45 'displayname' => array ( TYPE_STR
, REQ_YES
, ':self' ),
46 'usergroupid' => array ( TYPE_UINT
, REQ_YES
, ':self' ),
47 'password' => array ( TYPE_STR
, REQ_YES
, 'verify_noempty' ),
48 'salt' => array ( TYPE_STR
, REQ_SET
),
49 'authkey' => array ( TYPE_STR
, REQ_SET
),
50 'showemail' => array ( TYPE_BOOL
, REQ_NO
),
51 'showcolours' => array ( TYPE_BOOL
, REQ_NO
),
52 'languageid' => array ( TYPE_UINT
, REQ_NO
),
53 'timezone' => array ( TYPE_INT
, REQ_NO
),
54 'usedst' => array ( TYPE_BOOL
, REQ_NO
)
69 var $prefix = TABLE_PREFIX
;
71 // ###################################################################
79 $this- > set ( 'salt' , $this- > registry
-> funct
-> rand ( array ( 1 , 15 )));
82 // ###################################################################
88 function set_authkey ()
90 $this- > set ( 'authkey' , $this- > registry
-> funct
-> rand ());
93 // ###################################################################
101 $this- > set ( 'password' , md5 ( md5 ( $this- > values
[ 'password' ]) . md5 ( $this- > values
[ 'salt' ])));
104 // ###################################################################
110 function post_insert ()
115 // ###################################################################
121 function verify_email ()
123 $this- > verify_noempty ( 'displayname' );
125 if ( $this- > registry
-> funct
-> is_valid_email ( $this- > values
[ 'email' ]))
127 return $this- > registry
-> lang
-> string ( 'The specified email is invalid.' );
129 if ( $this- > registry
-> db
-> query_first ( "SELECT * FROM " . TABLE_PREFIX
. "user WHERE email = '" . $this- > registry
-> db
-> escape_string ( $this- > values
[ 'email' ]) . "' AND userid <> " . $this- > values
[ 'userid' ]))
131 return $this- > registry
-> lang
-> string ( 'The specified email is already in use.' );
136 // ###################################################################
138 * Verify: displayname
142 function verify_displayname ()
144 $this- > verify_noempty ( 'displayname' );
146 if ( $this- > registry
-> db
-> query_first ( "SELECT * FROM " . TABLE_PREFIX
. "user WHERE displayname = '" . $this- > registry
-> db
-> escape_string ( $this- > values
[ 'displayname' ]) . "' AND userid <> " . $this- > values
[ 'userid' ]))
148 return $this- > registry
-> lang
-> string ( 'That display name is already in use by another user.' );
153 // ###################################################################
155 * Verify: usergroupid
159 function verify_usergroupid ()
161 if (! isset ( $this- > registry
-> datastore
[ 'usergroup' ][ $this- > values
[ 'usergroupid' ] ]))
168 // ###################################################################
174 function pre_update ()
176 $this- > set_condition ();
179 if ( $this- > values
[ 'password' ] == '' )
181 $this- > set ( 'password' , $this- > objdata
[ 'password' ]);
185 $this- > registry
-> debug ( "updating password = true" );
186 $this- > set ( 'password' , md5 ( md5 ( $this- > values
[ 'password' ]) . md5 ( $this- > objdata
[ 'salt' ])));
190 // ###################################################################
196 function post_update ()
201 // ###################################################################
207 function pre_delete ()
209 if ( $this- > values
[ 'userid' ] == $this- > registry
-> userinfo
[ 'userid' ])
211 $this- > error ( $lang- > string ( 'You cannot delete your own account!' ));
214 if ( $this- > values
[ 'usergroupid' ] == 6 )
216 $count = $this- > registry
-> db
-> query_first ( "SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user WHERE usergroupid = 6 AND userid <> " . $this- > values
[ 'userid' ]);
217 if ( $count [ 'count' ] < 1 )
219 $this- > error ( $lang- > string ( 'At least one other administrator needs to be present before you can delete this user' ));
224 // ###################################################################
228 * @todo Finish post-delete user data cleanup
232 function post_delete ()
234 $this- > registry
-> db
-> query ( "DELETE FROM " . TABLE_PREFIX
. "user WHERE userid = " . $this- > values
[ 'userid' ]);
235 $this- > registry
-> db
-> query ( "DELETE FROM " . TABLE_PREFIX
. "favourite WHERE userid = " . $this- > values
[ 'userid' ]);
236 $this- > registry
-> db
-> query ( "DELETE FROM " . TABLE_PREFIX
. "useractivation WHERE userid = " . $this- > values
[ 'userid' ]);
242 /*=====================================================================*\
243 || ###################################################################
246 || ###################################################################
247 \*=====================================================================*/