Leaf PHP

Auth
in package

Leaf Simple Auth ------------------------- Simple, lightweight authentication.

Tags
author

Michael Darko

since
1.5.0
version
3.0.0

Table of Contents

Properties

$db  : Db
Internal instance of Leaf DB
$errorsArray  : array<string|int, mixed>
All errors caught
$user  : User
The currently authenticated user

Methods

__construct()  : mixed
autoConnect()  : $this
Connect to database using environment variables
clearErrors()  : mixed
Clear all errors caught
config()  : mixed
Get/Set Leaf Auth config
connect()  : $this
Connect leaf auth to the database
createRoles()  : Auth
Create roles and permissions
createUserFor()  : mixed
Create a new user --- Create an account for another user
data()  : object|null
Get data generated on user login
db()  : Db
Return the current db instance
dbConnection()  : mixed
Pass in db connection instance directly
errors()  : array<string|int, mixed>
Return all errors caught
find()  : User|null
Find a user by id --- Select and return an existing user from db
fromOAuth()  : bool
Create a new user from OAuth
id()  : string|int
Get the id of the currently authenticated user
login()  : bool
Sign a user in --- Verify user credentials and sign them in with token or session
logout()  : bool
Sign a user out --- Sign out the currently authenticated user
middleware()  : mixed
Register auth middleware for your Leaf apps
oauthToken()  : mixed
Get saved OAuth token
parseToken()  : mixed
Parse the current user's token
register()  : bool
Register a new user --- Save a new user to the database
roles()  : array<string|int, mixed>
Return all roles and their permissions
tokens()  : array<string|int, mixed>|null
Get generated access tokens
update()  : bool
Update user data --- Update user data in the database
updatePassword()  : bool
Update user password --- Update user password in the database
user()  : User|null
Get the currently authenticated user
verifyToken()  : mixed
Verify a user's token
checkAndExpireSession()  : bool
checkDbConnection()  : void
getFromSession()  : mixed
getTokenFromRequest()  : mixed
getTokenFromSession()  : mixed
sessionCheck()  : mixed

Properties

$db

Internal instance of Leaf DB

protected Db $db

$errorsArray

All errors caught

protected array<string|int, mixed> $errorsArray = []

$user

The currently authenticated user

protected User $user

Methods

__construct()

public __construct() : mixed

autoConnect()

Connect to database using environment variables

public autoConnect([array<string|int, mixed> $pdoOptions = [] ]) : $this
Parameters
$pdoOptions : array<string|int, mixed> = []

Options for PDO connection

Return values
$this

clearErrors()

Clear all errors caught

public clearErrors() : mixed

config()

Get/Set Leaf Auth config

public config(string|array<string|int, mixed> $config[, mixed $value = null ]) : mixed
Parameters
$config : string|array<string|int, mixed>

The auth config key or array of config

$value : mixed = null

The value if $config is a string

connect()

Connect leaf auth to the database

public connect([array<string|int, mixed> $dbConfig = [] ]) : $this
Parameters
$dbConfig : array<string|int, mixed> = []

Configuration for leaf db connection

Return values
$this

createRoles()

Create roles and permissions

public createRoles(array<string|int, mixed> $roles) : Auth
Parameters
$roles : array<string|int, mixed>

Array of roles and their permissions

Return values
Auth

createUserFor()

Create a new user --- Create an account for another user

public createUserFor(mixed $userData) : mixed
Parameters
$userData : mixed

data()

Get data generated on user login

public data() : object|null
Return values
object|null

db()

Return the current db instance

public db() : Db
Return values
Db

dbConnection()

Pass in db connection instance directly

public dbConnection(PDO $connection) : mixed
Parameters
$connection : PDO

A connection instance of your db

Tags
@return

$this;

errors()

Return all errors caught

public errors() : array<string|int, mixed>
Return values
array<string|int, mixed>

find()

Find a user by id --- Select and return an existing user from db

public find(string|int $id) : User|null
Parameters
$id : string|int

The id of the user to grab

Return values
User|null

fromOAuth()

Create a new user from OAuth

public fromOAuth(array<string|int, mixed> $userData) : bool
Parameters
$userData : array<string|int, mixed>

User data

Return values
bool

id()

Get the id of the currently authenticated user

public id() : string|int
Return values
string|int

login()

Sign a user in --- Verify user credentials and sign them in with token or session

public login(array<string|int, mixed> $credentials) : bool
Parameters
$credentials : array<string|int, mixed>

User credentials

Return values
bool

logout()

Sign a user out --- Sign out the currently authenticated user

public logout([mixed $action = null ]) : bool
Parameters
$action : mixed = null
Return values
bool

middleware()

Register auth middleware for your Leaf apps

public middleware(string $middleware, callable $callback) : mixed
Parameters
$middleware : string

The middleware to register

$callback : callable

The callback to run if middleware fails

oauthToken()

Get saved OAuth token

public oauthToken() : mixed

parseToken()

Parse the current user's token

public parseToken() : mixed

register()

Register a new user --- Save a new user to the database

public register(array<string|int, mixed> $userData) : bool
Parameters
$userData : array<string|int, mixed>

User data

Return values
bool

roles()

Return all roles and their permissions

public roles() : array<string|int, mixed>
Return values
array<string|int, mixed>

tokens()

Get generated access tokens

public tokens() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

update()

Update user data --- Update user data in the database

public update(array<string|int, mixed> $userData) : bool
Parameters
$userData : array<string|int, mixed>

User data

Return values
bool

updatePassword()

Update user password --- Update user password in the database

public updatePassword(string $oldPassword, string $newPassword) : bool
Parameters
$oldPassword : string

Old password

$newPassword : string

New password

Return values
bool

user()

Get the currently authenticated user

public user() : User|null
Return values
User|null

verifyToken()

Verify a user's token

public verifyToken(string $token) : mixed
Parameters
$token : string

The token to verify

checkAndExpireSession()

protected checkAndExpireSession() : bool
Return values
bool

checkDbConnection()

protected checkDbConnection() : void

getFromSession()

protected getFromSession(mixed $value) : mixed
Parameters
$value : mixed

getTokenFromRequest()

protected getTokenFromRequest() : mixed

getTokenFromSession()

protected getTokenFromSession() : mixed

sessionCheck()

protected sessionCheck() : mixed

        
On this page

Search results