PHP Class Flarum\Core\User

Inheritance: extends Flarum\Database\AbstractModel, use trait Flarum\Core\Support\EventGeneratorTrait, use trait Flarum\Core\Support\ScopeVisibilityTrait
Show file Open project: flarum/core Class Usage Examples

Protected Properties

Property Type Description
$dates
$gate Flarum\Core\Access\Gate The access gate.
$hasher Illuminate\Contracts\Hashing\Hasher The hasher with which to hash passwords.
$permissions string[] | null An array of permissions that this user has.
$preferences array - transformer: a callback that confines the value of the preference - default: a default value if the preference isn't set
$session Symfony\Component\HttpFoundation\Session\SessionInterface
$table

Public Methods

Method Description
accessTokens ( ) : Illuminate\Database\Eloquent\Relations\HasMany Define the relationship with the user's access tokens.
activate ( ) Activate the user's account.
addPreference ( string $key, callable $transformer = null, mixed $default = null ) Register a preference with a transformer and a default value.
boot ( ) : void Boot the model.
can ( string $ability, array | mixed $arguments = [] ) : boolean
cannot ( string $ability, array | mixed $arguments = [] ) : boolean
changeAvatarPath ( string $path ) Change the path of the user avatar.
changeBio ( string $bio ) Change the user's bio.
changeEmail ( string $email ) Change the user's email.
changePassword ( string $password ) Change the user's password.
checkPassword ( string $password ) : boolean Check if a given password matches the user's password.
getAlertableNotificationTypes ( ) : array Get the notification types that should be alerted to this user, according to their preferences.
getAvatarUrlAttribute ( ) : string Get the URL of the user's avatar.
getGate ( ) : Flarum\Core\Access\Gate
getLocaleAttribute ( string $value ) : string Get the user's locale, falling back to the forum's default if they haven't set one.
getNewNotificationsCount ( ) : integer Get the number of new, unseen notifications for the user.
getNotificationPreferenceKey ( string $type, string $method ) : string Get the key for a preference which flags whether or not the user will receive a notification for $type via $method.
getPermissions ( ) : string[] Get a list of permissions that the user has.
getPreference ( string $key, mixed $default = null ) : mixed Get the value of a preference for this user.
getPreferencesAttribute ( string $value ) : array Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.
getSession ( ) : Symfony\Component\HttpFoundation\Session\SessionInterface
getUnreadNotificationsCount ( ) : integer Get the number of unread notifications for the user.
groups ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany Define the relationship with the user's groups.
hasPermission ( string $permission ) : boolean Check whether the user has a certain permission based on their groups.
hasPermissionLike ( string $match ) : boolean Check whether the user has a permission that is like the given string, based on their groups.
isAdmin ( ) : boolean Check whether or not the user is an administrator.
isGuest ( ) : boolean Check whether or not the user is a guest.
markAllAsRead ( ) Mark all discussions as read.
markNotificationsAsRead ( ) Mark all notifications as read.
notifications ( ) : Illuminate\Database\Eloquent\Relations\HasMany Define the relationship with the user's notifications.
permissions ( ) : Builder Define the relationship with the permissions of all of the groups that the user is in.
posts ( ) : Illuminate\Database\Eloquent\Relations\HasMany Define the relationship with the user's posts.
read ( ) : BelongsTo Define the relationship with the user's read discussions.
register ( string $username, string $email, string $password ) : static Register a new user.
rename ( string $username ) Rename the user.
requestEmailChange ( string $email ) Request that the user's email be changed.
setGate ( Flarum\Core\Access\Gate $gate )
setHasher ( Illuminate\Contracts\Hashing\Hasher $hasher ) Set the hasher with which to hash passwords.
setPasswordAttribute ( string $value ) Set the password attribute, storing it as a hash.
setPreference ( string $key, mixed $value ) Set the value of a preference for this user.
setPreferencesAttribute ( mixed $value ) Encode an array of preferences for storage in the database.
setSession ( Symfony\Component\HttpFoundation\Session\SessionInterface $session )
shouldAlert ( string $type ) : boolean Check whether or not the user should receive an alert for a notification type.
shouldEmail ( string $type ) : boolean Check whether or not the user should receive an email for a notification type.
updateLastSeen ( ) Set the user as being last seen just now.

Protected Methods

Method Description
getUnreadNotifications ( ) : Illuminate\Database\Eloquent\Collection Get all notifications that have not been read yet.

Method Details

accessTokens() public method

Define the relationship with the user's access tokens.
public accessTokens ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany

activate() public method

Activate the user's account.
public activate ( )

addPreference() public static method

Register a preference with a transformer and a default value.
public static addPreference ( string $key, callable $transformer = null, mixed $default = null )
$key string
$transformer callable
$default mixed

boot() public static method

Boot the model.
public static boot ( ) : void
return void

can() public method

public can ( string $ability, array | mixed $arguments = [] ) : boolean
$ability string
$arguments array | mixed
return boolean

cannot() public method

public cannot ( string $ability, array | mixed $arguments = [] ) : boolean
$ability string
$arguments array | mixed
return boolean

changeAvatarPath() public method

Change the path of the user avatar.
public changeAvatarPath ( string $path )
$path string

changeBio() public method

Change the user's bio.
public changeBio ( string $bio )
$bio string

changeEmail() public method

Change the user's email.
public changeEmail ( string $email )
$email string

changePassword() public method

Change the user's password.
public changePassword ( string $password )
$password string

