API Documentation for: 1.1.1
Show:

UserService Class

Services for accessing the Users and logging in to the site. Located in the namespace Canteen\Services.

Methods

__call

(
  • method
  • args
)

Inherited from ObjectService

Override of the dynamic call method to call verify* methods, for instance if we're validating Name it would be $this->verifyName($value)

Parameters:

  • method String

    The name of the method to call

  • args Array

    The collection of arguments

adduser

(
  • propertiesOrUsername
  • [email]
  • [password]
  • [firstName]
  • [lastName]
  • [privilege=Privilege::GUEST]
  • [isActive=true]
)
Int | Boolean

Add a user to the data base

Parameters:

  • propertiesOrUsername Dictionary | String

    The collection of values to set or username

  • [email] String optional

    The email address

  • [password] String optional

    The unhashed plain password

  • [firstName] String optional

    The first name

  • [lastName] String optional

    The last name

  • [privilege=Privilege::GUEST] Int optional

    The privilege

  • [isActive=true] Boolean optional

    If the user is active

Returns:

Int | Boolean:

If successfully return a new ID, or else false

autoDetectItem

(
  • method
)
ObjectServiceItem private

Inherited from ObjectService:

Auto detect the item name based on the name of the method that called it

Parameters:

  • method String

    The name of the method

Returns:

ObjectServiceItem:

Returns the item or throw error

bindObject

(
  • data
  • dataClass
  • [prepends=null]
  • [useFirstRow=true]
)
Mixed protected

Inherited from Service:

Bind an associate array to a data object

Parameters:

  • data Array

    The data to bind

  • dataClass String

    The name of the data class (string to bind)

  • [prepends=null] Array optional

    The array of maps to prepend to the variables used for prepending a path or directory to a file/path/url

  • [useFirstRow=true] Boolean optional

    If to just return the row in a return, only getting one item from a mysql array call

Returns:

Mixed:

The typed data object

bindObjects

(
  • data
  • dataClass
  • [prepends=null]
)
Array protected

Inherited from Service:

Same as bindObject but done on a whole collection

Parameters:

  • data Array

    The data to bind

  • dataClass String

    The name of the data class (string to bind)

  • [prepends=null] Array optional

    The array of maps to prepend to the variables used for prepending a path or directory to a file/path/url

Returns:

Array:

The data object

call

(
  • [args*]
)
protected

Inherited from ObjectService

This allows for the internal dynamic calling of methods, the methods supported include getItems, getItem, updateItem, removeItem, getTotalItems, getTotalItem, getItemBy[IndexName], getTotalItemBy[IndexName], removeItemBy[IndexName], updateItemBy[IndexName].

Parameters:

  • [args*] Mixed optional

    The collection of arguments

callByItem

(
  • item
  • method
  • args
)
Mixed protected

Inherited from ObjectService:

Generally called for calling the item methods

Parameters:

Returns:

Mixed:

The result of the method call

checkCookieLogin

(
  • userId
  • The
)
User

Check the cookie for authentication

Parameters:

  • userId Int

    The user's id

  • The String

    saved session ID

Returns:

User:

The user if there's a saved session

checkLogin

(
  • usernameOrEmail
  • password
  • [isPasswordHashed=false]
)
User | Boolean

Check the user login

Parameters:

  • usernameOrEmail String

    The username or email address

  • password String

    The text password (can be either plain text or hashed)

  • [isPasswordHashed=false] Boolean optional

    If the password is hashed

Returns:

User | Boolean:

User object if true, or false if login failed

checkSession

(
  • username
  • passwordHash
  • sessionId
  • ipAddress
)
User

Check the user's session

Parameters:

  • username String

    The username

  • passwordHash String

    The password hash

  • sessionId String

    The unique PHP session ID

  • ipAddress String

    The ip address of the user

Returns:

User:

The user if successful, null if not

clearExpiredSessions

(
  • id
  • idledSec
)
Boolean

Clear all expired sessions

Parameters:

  • id Int

    User's ID

  • idledSec Int

    The number of idled seconds

Returns:

Boolean:

If successful cleared sessions

