Documenation
User
/_plugins/user.php
The user plugin handles user authentication and preferences. This plugin requires a database and depends on the MySQL (or any other database) and Session plug-ins.
Example
01
02
03
04
05
06
07
08
09
10
11
02
03
04
05
06
07
08
09
10
11
<?php
if ( $model->session->get('user id') != user::guestId )
{
// User is logged in
}
if ( $model->session->get('user is owner') )
{
// User is the website owner
}
?>
Preferences
Plug-ins can add new preferences to user accounts. Users can change their preferences on the account page (/account/).
The $model->user->save_pref() function requires three or four parameters.
-
pref
The name of the preference. -
type
The type of preference, one of select (multiple choice), text (manual input) and checkbox (yes/no). -
match
A regular expression to validate the user input. -
options
An array with options (presented to the user), only used when the type is set toselect.
Example
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?php
$model->user->save_pref(array(
'pref' => 'Example',
'type' => 'select',
'match' => '/.*/',
'options' => array(1 => 'Option 1', 2 => 'Option 2')
));
?>
Class
$model->user
Public functions
-
$model->user->login ( string $username, string $password )
Logs the user in with a username and password and updates the session. -
$model->user->logout ( )
Logs the user out and resets the session. -
$model->user->validate_password ( string $username, string $password )
Checks if a username/password combination is correct. -
$model->user->make_pass_hash ( string $username, string $password )
Generates a password hash. -
$model->user->save_pref ( array $params )
Saves a preference. -
$model->user->delete_pref ( string $pref )
Deletes a preference. -
$model->user->save_pref_value ( string $params )
Saves a preference value. -
$model->user->get_pref_values ( int $userId )
Gets a user's preferences.
Constants
-
user::guestId
Reserved user ID for all guest users (users who are not logged in). This can be used to test if a user is logged in or not (e.g.if ( $model->session->get('user id') != user::guestId )).