checkPassword() public method

Check if a given password matches the user's password.
public checkPassword ( string $password ) : boolean
$password string
return boolean

getAlertableNotificationTypes() public method

Get the notification types that should be alerted to this user, according to their preferences.

getAvatarUrlAttribute() public method

Get the URL of the user's avatar.
public getAvatarUrlAttribute ( ) : string
return string

getGate() public static method

public static getGate ( ) : Flarum\Core\Access\Gate
return Flarum\Core\Access\Gate

getLocaleAttribute() public method

Get the user's locale, falling back to the forum's default if they haven't set one.
public getLocaleAttribute ( string $value ) : string
$value string
return string

getNewNotificationsCount() public method

Get the number of new, unseen notifications for the user.

getNotificationPreferenceKey() public static method

Get the key for a preference which flags whether or not the user will receive a notification for $type via $method.
public static getNotificationPreferenceKey ( string $type, string $method ) : string
$type string
$method string
return string

getPermissions() public method

Get a list of permissions that the user has.
public getPermissions ( ) : string[]
return string[]

getPreference() public method

Get the value of a preference for this user.
public getPreference ( string $key, mixed $default = null ) : mixed
$key string
$default mixed
return mixed

getPreferencesAttribute() public method

Get the values of all registered preferences for this user, by transforming their stored preferences and merging them with the defaults.
public getPreferencesAttribute ( string $value ) : array
$value string
return array

getSession() public method

public getSession ( ) : Symfony\Component\HttpFoundation\Session\SessionInterface
return Symfony\Component\HttpFoundation\Session\SessionInterface

getUnreadNotifications() protected method

Get all notifications that have not been read yet.
protected getUnreadNotifications ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

getUnreadNotificationsCount() public method

Get the number of unread notifications for the user.

groups() public method

Define the relationship with the user's groups.
public groups ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany
return Illuminate\Database\Eloquent\Relations\BelongsToMany

hasPermission() public method

Check whether the user has a certain permission based on their groups.
public hasPermission ( string $permission ) : boolean
$permission string
return boolean

hasPermissionLike() public method

Check whether the user has a permission that is like the given string, based on their groups.
public hasPermissionLike ( string $match ) : boolean
$match string
return boolean

isAdmin() public method

Check whether or not the user is an administrator.
public isAdmin ( ) : boolean
return boolean

isGuest() public method

Check whether or not the user is a guest.
public isGuest ( ) : boolean
return boolean

markAllAsRead() public method

Mark all discussions as read.
public markAllAsRead ( )

markNotificationsAsRead() public method

Mark all notifications as read.

notifications() public method

Define the relationship with the user's notifications.
public notifications ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany

permissions() public method

Define the relationship with the permissions of all of the groups that the user is in.
public permissions ( ) : Builder
return Illuminate\Database\Eloquent\Builder

posts() public method

Define the relationship with the user's posts.
public posts ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany

read() public method

Define the relationship with the user's read discussions.
public read ( ) : BelongsTo
return Illuminate\Database\Eloquent\Relations\BelongsTo

register() public static method

Register a new user.
public static register ( string $username, string $email, string $password ) : static
$username string
$email string
$password string
return static

rename() public method

Rename the user.
public rename ( string $username )
$username string

requestEmailChange() public method

Request that the user's email be changed.
public requestEmailChange ( string $email )
$email string

setGate() public static method

public static setGate ( Flarum\Core\Access\Gate $gate )
$gate Flarum\Core\Access\Gate

setHasher() public static method

Set the hasher with which to hash passwords.
public static setHasher ( Illuminate\Contracts\Hashing\Hasher $hasher )
$hasher Illuminate\Contracts\Hashing\Hasher

setPasswordAttribute() public method

Set the password attribute, storing it as a hash.
public setPasswordAttribute ( string $value )
$value string

setPreference() public method

Set the value of a preference for this user.
public setPreference ( string $key, mixed $value )
$key string
$value mixed

setPreferencesAttribute() public method

Encode an array of preferences for storage in the database.
public setPreferencesAttribute ( mixed $value )
$value mixed

setSession() public method

public setSession ( Symfony\Component\HttpFoundation\Session\SessionInterface $session )
$session Symfony\Component\HttpFoundation\Session\SessionInterface

shouldAlert() public method

Check whether or not the user should receive an alert for a notification type.
public shouldAlert ( string $type ) : boolean
$type string
return boolean

shouldEmail() public method

Check whether or not the user should receive an email for a notification type.
public shouldEmail ( string $type ) : boolean
$type string
return boolean

updateLastSeen() public method

Set the user as being last seen just now.
public updateLastSeen ( )

Property Details

$dates protected property

protected $dates

$gate protected static property

The access gate.
protected static Gate,Flarum\Core\Access $gate
return Flarum\Core\Access\Gate

$hasher protected static property

The hasher with which to hash passwords.
protected static Hasher,Illuminate\Contracts\Hashing $hasher
return Illuminate\Contracts\Hashing\Hasher

$permissions protected property

An array of permissions that this user has.
protected string[]|null $permissions
return string[] | null

$preferences protected static property

- transformer: a callback that confines the value of the preference - default: a default value if the preference isn't set
protected static array $preferences
return array

$session protected property

protected SessionInterface,Symfony\Component\HttpFoundation\Session $session
return Symfony\Component\HttpFoundation\Session\SessionInterface

$table protected property

protected $table