createSession

(
  • id
  • sessionId
  • ipAddress
)
Boolean

Clear the status

Parameters:

  • id Int

    The user id

  • sessionId String

    The unique PHP session id

  • ipAddress String

    The ip address of the login

Returns:

Boolean:

If successful

field

(
  • id
  • [type=null]
  • [name=null]
)
ObjectServiceField protected

Inherited from ObjectService:

Convenience function for creating a new field

Parameters:

  • id String

    The name of the field on the database

  • [type=null] RegExp | Array optional

    The validation type or set of values, default is no validation

  • [name=null] String optional

    The name of the php property

Returns:

ObjectServiceField:

The new custom field object

freezeUsername

(
  • username
  • frozenMins
)
Boolean

Freeze the username after the user has failed-out the max number of login attempts

Parameters:

  • username String

    The username

  • frozenMins Int

    Number of minutes to freeze before the user can try again

Returns:

Boolean:

If successful

gateway

(
  • uri
  • method
  • [privilege=Privilege::ANONYMOUS]
)
Service

Inherited from Service:

Add for use on the Gateway, these methods can be called from javascript. For an example see the TimeService class.

Parameters:

  • uri String

    The URI path to call from the gateway

  • method String

    The name of the method

  • [privilege=Privilege::ANONYMOUS] Int optional

    The minimum privilege needed for the client to access this method.

Returns:

Service:

Return the instance of this for chaining

getCaller

(
  • [ignore=1]
)
String | Array protected

Inherited from Service:

Get the method/function name of the caller function

Parameters:

  • [ignore=1] Int optional

    The depth of the call, default is the immediate function before this one is called

Returns:

String | Array:

The name of the method

getStack

(
  • [limit=0]
  • [ignore=1]
)
String | Array protected

Inherited from Service:

Get the method/function name of the caller function

Parameters:

  • [limit=0] Int optional

    The number of stack items to return, default is all

  • [ignore=1] Int optional

    The number of stack levesl to ignore, default is the immediate function before this one is called.

Returns:

String | Array:

The name of the method or full trace

getUser

(
  • usernameOrEmail
)
User

Get a user or users by email addresses or usernames

Parameters:

  • usernameOrEmail String | Array

    Either the username or email address or collection of usernames

Returns:

User:

The User object or collection of User objects

getUser

(
  • id
)
User | Array

Get a user or user by id

Parameters:

  • id Int | Array

    Either a single user ID or an array of IDs

Returns:

User | Array:

The User object or collection of User objects

getUsers

() Array

Get all of the current users

Returns:

Array:

A collection of User objects

hasDefaultField

(
  • method
)
private

Inherited from ObjectService:

Get the default part of the property name

Parameters:

  • method String

    The name of the default method (without "ByField")

install

() Boolean protected

Inherited from SimpleObjectService:

Use the install method that comes built-in, this is experimental and may not set the best default data type on the table. It's encouraged that manual adjustments are made afterwards.

Returns:

Boolean:

If the install was successful

installItem

(
  • item
)
Boolean protected

Inherited from ObjectService:

Auto install the service item

Parameters:

Returns:

Boolean:

If item was installed successfully

installItems

(
  • items
)
Boolean protected

Inherited from ObjectService:

Auto install multiple service items

Parameters:

  • items Array | ObjectServiceItem

    Registered items as different arguments or as a collection of ObjectServiceItems

Returns:

Boolean:

If item was installed successfully

internalAdd

(
  • item
  • properties
)
Int protected

Inherited from ObjectService:

Conviencence method to inserting a new row into a table, this does all the field validation and insert.

Parameters:

  • item ObjectServiceItem

    The item to use

  • properties Dictionary | Object

    The collection map of field names to values

Returns:

Int:

The result

internalGetAll

(
  • item
  • [lengthOrIndex=null]
  • [duration=null]
)
Array private

Inherited from ObjectService:

Internal getting a collection of items

Parameters:

  • item ObjectServiceItem

    The item definition

  • [lengthOrIndex=null] Int optional

    The starting index or elements to return

  • [duration=null] Int optional

    The duration of the items

