\Auth

Authorization and current account control

Used to all auth purposes and getting current user info

Summary

Methods
Properties
Constants
__construct()
Init()
getTokenData()
User()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
newToken()
check()
record()
$token
$data
$init
N/A

Properties

$token

$token : string

Type

string — 64 symbols unique access key

$data

$data : array<mixed,mixed>

Type

array<mixed,mixed> — Current user info

$init

$init : boolean

Type

boolean — Checks if Auth() was already inited

Methods

__construct()

__construct(string  $act = '') 

Launch Auth system

Parameters

string $act

Navigator string

  • auth - New login. Uses user-passed credentials (login and password fields)
  • checkToken - Just check token without other instances
  • <empty> - Requires login

Throws

\apiException
  • [300] DB Error
  • [301] Invalid credentials for login
  • [302] There's no such token in DB

Examples

Auth could be called by statements
// If Auth test was requested
if (isset($secure['auth_test'])) {
    // Try to auth
    Auth();
    // If there's no exception - add a key
    $ra['auth_test'] = true;
}

Init()

Init() 

Prepare Auth system

Generates template for login system (Later used for current token data).

getTokenData()

getTokenData() : array

Get token, etc.

Get such data as token and verify status

Returns

array —

Token data

  • token - [string] 64-symbols length
  • verify - [boolean] if true - token is checked

User()

User(boolean  $r = false) : \User|array

Current user

Recieve current User object

If $r === true: User->get() will be returned, else - class User

Parameters

boolean $r

Return switcher

Returns

\User|array

newToken()

newToken(string  $l, string  $p) : boolean

New token

Auth with login and password

Parameters

string $l

Login

string $p

Password

Throws

\apiException
  • [300] DB Error
  • [301] Invalid credentials for login

Returns

boolean —

If true - login successful

check()

check(string  $t) : boolean

Check token

Checks if given token is correct

Parameters

string $t

64-symbols long token

Throws

\apiException
  • [302] Incorrect token

Returns

boolean —

If true - token is correct

record()

record(array  $data) : void

Write current user data

Saves current user to class field

Parameters

array $data

User's data