\ptejada\uFlexUser

All in one user object use to authenticating, registering new users and other user actions Note: Either start() or login() must be called at least once on your code per User instance

Summary

Methods
Properties
Constants
__construct()
addValidation()
getProperty()
__get()
__set()
toArray()
login()
start()
logout()
isSigned()
register()
update()
resetPassword()
newPassword()
__destruct()
activate()
manageUser()
$log
$config
$table
$session
VERSION
toCollection()
validateAll()
validate()
$hash
$_data
$_updates
$_validations
$db
$cookie
$errorList
N/A
No private methods found
No private properties found
N/A

Constants

VERSION

VERSION

Class Version

Properties

$_data

$_data : array

Type

array — - The user information object

$_updates

$_updates : \ptejada\uFlex\Collection

Type

\ptejada\uFlex\Collection — - Updates for the user information object

$errorList

$errorList : array

Type

array — Array of errors text. Could use overwritten for multilingual support

Methods

__construct()

__construct(array $userData)

Initializes the the User object

Parameters

array $userData

addValidation()

addValidation(string|array $name, string $limit, string|bool $regEx) : null

Adds validation to queue for either the Registration or Update Method Single Entry: Requires the first two parameters $name = string (name of the field to be validated) $limit = string (range of the accepted value length in the format of "5-10") - to make a field optional start with 0 (Ex. "0-10") Optional third parameter $regEx = string (Regular Expression to test the field) _____________________________________________________________________________________________________ Multiple Entry:

Takes only the first argument

   $name = Array Object (takes an object in the following format:
       array(
           "Username" => array(
                   "limit" => "3-15",
                   "regEx" => "/^([a-zA-Z0-9_])+$/"
                   ),
           "Password" => array(
                   "limit" => "3-15",
                   "regEx" => false
                   )
           );

Parameters

string|array $name

Name of the field to validate or an array of all the fields and their validations

string $limit

A range of the accepted value length in the format of "5-10", to make a field optional

                       start with 0 (Ex. "0-10")
string|bool $regEx

Regular expression to the test the field with

Returns

null

getProperty()

getProperty(mixed $name) : mixed

Get the value of a user property

Parameters

mixed $name

Returns

mixed

__get()

__get(mixed $name) : mixed|null

Get the value of a user property

Parameters

mixed $name

Returns

mixed|null

__set()

__set(mixed $name, mixed $value)

Queues any updates to user properties

Parameters

mixed $name
mixed $value

toArray()

toArray() : array

Get all the user fields as an array

Returns

array

login()

login(string $identifier, string $password, bool $autoLogin) : bool

Restore the a user session or Login a with given credentials.

Parameters

string $identifier
  • Username or Email
string $password
  • Clear text password
bool $autoLogin
  • Flag whether to remember the user

Returns

bool

start()

start(bool $login) : $this

Starts and Configures the object

Parameters

bool $login

Flag whether to attempt to login or not

Returns

$this

logout()

logout() : void

Logout the user Logs out the current user and deletes any autologin cookies

isSigned()

isSigned() : bool

Check if a user currently signed-in

Returns

bool

register()

register(array|\ptejada\uFlex\Collection $info, bool $activation) : string|bool

Register A New User Takes two parameters, the first being required

Parameters

array|\ptejada\uFlex\Collection $info

An associative array, the index being the field name(column in database)and the value

                                its content(value)
bool $activation

Default is false, if true the user will need required further steps to activate account

                                Otherwise the account will be activated if registration succeeds

Returns

string|bool —

Returns activation hash if second parameter $activation is true

                   Returns true if second parameter $activation is false
                   Returns false on Error

update()

update(array|\ptejada\uFlex\Collection $updates) : bool

Validates and updates any field in the database for the current user Similar to the register method function in structure, this Method validates and updates any field in the database

Parameters

array|\ptejada\uFlex\Collection $updates

An associative array,

                             the index being the field name(column in database)
                             and the value its content(value)

Returns

bool —

Returns true on success anf false on error

resetPassword()

resetPassword(string $email) : \ptejada\uFlex\Collection|bool

Method to reset password, Returns confirmation code to reset password

Parameters

string $email

User email to reset password

Returns

\ptejada\uFlex\Collection|bool —

On Success it returns a Collection with the user's (Email,Username,ID,Confirmation)

                   which could then be use to construct the confirmation URL and Email.
                   On Failure it returns false

newPassword()

newPassword(string $hash, array $newPass) : bool

Changes a Password with a Confirmation hash from the pass_reset method This is for users that forget their passwords to change the signed in user password use ->update()

Parameters

string $hash

hash returned by the pass_reset() method

array $newPass

An array with indexes 'password' and 'password2' Example:

                     array(
                     [password] => pass123
                     [password2] => pass123
                     )

Returns

bool —

Returns true on a successful password change. Returns false on error

__destruct()

__destruct()

Destroys the session if the instance is a clone

activate()

activate(string $hash) : bool

Activates Account with a hash Takes Only and Only the URL parameter of a confirmation page which would be the hash returned by the register() method

Parameters

string $hash

Hash returned in the register method

Returns

bool —

Returns true account activation and false on failure

manageUser()

manageUser(int $id) : bool|\ptejada\uFlex\User

User factory Returns a clone of the User instance which allows simple user managing capabilities such as updating a user field, resetting its password and so on.

Parameters

int $id

Returns

bool|\ptejada\uFlex\User

Returns false if user does not exists in database

toCollection()

toCollection(mixed $data) : \ptejada\uFlex\Collection

Check if the data is a Collection if an array convert it to a Collection

Parameters

mixed $data

Returns

\ptejada\uFlex\Collection

validateAll()

validateAll(bool $includeAllRules) : bool

Validates All fields in _updates queue

Parameters

bool $includeAllRules
  • Will also run rules not validated

Returns

bool

validate()

validate(string $name, string $limit, bool|string $regEx) : bool

Validates a field in tmp_data

Parameters

string $name

field name

string $limit

valid value length range, Ex: '0-10'

bool|string $regEx

regular expression to test the field against

Returns

bool