05.4 User Functions
Peter Ivanov edited this page Aug 20, 2013
·
1 revision
Use the to work with the user and the session
Returns the current user id. If the user is not logged returns false;
$user_id = user_id();
Returns the array of users
Parameters for get_users
parameter | description | |
---|---|---|
id | the id of the content | |
created_on | the date of creation |
strtotime compatible date |
updated_on | the date of last edit |
strtotime compatible date |
last_login | datetime of the last login | |
last_login_ip | the last login ip address | |
username | username for login | |
email for login | ||
password | password for login | |
first_name | user first name | |
last_name | user last name | |
thumbnail | src for the profile picture | |
is_verified | flag for verified email address | "n" or "y" |
is_active | indicated if the user account is active | "y" or "n" |
is_admin | indicated if the user is admin | "y" or "n" |
Usage:
$users = get_users('email=example@example.com');
$admins = get_users('is_admin=y');
Logs in a user into the CMS
also avaiable via the REST api at http://yoursite/api/user_login
//login a user
$login_data = array();
$login_data['username'] = 'admin';
$login_data['password'] = '123456';
$login = user_login($login_data);
var_dump($login);
// On error
array(["error"]=> string(41) "Please enter right username and password!" );
// On success
array(["is_logged"]=> string(3) "yes" ["user_id"]=> string(1) "1" ["success"]=> string(18) "You are logged in!");
Logs out a user
also avaiable via the REST api at http://yoursite/api/logout
//log out a user
logout();
Register new user
(requires capcha) Call via the REST api at http://yoursite/api/user_register
<form method=post>
<input type="text" name="username">
<input type="password" name="password">
<input type="text" name="capcha">
<img src="<?php print site_url('api_html/capcha'); ?>">
<input type="submit" name="register">
</form>