Class uFlex

 Methods

Activates Account with a hash

activate(string $hash) : bool
API

Takes Only and Only the URL parameter of a confirmation page which would be the hash returned by the register method

access public
api

Parameters

$hash

string

Hash returned in the register method

Returns

boolReturns true account activation and false on failure

Adds validation to queue for either the Registration or Update Method

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

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
                        )
                );
access public
api

Parameters

$name

stringarray

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

$limit

string

A range of the accepted value length in the format of "5-10", to make a field optional start with 0 (Ex. "0-10")

$regEx

stringbool

Regular expression to the test the field with

Returns

null

Test field value in database

check_field(string $field, string | int $val, bool | string $err) : bool

Check for the uniqueness of a value in a specified field/column. For example could be use to check for the uniqueness of a username or email prior to registration

Parameters

$field

string

The name of the field

$val

stringint

The value for the field to check

$err

boolstring

Custom error string to log if field value is not unique

Returns

bool

Checks and validates a confirmation hash

check_hash(string $hash, bool $bypass) : bool

Parameters

$hash

string

hashed string to check

$bypass

bool

bypass hash confirmation and get the user by partially matching its password

Returns

bool

Executes SQL query and checks for success

check_sql(string $sql, bool | array $args) : bool

Parameters

$sql

string

SQL query string

$args

boolarray

Array of arguments to execute $sql with

Returns

bool

Add an error log entry

error(string | bool $str) : bool | array

Parameters

$str

stringbool

Text information, default is false

Returns

boolarrayIf $str is false returns the array of errors in the current logger

Add a form field error log entry

form_error(string | bool $field, string | bool $error) : bool | array

Parameters

$field

stringbool

Field name, default is false

$error

stringbool

Text information, default is false

Returns

boolarrayIf $field and $error is false returns the array of form field error in the current logger

Get a single user row depending on arguments

getRow(array $args) : bool | mixed

Parameters

$args

array

field and value pair set to look up user for

Returns

boolmixed

Get a PDO statement

getStatement(string $sql, bool | mixed[] $args) : bool | \PDOStatement

Parameters

$sql

string

SQL query string

$args

boolmixed[]

argument to execute the statement with

Returns

Check if there is an error in the current logger

has_error(bool | string $index) : bool

Parameters

$index

boolstring

Stack name to look for errors

Returns

bool

Log the type of request being initialized and log with the error amd report methods

logger(string $log) : object

Parameters

$log

string

Request name

Returns

objectSelf $this object

Logout the user

logout() : void

Logs out the current user and deletes any autologin cookies

Changes a Password with a Confirmation hash from the pass_reset method

new_pass(string $hash, array $newPass) : bool
API

This is for users that forget their passwords to change the signed in user password use ->update()

access public
api

Parameters

$hash

string

hash returned by the pass_reset() method

$newPass

array

An array with indexes 'password' and 'password2' Example: array( [password] => pass123 [password2] => pass123 )

Returns

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

Method to reset password, Returns confirmation code to reset password

pass_reset(string $email) : array | bool
API
access public
api

Parameters

$email

string

User email to reset password

Returns

arrayboolOn Success it returns an array(email,username,user_id,hash) which could then be use to construct the confirmation URL and Email. On Failure it returns false

Register A New User

register(array $info, bool $activation) : array | bool
API

Takes two parameters, the first being required

access public
api

Parameters

$info

array

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

$activation

bool

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

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

Add a report log entry

report(string | bool $str) : bool | mixed[]

Parameters

$str

stringbool

Text information, default is false

Returns

boolmixed[]If $str is false returns the array of reports in the current logger

Manage the session uFlex object variables

session(string | array | bool $index, mixed[] | bool $val) : bool | mixed[]

This method has many functions: session([String]) => Get the value of the index session([String], [String|mixed]) => Set the specified index with the given value session([Array]) => Overwrite the whole uFlex session space with a given array

Parameters

$index

stringarraybool

Session index to get or set

$val

mixed[]bool

The value to the set the $index with

Returns

boolmixed[]

Public function to start a delayed constructor

start() : void
API

When you initialize the class like new uFlex(false) the object construction will be halted until this method is called.

access public
api

Validates and updates any field in the database for the current user

update(array $info) : bool
API

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

access public
api

Parameters

$info

array

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

Returns

boolReturns true on success anf false on error

Connects to the database

connect() : bool

Check if the database connection exists if not connects to the database

Returns

bool

Decodes a string into an integer

decode(string $d) : int

Parameters

$d

string

string to decode into an integer

Returns

int

Encodes an integer

encode(int $d) : string

Parameters

$d

int

integer to encode

Returns

stringencoded integer string

Generates a unique confirm hash

make_hash(int $uid, bool | string $hash) : string

Parameters

$uid

int

user id

$hash

boolstring

optional hash to implement

Returns

string

Saves the confirmation hash in the database

save_hash(bool $activated) : bool

Parameters

$activated

bool

whether to set the user as activate or not

Returns

bool

Set the autologin cookie for the current user

setCookie() 

Validates a field in tmp_data

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

Parameters

$name

string

field name

$limit

string

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

$regEx

boolstring

regular expression to test the field against

Returns

bool

Validates All fields in ->tmp_data array

validateAll() 

 Properties

 

Holds the hash for any type of confirmation

$confirm : string
 

Container to hold errors and reports

$console : array
 

Holds entire user database row as an associative array

$data : array
 

An array of database credentials or a PDO object if connected to the database

$db : \PDO | array
 

Array of errors text. Could use overwritten for multilingual support

$errorList : array
 

Current user ID

$id : int
 

$opt : array

Array of internal options:

[table_name]: Name of the users table
[cookie_time]: Autologin cookie lifetime
[cookie_name]: Autologin cookie name
[cookie_path]: Autologin cookie path
[cookie_host]: Autologin cookie host
[user_session]: $_SESSION index to use
[default_user]: An associative array with properties of the default array
 

Holds the user password hash

$pass : string
 

Current User PHP Session ID

$sid : string
 

Flag of weather a user is signed-in or not

$signed : bool
 

Holds the temporary user information during registration and other methods

$tmp_data : array
 

Current user username

$username : string
 

Array for default field validations

$validations : array
 

Pointer for tracking errors and reports in the console

$log : string

 Constants

 

Class Version

version : int