Documentation

User extends SimpleModel Uses User, FWEdit, MakeGuard, HandleRole

A class implementing a RedBean model for User beans

Table of Contents

$roletype string
$editfields array
add() Add a User from a form - invoked by the AJAX bean operation OODBBean
isAdmin() Is this user an admin? bool
isActive() Is this user active? bool
isConfirmed() Is this user confirmed? bool
isDeveloper() Is this user a developer? bool
setPW() Set the user's password void
pwOK() Check a password bool
doConfirm() Set the email confirmation flag void
makeToken() Generate a token for this user that can be used as a unique id from a phone. string
startEdit() Setup for an edit void
edit() Handle an edit form for this user array
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!) bool
register() Do any extra registration stuff string[]
addData() Called from the "add" function when a new user is created. void
update() Function called when a user bean is updated - do error checking in here void
dofields() Handle editing of beans string[]
guard() Return the CSRFGuard inputs for inclusion in a form; string
checkrole() Check that user has one of a set of roles array
hasrole() Check for a role object|null
hasRoleByBean() Check for a role by bean object|null
delrole() Delete a role void
addrole() Add a role OODBBean
addRoleByBean() Add a role OODBBean
roles() Get all currently valid roles for this bean \RedBeanPHP\OODBBean[]
editroles() Deal with the role selecting part of a form void

Properties

$roletype

private string $roletype = \Config\Framework::ROLE

$editfields

private static array $editfields = ['email' => [TRUE, FALSE]]

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
Return values
OODBBean

isAdmin()

Is this user an admin?

public isAdmin( ) : bool
Return values
bool

isActive()

Is this user active?

public isActive( ) : 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

setPW()

Set the user's password

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

The password

pwOK()

Check a password

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

The password

Return values
bool

doConfirm()

Set the email confirmation flag

public doConfirm( ) : void

makeToken()

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

public makeToken( $url : string [, $device : string = '' ] ) : 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

startEdit()

Setup for an edit

public startEdit( $context : Context , $rest : string[] ) : void
Parameters
$context : Context

The context object

$rest : string[]

Any other values from the URL

Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

edit()

Handle an edit form for this user

public edit( $context : Context ) : array
Parameters
$context : Context

The context object

Return values
array

[TRUE if error, [error messages]]

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( $pw : string ) : bool
Parameters
$pw : string

The password

Tags
throws

If a bad password is detected this could be thrown

Return values
bool

register()

Do any extra registration stuff

public register( $context : Context ) : string[]

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

Parameters
$context : Context
Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
string[]

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

update()

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

public update( ) : void
Tags
throws

dofields()

Handle editing of beans

private dofields( $fdt : AccessBase ) : string[]
Parameters
$fdt : AccessBase

The formdata object from the context

Return values
string[]

guard()

Return the CSRFGuard inputs for inclusion in a form;

public guard( ) : string
Return values
string

checkrole()

Check that user has one of a set of roles

public checkrole( $roles : string[][] [, $or : bool = TRUE ] ) : array
Parameters
$roles : string[][]

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

$or : bool = TRUE

If TRUE then the condition is OR

Tags
todo

support nested AND/OR

Return values
array

hasrole()

Check for a role

public hasrole( $contextname : string , $rolename : string ) : 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( $rolecontext : OODBBean , $rolename : OODBBean|null ) : 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

delrole()

Delete a role

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

The name of a context...

$rolename : string

The name of a role....

Tags
throws

addrole()

Add a role

public addrole( $contextname : string , $rolename : string , $otherinfo : string , $start : string [, $end : string = '' ] ) : 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
Return values
OODBBean

addRoleByBean()

Add a role

public addRoleByBean( $rolecontext : OODBBean , $rolename : OODBBean , $otherinfo : string , $start : string [, $end : string = '' ] ) : 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

roles()

Get all currently valid roles for this bean

public roles( [ $all : bool = FALSE ] ) : \RedBeanPHP\OODBBean[]
Parameters
$all : bool = FALSE

If TRUE then include expired roles

Return values
\RedBeanPHP\OODBBean[]

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

Search results