Documentation

User extends SimpleModel
in package
Uses User, FWEdit, MakeGuard, HandleRole

A class implementing a RedBean model for User beans

Tags
psalm-suppress

UnusedClass

Table of Contents

$editfields  : array<string|int, mixed>
$roletype  : string
add()  : OODBBean
Add a User from a form - invoked by the AJAX bean operation
addData()  : void
Called from the "add" function when a new user is created.
addrole()  : OODBBean
Add a role
addRoleByBean()  : OODBBean
Add a role
checkrole()  : array<string|int, mixed>
Check that user has one of a set of roles
delrole()  : void
Delete a role
doConfirm()  : void
Set the email confirmation flag
edit()  : array<string|int, mixed>
Handle an edit form for this user
editroles()  : void
Deal with the role selecting part of a form
guard()  : string
Return the CSRFGuard inputs for inclusion in a form;
hasrole()  : object|null
Check for a role
hasRoleByBean()  : object|null
Check for a role by bean
isActive()  : bool
Is this user active?
isAdmin()  : bool
Is this user an admin?
isConfirmed()  : bool
Is this user confirmed?
isDeveloper()  : bool
Is this user a developer?
makeToken()  : string
Generate a token for this user that can be used as a unique id from a phone.
pwOK()  : bool
Check a password
pwValid()  : bool
A function to ensure that any relevant password rules are applied when setting a new password. Defaults to be not-empty. Modify this method if you want to implement particular password rules. (Length is really the only thing you should be testing though!)
register()  : array<string|int, string>
Do any extra registration stuff
roles()  : array<string|int, OODBBean>
Get all currently valid roles for this bean
setPW()  : void
Set the user's password
startEdit()  : void
Setup for an edit
update()  : void
Function called when a user bean is updated - do error checking in here
dofields()  : array<string|int, string>
Handle editing of beans

Properties

$editfields

private static array<string|int, mixed> $editfields = ['email' => [TRUE, FALSE]]
Tags
phpcsSuppress

SlevomatCodingStandard.Classes.UnusedPrivateElements

$roletype

private string $roletype = ConfigFramework::ROLE
Tags
phpcsSuppress

SlevomatCodingStandard.Classes.UnusedPrivateElements

Methods

add()

Add a User from a form - invoked by the AJAX bean operation

public static add(Context $context) : OODBBean
Parameters
$context : Context

The context object for the site

Tags
throws
BadValue
Return values
OODBBean

addData()

Called from the "add" function when a new user is created.

public addData(Context $context) : void

This allows you to do any extra operations that you want to when a user is added

Parameters
$context : Context
Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
void

addrole()

Add a role

public addrole(string $contextname, string $rolename, string $otherinfo, string $start[, string $end = '' ]) : OODBBean
Parameters
$contextname : string

The name of a context...

$rolename : string

The name of a role....

$otherinfo : string

Any other info that is to be stored with the role

$start : string

A datetime

$end : string = ''

A datetime or ''

Tags
throws
BadValue
Return values
OODBBean

addRoleByBean()

Add a role

public addRoleByBean(OODBBean $rolecontext, OODBBean $rolename, string $otherinfo, string $start[, string $end = '' ]) : OODBBean
Parameters
$rolecontext : OODBBean

Contextname

$rolename : OODBBean

Rolename

$otherinfo : string

Any other info that is to be stored with the role

$start : string

A datetime

$end : string = ''

A datetime or ''

Return values
OODBBean

checkrole()

Check that user has one of a set of roles

public checkrole(array<string|int, array<string|int, string>> $roles[, bool $or = TRUE ]) : array<string|int, mixed>
Parameters
$roles : array<string|int, array<string|int, string>>

[['context', 'role'],...]]

$or : bool = TRUE

If TRUE then the condition is OR

Tags
todo

support nested AND/OR

Return values
array<string|int, mixed>

delrole()

Delete a role

public delrole(string $contextname, string $rolename) : void
Parameters
$contextname : string

The name of a context...

$rolename : string

The name of a role....

Tags
throws
BadValue
Return values
void

doConfirm()

Set the email confirmation flag

public doConfirm() : void
Return values
void

edit()

Handle an edit form for this user

public edit(Context $context) : array<string|int, mixed>
Parameters
$context : Context

The context object

Return values
array<string|int, mixed>

[TRUE if error, [error messages]]

editroles()

Deal with the role selecting part of a form

public editroles(Context $context) : void
Parameters
$context : Context

The context object

Tags
psalm-suppress

UndefinedClass

Return values
void

guard()

Return the CSRFGuard inputs for inclusion in a form;

public guard() : string
Return values
string

hasrole()

Check for a role

public hasrole(string $contextname, string $rolename) : object|null
Parameters
$contextname : string

The name of a context...

$rolename : string

The name of a role - if this is the empty string then having the context is enough

Return values
object|null

hasRoleByBean()

Check for a role by bean

public hasRoleByBean(OODBBean $rolecontext, OODBBean|null $rolename) : object|null
Parameters
$rolecontext : OODBBean

A rolecontext

$rolename : OODBBean|null

A rolename - if this is NULL having the context is enough

Return values
object|null

isActive()

Is this user active?

public isActive() : bool
Return values
bool

isAdmin()

Is this user an admin?

public isAdmin() : bool
Return values
bool

isConfirmed()

Is this user confirmed?

public isConfirmed() : bool
Return values
bool

isDeveloper()

Is this user a developer?

public isDeveloper() : bool
Return values
bool

makeToken()

Generate a token for this user that can be used as a unique id from a phone.

public makeToken(string $url[, string $device = '' ]) : string
Parameters
$url : string

The URL of the site

$device : string = ''

Currently not used!!

Tags
psalm-suppress

UnusedVariable

phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
string

pwOK()

Check a password

public pwOK(string $pw) : bool
Parameters
$pw : string

The password

Return values
bool

pwValid()

A function to ensure that any relevant password rules are applied when setting a new password. Defaults to be not-empty. Modify this method if you want to implement particular password rules. (Length is really the only thing you should be testing though!)

public static pwValid(string $pw) : bool
Parameters
$pw : string

The password

Tags
throws
BadValue

If a bad password is detected this could be thrown

Return values
bool

register()

Do any extra registration stuff

public register(Context $context) : array<string|int, string>

Returns an array of error messages or an empty array if OK

Parameters
$context : Context
Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
array<string|int, string>

roles()

Get all currently valid roles for this bean

public roles([bool $all = FALSE ]) : array<string|int, OODBBean>
Parameters
$all : bool = FALSE

If TRUE then include expired roles

Return values
array<string|int, OODBBean>

setPW()

Set the user's password

public setPW(string $pw) : void
Parameters
$pw : string

The password

Return values
void

startEdit()

Setup for an edit

public startEdit(Context $context, array<string|int, string> $rest) : void
Parameters
$context : Context

The context object

$rest : array<string|int, string>

Any other values from the URL

Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
void

update()

Function called when a user bean is updated - do error checking in here

public update() : void
Tags
throws
BadValue
Return values
void

dofields()

Handle editing of beans

private dofields(AccessBase $fdt) : array<string|int, string>
Parameters
$fdt : AccessBase

The formdata object from the context

Return values
array<string|int, string>

Search results