Skip to content

4.07. Authentication

ArachnidsGrip edited this page Apr 15, 2019 · 1 revision

The "eloquent" and "database" auth drives are still available, but w.eloquent brings a new wordpress driver to handle user authentication.

It is configurable on app/config/auth.php file which is pretty much the same as Laravel.

Auth manager

If you choose the wordpress driver the Auth facade will return a instance of Weloquent\Core\Auth\WpAuth. Internally it uses the WprdPress API, so every hook is still available.

Auth API

Auth::check() Determine if the current user is authenticated.

Auth::guest() Determine if the current user is a guest.

Auth::user() Get the currently authenticated user.

Auth::id() Get the ID for the currently authenticated user.

Auth::validate(array $credentials) Validate a user's credentials, but do not log in.

Auth::attempt(array $credentials = array(), $remember = false, $login = true, $secure = false) Attempt to authenticate a user using the given credentials.

Auth::logout() Log the user out of the application.

Auth::loginUsingId($id) Log the given user ID into the application.

Auth::getError() If Attempt returns false it returns the WpException object.

Auth::is(string|array $roles) Checks if the user is a certain role, or is one of many roles if passed an array.

Auth::can(string|array $capability, $args = null) Checks if the user is has a certain permission, or has one of many permissions if passed an array. $args is the WordPress arguments.

Auth::level(int $level, string $operator = '>=') Compare against the highest user level (deprecated by WordPress).

Example

$credentials = [
	'user_login'    => Input::get('user_login'),
	'user_password' => Input::get('user_password')
];

if (Auth::attempt($credentials))
{
	Redirect::to('/panel');
}
else
{
	Session::flash('error', Auth::getError()->getMessage());
	Redirect::to('/login');
}

Clone this wiki locally