Returns:

Array:

The collection of objects

internalGetByIndex

(
  • item
  • index
  • isSingle
  • search
  • [lengthOrIndex=null]
  • [duration=null]
)
Array | Object private

Inherited from ObjectService:

Internal method for getting result by an index

Parameters:

  • item ObjectServiceItem

    The item definition

  • index ObjectServiceField

    The index field to search on

  • isSingle Boolean

    If the index search is a single

  • search Array | Mixed

    The value to search on

  • [lengthOrIndex=null] Int optional

    The starting index or elements to return

  • [duration=null] Int optional

    The duration of the items

Returns:

Array | Object:

The collection of objects or a single object matching the className from the constuction

internalGetTotalAll

(
  • item
)
Int private

Inherited from ObjectService:

Internal getting a total number of items

Parameters:

Returns:

Int:

The number of items in selection

internalGetTotalByIndex

(
  • item
  • index
  • isSingle
  • search
)
Array | Object private

Inherited from ObjectService:

Internal method for getting result by an index

Parameters:

Returns:

Array | Object:

The collection of objects or a single object matching the className from the constuction

internalRemoveByIndex

(
  • item
  • index
  • search
)
Boolean private

Inherited from ObjectService:

The internal remove of items by index

Parameters:

Returns:

Boolean:

If the remove was successful

internalUpdateByIndex

(
  • item
  • index
  • search
  • prop
  • [value=null]
)
Boolean private

Inherited from ObjectService:

The internal remove of items by index

Parameters:

  • item ObjectServiceItem

    The item definition

  • index ObjectServiceField

    The index field to search on

  • search Mixed

    The value to search on

  • prop Dictionary | String

    The property name or map of properties to update

  • [value=null] Mixed optional

    If updating a single property, the property name

Returns:

Boolean:

If the remove was successful

parse

(
  • content
  • substitutions
)
String protected

Inherited from CanteenBase

Convenience method for parsing content

Parameters:

  • content String

    The string to parse

  • substitutions Dictionary

    The dictionary of tags to replace

Returns:

String:

The parsed string

privilege

(
  • [required=Privilege::GUEST]
)
protected

Inherited from Service:

You can run to make sure a process requires a particular privilege

Parameters:

  • [required=Privilege::GUEST] Int optional

    The privilege level required, default is anonymous

refresh

(
  • id
)
Boolean

Update the last login point on the user's table

Parameters:

  • id Int

    The user id

Returns:

Boolean:

if successful

registerItem

(
  • className
  • table
  • field
  • itemName
  • itemsName
)
ObjectServiceItem protected

Inherited from ObjectService:

Add a new Item definition to the service. This is required before using any of the methods for updating, getting, removing. Located in the namespace Canteen\Services.

Parameters:

  • className String

    Class to bind database result to

  • table String

    The name of the database table

  • field Array

    The collection of ObjectServiceField objects

  • itemName String

    The name of the item

  • itemsName String

    The name of the plural items

Returns:

ObjectServiceItem:

The new service definition created

removeUser

(
  • id
)
Boolean

Remove a user by an id

Parameters:

  • id Int | Array

    The user id or collection of IDs

Returns:

Boolean:

If successfully deleted

reportAttempt

(
  • username
)
Boolean

The user attempted another failed try to login

Parameters:

  • username String

    The username

Returns:

Boolean:

if successful

service

(
  • alias
)
Service protected

Inherited from CanteenBase:

Get a service by alias

Parameters:

Returns:

Service:

The service matching the alias

setPrepends

(
  • maps
  • [value=null]
)
ObjectService protected

Inherited from SimpleObjectService:

Set the collection or single prepend the field value

Parameters:

  • maps Dictionary | String

    If null, returns prepends Dictionary

  • [value=null] String optional

    The value if setting a single map

Returns:

ObjectService:

The instance of this class, for chaining

setProperties

(
  • [props=null]
)
ObjectService protected

Inherited from SimpleObjectService:

Set additional selection properties not part of the field set

Parameters:

  • [props=null] Array | String* optional

    N-number of strings to set as additional properties, or a collection of strings to add to the existing properties.

