UserService Class
Services for accessing the Users and logging in to the site. Located in the namespace Canteen\Services.
Item Index
Methods
- __call
- adduser
- autoDetectItem
- bindObject
- bindObjects
- call
- callByItem
- checkCookieLogin
- checkLogin
- checkSession
- clearExpiredSessions
- createSession
- field
- freezeUsername
- gateway
- getCaller
- getStack
- getUser
- getUser
- getUsers
- hasDefaultField
- install
- installItem
- installItems
- internalAdd
- internalGetAll
- internalGetByIndex
- internalGetTotalAll
- internalGetTotalByIndex
- internalRemoveByIndex
- internalUpdateByIndex
- parse
- privilege
- refresh
- registerItem
- removeUser
- reportAttempt
- service
- setPrepends
- setProperties
- setup
- setWhere
- template
- updateUser
- valueSet
- verify
- verifyField
- verifyResetPassword
Methods
__call
-
method
-
args
Override of the dynamic call method to call verify* methods, for instance if we're validating Name it would be $this->verifyName($value)
adduser
-
propertiesOrUsername
-
[email]
-
[password]
-
[firstName]
-
[lastName]
-
[privilege=Privilege::GUEST]
-
[isActive=true]
Add a user to the data base
Parameters:
-
propertiesOrUsername
Dictionary | StringThe collection of values to set or username
-
[email]
String optionalThe email address
-
[password]
String optionalThe unhashed plain password
-
[firstName]
String optionalThe first name
-
[lastName]
String optionalThe last name
-
[privilege=Privilege::GUEST]
Int optionalThe privilege
-
[isActive=true]
Boolean optionalIf the user is active
Returns:
If successfully return a new ID, or else false
autoDetectItem
-
method
Auto detect the item name based on the name of the method that called it
Parameters:
-
method
StringThe name of the method
Returns:
Returns the item or throw error
bindObject
-
data
-
dataClass
-
[prepends=null]
-
[useFirstRow=true]
Bind an associate array to a data object
Parameters:
-
data
ArrayThe data to bind
-
dataClass
StringThe name of the data class (string to bind)
-
[prepends=null]
Array optionalThe array of maps to prepend to the variables used for prepending a path or directory to a file/path/url
-
[useFirstRow=true]
Boolean optionalIf to just return the row in a return, only getting one item from a mysql array call
Returns:
The typed data object
bindObjects
-
data
-
dataClass
-
[prepends=null]
Same as bindObject but done on a whole collection
Parameters:
Returns:
The data object
call
-
[args*]
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 optionalThe collection of arguments
callByItem
-
item
-
method
-
args
Generally called for calling the item methods
Parameters:
-
item
ObjectServiceItemThe item to call for
-
method
StringThe method name to call
-
args
ArrayThe collection of additional arguments
Returns:
The result of the method call
checkCookieLogin
-
userId
-
The
Check the cookie for authentication
Parameters:
-
userId
IntThe user's id
-
The
Stringsaved session ID
Returns:
The user if there's a saved session
checkLogin
-
usernameOrEmail
-
password
-
[isPasswordHashed=false]
Check the user login
Parameters:
checkSession
-
username
-
passwordHash
-
sessionId
-
ipAddress
Check the user's session
Parameters:
Returns:
The user if successful, null if not
clearExpiredSessions
-
id
-
idledSec
Clear all expired sessions
Parameters:
-
id
IntUser's ID
-
idledSec
IntThe number of idled seconds
Returns:
If successful cleared sessions
createSession
-
id
-
sessionId
-
ipAddress
Clear the status
Parameters:
Returns:
If successful
field
-
id
-
[type=null]
-
[name=null]
Convenience function for creating a new field
Parameters:
Returns:
The new custom field object
freezeUsername
-
username
-
frozenMins
Freeze the username after the user has failed-out the max number of login attempts
Parameters:
-
username
StringThe username
-
frozenMins
IntNumber of minutes to freeze before the user can try again
Returns:
If successful
gateway
-
uri
-
method
-
[privilege=Privilege::ANONYMOUS]
Add for use on the Gateway, these methods can be
called from javascript. For an example see the
TimeService
class.
Parameters:
Returns:
Return the instance of this for chaining
getCaller
-
[ignore=1]
Get the method/function name of the caller function
Parameters:
-
[ignore=1]
Int optionalThe depth of the call, default is the immediate function before this one is called
getStack
-
[limit=0]
-
[ignore=1]
Get the method/function name of the caller function
Parameters:
-
[limit=0]
Int optionalThe number of stack items to return, default is all
-
[ignore=1]
Int optionalThe number of stack levesl to ignore, default is the immediate function before this one is called.
getUser
-
usernameOrEmail
Get a user or users by email addresses or usernames
Parameters:
Returns:
The User object or collection of User objects
getUser
-
id
Get a user or user by id
Parameters:
-
id
Int | ArrayEither a single user ID or an array of IDs
hasDefaultField
-
method
Get the default part of the property name
Parameters:
-
method
StringThe name of the default method (without "ByField")
install
()
Boolean
protected
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:
If the install was successful
installItem
-
item
Auto install the service item
Parameters:
-
item
ObjectServiceItemRegistered item
Returns:
If item was installed successfully
installItems
-
items
Auto install multiple service items
Parameters:
-
items
Array | ObjectServiceItemRegistered items as different arguments or as a collection of ObjectServiceItems
Returns:
If item was installed successfully
internalAdd
-
item
-
properties
Conviencence method to inserting a new row into a table, this does all the field validation and insert.
Parameters:
-
item
ObjectServiceItemThe item to use
-
properties
Dictionary | ObjectThe collection map of field names to values
Returns:
The result
internalGetAll
-
item
-
[lengthOrIndex=null]
-
[duration=null]
Internal getting a collection of items
Parameters:
-
item
ObjectServiceItemThe item definition
-
[lengthOrIndex=null]
Int optionalThe starting index or elements to return
-
[duration=null]
Int optionalThe duration of the items
Returns:
The collection of objects
internalGetByIndex
-
item
-
index
-
isSingle
-
search
-
[lengthOrIndex=null]
-
[duration=null]
Internal method for getting result by an index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
isSingle
BooleanIf the index search is a single
-
search
Array | MixedThe value to search on
-
[lengthOrIndex=null]
Int optionalThe starting index or elements to return
-
[duration=null]
Int optionalThe duration of the items
internalGetTotalAll
-
item
Internal getting a total number of items
Parameters:
-
item
ObjectServiceItemThe item definition
Returns:
The number of items in selection
internalGetTotalByIndex
-
item
-
index
-
isSingle
-
search
Internal method for getting result by an index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
isSingle
BooleanIf the index search is a single
-
search
Array | MixedThe value to search on
internalRemoveByIndex
-
item
-
index
-
search
The internal remove of items by index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
search
Array | MixedThe value to search on
Returns:
If the remove was successful
internalUpdateByIndex
-
item
-
index
-
search
-
prop
-
[value=null]
The internal remove of items by index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
search
MixedThe value to search on
-
prop
Dictionary | StringThe property name or map of properties to update
-
[value=null]
Mixed optionalIf updating a single property, the property name
Returns:
If the remove was successful
parse
-
content
-
substitutions
Convenience method for parsing content
Parameters:
-
content
StringThe string to parse
-
substitutions
DictionaryThe dictionary of tags to replace
Returns:
The parsed string
privilege
-
[required=Privilege::GUEST]
You can run to make sure a process requires a particular privilege
Parameters:
-
[required=Privilege::GUEST]
Int optionalThe privilege level required, default is anonymous
refresh
-
id
Update the last login point on the user's table
Parameters:
-
id
IntThe user id
Returns:
if successful
registerItem
-
className
-
table
-
field
-
itemName
-
itemsName
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:
Returns:
The new service definition created
removeUser
-
id
Remove a user by an id
Parameters:
-
id
Int | ArrayThe user id or collection of IDs
Returns:
If successfully deleted
reportAttempt
-
username
The user attempted another failed try to login
Parameters:
-
username
StringThe username
Returns:
if successful
service
-
alias
Get a service by alias
Parameters:
-
alias
StringThe alias
Returns:
The service matching the alias
setPrepends
-
maps
-
[value=null]
Set the collection or single prepend the field value
Parameters:
Returns:
The instance of this class, for chaining
setProperties
-
[props=null]
Set additional selection properties not part of the field set
Parameters:
Returns:
The instance of this class, for chaining
setup
-
username
-
email
-
password
-
firstName
-
lastName
Install the table for the first time.
Parameters:
Returns:
if successfully installed
setWhere
-
args
Register additional where clauses for the SQL select on get methods
Parameters:
Returns:
The instance of this class, for chaining
template
-
name
-
[substitutions=[]
Convenience method for parsing content
Parameters:
-
name
StringThe name of the template to parse
-
[substitutions=[]
Dictionary optionalThe dictionary of tags to replace
Returns:
The parsed string
updateUser
-
id
-
prop
-
[value=null]
Update a user property or properties
Parameters:
-
id
IntThe user id
-
prop
String | DictionaryThe property name or an array of property => value
-
[value=null]
Mixed optionalThe value to update to if we're updating a single property
Returns:
If successful
valueSet
-
A
-
[validationType=null]
Get a set of ids
Parameters:
Returns:
The MySQL formatted set of IDs
verify
-
data
-
[type=null]
-
[suppressErrors=false]
Sanitize input data using the validation types above
Parameters:
Returns:
If we don't verify and suppress errors, returns false, else returns the data
verifyField
-
item
-
name
-
[value=null]
The more manual method for verifying a field value.
Parameters:
-
item
ObjectServiceItemRegistered item
-
name
Dictionary | StringThe name of the field or a map of name=>values
-
[value=null]
Mixed optionalThe value to check against
Returns:
The instance of this object for chaining
Properties
db
Database
Convenience getter for the database connection
items
Dictionary
The dictionary of item names to ObjectServiceItem objects
parser
Parser
The parser is responsible for rendering templates
prepends
Dictionary
The list of prepend map
profiler
Profiler
The instance of the profiler for debugging performance