Documentation for the basic and must common functions:

Console Doc

  • login - Use to login a user with its credentials
  • register - Use to register a new user
  • update - Use to update any field of the current user in the database
  • addValidation - Use to add validation rules to fields for fields
  • activate - Use to activate an accounts with a confirmation hash
  • resetPassword - Use to generate a hash to reset a forgotten password
  • newPassword - Use to set a new password with a confirmation hash
  • manageUser - Use to manage other users, update other user administratively
  • logout - Use to logout user and destroy any autologin cookie

API changes from v0.97 to 1.0.0

Alternative PHPDoc generated documentation

Useful tips

Matching fields

You can match(check if they are equal) fields by simply appending a '2' to the original field name. For example if the original field name is 'password' then 'password2' will be compared to 'password'.

			
	<input name="password" type="password">
	<input name="password2" type="password">

	<input name="email" type="text">
	<input name="email2" type="text">

		

Making fields optional

You could make a field optional using the addValidation method to set the minimun value to '0'. For example this is the PHP code to make a 'first_name' field optional:

			
	//The Minimun length of 'first_name' could be 0(empty) and Maximun 15
	$user->addValidation("first_name","0-15");

		

Adding new method/function ( advance )

The proffered way to add new methods is to extend the uFlex class. By extending the class you wont be editing the main class file. In PHP you area able extends classes just like in any object oriented programming language. Therefore you could extend the uFlex class and add your methods or modifications without having to modify the uFlex class itself. For example:


class MyUser extends ptejada\uFlex\User{
	/*
	 * Add your default properties values
	 * such as database connection credentials
	 * user default information
	 * Or cookie preferences
	 */

	/*
	 * Create your own methods
	 */
	function updateAvatar(){}

	function linkOpeniDAccout(){}

	/*
	 * Extend existing methods functionality
	 * For example overwrite the register method to
	 * send emails too
	 */
	function register(...){
		//call the original register method
		$response = parent::register(...);

		// Handle the $response and send email conditionally
	}
}

		






login( $username || $email, $password, $auto )

This function login a user with either a username + password combination or email + password combination.

Parameters

username || email

The user's username or email as a string.

password

The user's clear text password.

auto

An optional boolean stating weather to remember the user or not. If true a cookie will be set to auto login the user on its next visit. If false no cookie will be set. By default this is false.

Return Values

N/A

register( $userData, $activation )

This function register a new user after processing and validating the information provided. See addValidation for validating fields.

Parameters

userData

This is an associative array(field => value) with all the user registration information. For example:

					
	Array(
		"username" => "pablo",
		"email"	=> "tadah@whatever.com",
		"password" => "!@#$$%",
		"password2" => "!@#$$%"
	);
				

Note: by default this class doesn't stores password in clear text so the password field will autmatically be hashed before been stored\saved in database.

activation

A boolean that specifies weather the newly register user would need further authentication before he/she could login. If true the new user account will require activation, see activate method. If false the new account will be activated upon registration.

Return Values

Returns true if registration succeeds and $activation is false

Returns a confirmation\activation hash if registration succeeds and $activation is true

Returns false if registration fails, error or failure.

update( $userData )

This function updates any field in the database of a registered user after been processed and validated. See addValidation for validating fields.

Parameters

userData

This is an associative array(field => value) with all the user information been updated. For example:

					
	Array(
		"first_name"	=> "Jose"
		"email"		=> "tadah2@whatever.com"
	);
				

Note: by default this class doesn't stores password in clear text so the password field will autmatically be hashed before been stored\saved in database.

Return Values

Returns true on success

Returns false on error or failure.

addValidation( $name || $rules, $limit, $regEx )

This function is to add validation rules in a per field basis to be used during the validation cycles of the register and update methods.

Validation rules can be added one by one or all together. To add one by one use this format ->addValidation($name, $limit, $regEx) To add it all together use it like this ->addValidation($rules)

Parameters

name || rules

For single rule, one by one, $name is the field name to which the rule will apply. For example: email


For multiple rules at a time, $rules is an strict associative array which may contain multiple if not all the rules you may need to add. Below is the $rules array structure you must follow:

					
	array(
		$name => array(
			"limit" => $limit,
			"regEx" => $regEx
			),
		$name => array(
			"limit" => $limit,
			"regEx" => $regEx
			),
		... 
	);
				

So instead of doing

					
	$user->addValidation("username", "3-15", "/^([a-z])+$/");		
	$user->addValidation("password", "3-15", false);
				

You could do


	$validations = array(
		"username" => array(
			"limit" => "3-15",
			"regEx" => "/^([a-z])+$/"
			),
		"password" => array(
			"limit" => "3-15",
			"regEx" => false
			)
	);
	
	$user->addValidation($validations);
				

Both uses will accomplished the same results, is just a matter of which feels more natural to you.

limit

Its a range in the form of a string. This rage deternines the minimun and maximun length of the field value. For example: "3-15" means minimun length is 3 and the maximun 15.
The default value is "0-1".

regEx

Its the Regular Expression with which the field value will be tested against. For Example: "/^\w+$/" will match a word (hola), no symbols nor spaces, just a word.
The default value is false.

Return Values

N/A

activate( $hash )

This function activates a user account with a confirmation hash. The $hash is usually the hash returned by the register method.

Parameters

hash

The user confirmation hash to activate the account. This hash is returned by the register method.

Return Values

Returns true on successful activation.

Returns false on activation error or failure.

resetPassword( $email )

This function generate a hash which will then be used with the newPassword function to actually change the user's password. The hash returned by this function will most likely be emailed to the user embeded in a URL.

Parameters

email

The plain text email associated with the user account for the password reset.

Return Values

Returns an associative with the following keys: user_id, username, email, hash. The essential information for sending a password reset email to user.

Returns false on error or failure.

newPassword( $hash, $newPass )

This function uses the supplied hash to change the password of the user. This functions also validates the password field according to the validation rules like in register and update.

Parameters

hash

A compatible user hash, usually the hash returned by the resetPassword function.

newPass

This argument is NOT a string, is actually an array. An array with double password field to confirm the new password. The array indexes should be password and password2:

					
	array(
	  "password"  => 123456
	  "password2" => 123456
	);
				

Return Values

Returns true on success.

Returns false on error or failure.

manageUser( $userID )

Use to manage other users other than the current user. Is simple, the factory returns a clone of the uFlex instance but the new instance will control the user with the specified $userID.

Parameters

userID

The ID of the user to manage.

Return Values

Returns an uFlex instance or false if the user does not exists.

logout()

This function is use to logout a user by deleting the class session space and any existing auto-login cookies.

Parameters

N/A

Return Values

N/A



Copyright © 2010-2016 Pablo Tejada, All Right Reserved. Webmaster | Generated in 0.01 seconds