Returns:

ObjectService:

The instance of this class, for chaining

setup

(
  • username
  • email
  • password
  • firstName
  • lastName
)
Boolean

Install the table for the first time.

Parameters:

  • username String

    The admin username

  • email String

    The admin email address

  • password String

    The admin password

  • firstName String

    The admin first name

  • lastName String

    The admin last name

Returns:

Boolean:

if successfully installed

setWhere

(
  • args
)
ObjectService protected

Inherited from SimpleObjectService:

Register additional where clauses for the SQL select on get methods

Parameters:

  • args Array | String*

    The collection of extra SQL select where parameters to add to all get selections

Returns:

ObjectService:

The instance of this class, for chaining

template

(
  • name
  • [substitutions=[]
)
String protected

Inherited from CanteenBase:

Convenience method for parsing content

Parameters:

  • name String

    The name of the template to parse

  • [substitutions=[] Dictionary optional

    The dictionary of tags to replace

Returns:

String:

The parsed string

updateUser

(
  • id
  • prop
  • [value=null]
)
Boolean

Update a user property or properties

Parameters:

  • id Int

    The user id

  • prop String | Dictionary

    The property name or an array of property => value

  • [value=null] Mixed optional

    The value to update to if we're updating a single property

Returns:

Boolean:

If successful

valueSet

(
  • A
  • [validationType=null]
)
String protected

Inherited from Service:

Get a set of ids

Parameters:

  • A Array | String

    single id or a collection of IDs

  • [validationType=null] RegExp optional

    See Validation class for more information on types

Returns:

String:

The MySQL formatted set of IDs

verify

(
  • data
  • [type=null]
  • [suppressErrors=false]
)
Mixed protected

Inherited from Service:

Sanitize input data using the validation types above

Parameters:

  • data String

    The data to be validated, can be an array of items

  • [type=null] RegExp optional

    The type of validation, defaults to Numeric. Can also be an array set of items

  • [suppressErrors=false] Boolean optional

    If we should suppress throwing errors

Returns:

Mixed:

If we don't verify and suppress errors, returns false, else returns the data

verifyField

(
  • item
  • name
  • [value=null]
)
ObjectService protected

Inherited from ObjectService:

The more manual method for verifying a field value.

Parameters:

  • item ObjectServiceItem

    Registered item

  • name Dictionary | String

    The name of the field or a map of name=>values

  • [value=null] Mixed optional

    The value to check against

Returns:

ObjectService:

The instance of this object for chaining

verifyResetPassword

(
  • username
  • The
)
Boolean

Verify that the password has been reset

Parameters:

  • username String

    The username

  • The String

    forgot password string

Returns:

Boolean:

If the forgot string is valid

Properties

alias

String

Inherited from Service:

The name of the service alias

cache

ServerCache

Inherited from CanteenBase:

Get the instance of the site cache

className

String

Inherited from SimpleObjectService:

The name of the class to bind with

db

Database

Inherited from Service:

Convenience getter for the database connection

item

ObjectServiceItem protected

Inherited from SimpleObjectService

The item definition

items

Dictionary

Inherited from ObjectService:

The dictionary of item names to ObjectServiceItem objects

mappings

Array private

Inherited from Service:

The mappings used to prepend the data object paths

parser

Parser

Inherited from CanteenBase:

The parser is responsible for rendering templates

prepends

Dictionary

Inherited from SimpleObjectService:

The list of prepend map

profiler

Profiler

Inherited from CanteenBase:

The instance of the profiler for debugging performance

properties

Array

Inherited from SimpleObjectService:

The list of select properties

propertiesJoined

Array private

The list of user select table properties for joining tables

sessionsTable

String private

The table for who's session is currently active

settings

SettingsManager

Inherited from CanteenBase:

Get the instance of the settings manager

site

Site

Inherited from CanteenBase:

Convenience getter for the site

table

String

Inherited from SimpleObjectService:

The name of the table of the custom type

user

Authorization

Inherited from CanteenBase:

Get the Authorization class to handle things like login, password change