mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-03-13 21:49:40 +01:00
Fix referenced namespaces to be absolute or fully qualified
This commit is contained in:
parent
5a954ca13b
commit
90fe75c27e
32
README.md
32
README.md
@ -46,7 +46,7 @@ Completely framework-agnostic and database-agnostic.
|
||||
// $db = new PDO('mysql:dbname=database;host=localhost;charset=utf8', 'username', 'password');
|
||||
// $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$auth = new Delight\Auth\Auth($db);
|
||||
$auth = new \Delight\Auth\Auth($db);
|
||||
```
|
||||
|
||||
If you have an open `PDO` connection already, just re-use it.
|
||||
@ -67,16 +67,16 @@ try {
|
||||
|
||||
// we have signed up a new user with the ID `$userId`
|
||||
}
|
||||
catch (Delight\Auth\InvalidEmailException $e) {
|
||||
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||
// invalid email address
|
||||
}
|
||||
catch (Delight\Auth\InvalidPasswordException $e) {
|
||||
catch (\Delight\Auth\InvalidPasswordException $e) {
|
||||
// invalid password
|
||||
}
|
||||
catch (Delight\Auth\UserAlreadyExistsException $e) {
|
||||
catch (\Delight\Auth\UserAlreadyExistsException $e) {
|
||||
// user already exists
|
||||
}
|
||||
catch (Delight\Auth\TooManyRequestsException $e) {
|
||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||
// too many requests
|
||||
}
|
||||
```
|
||||
@ -99,16 +99,16 @@ try {
|
||||
|
||||
// user is logged in
|
||||
}
|
||||
catch (Delight\Auth\InvalidEmailException $e) {
|
||||
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||
// wrong email address
|
||||
}
|
||||
catch (Delight\Auth\InvalidPasswordException $e) {
|
||||
catch (\Delight\Auth\InvalidPasswordException $e) {
|
||||
// wrong password
|
||||
}
|
||||
catch (Delight\Auth\EmailNotVerifiedException $e) {
|
||||
catch (\Delight\Auth\EmailNotVerifiedException $e) {
|
||||
// email not verified
|
||||
}
|
||||
catch (Delight\Auth\TooManyRequestsException $e) {
|
||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||
// too many requests
|
||||
}
|
||||
```
|
||||
@ -125,13 +125,13 @@ try {
|
||||
|
||||
// email address has been verified
|
||||
}
|
||||
catch (Delight\Auth\InvalidSelectorTokenPairException $e) {
|
||||
catch (\Delight\Auth\InvalidSelectorTokenPairException $e) {
|
||||
// invalid token
|
||||
}
|
||||
catch (Delight\Auth\TokenExpiredException $e) {
|
||||
catch (\Delight\Auth\TokenExpiredException $e) {
|
||||
// token expired
|
||||
}
|
||||
catch (Delight\Auth\TooManyRequestsException $e) {
|
||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||
// too many requests
|
||||
}
|
||||
```
|
||||
@ -146,10 +146,10 @@ try {
|
||||
|
||||
// password has been changed
|
||||
}
|
||||
catch (Delight\Auth\NotLoggedInException $e) {
|
||||
catch (\Delight\Auth\NotLoggedInException $e) {
|
||||
// not logged in
|
||||
}
|
||||
catch (Delight\Auth\InvalidPasswordException $e) {
|
||||
catch (\Delight\Auth\InvalidPasswordException $e) {
|
||||
// invalid password(s)
|
||||
}
|
||||
```
|
||||
@ -228,13 +228,13 @@ $ip = $auth->getIpAddress();
|
||||
|
||||
```php
|
||||
$length = 24;
|
||||
$randomStr = Delight\Auth\Auth::createRandomString($length);
|
||||
$randomStr = \Delight\Auth\Auth::createRandomString($length);
|
||||
```
|
||||
|
||||
#### Create a UUID v4 as per RFC 4122
|
||||
|
||||
```php
|
||||
$uuid = Delight\Auth\Auth::createUuid();
|
||||
$uuid = \Delight\Auth\Auth::createUuid();
|
||||
```
|
||||
|
||||
## Features
|
||||
|
@ -25,7 +25,7 @@ $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
require __DIR__.'/../src/Auth.php';
|
||||
|
||||
$auth = new Delight\Auth\Auth($db);
|
||||
$auth = new \Delight\Auth\Auth($db);
|
||||
|
||||
$result = processRequestData($auth);
|
||||
|
||||
@ -38,7 +38,7 @@ else {
|
||||
showGuestUserForm();
|
||||
}
|
||||
|
||||
function processRequestData(Delight\Auth\Auth $auth) {
|
||||
function processRequestData(\Delight\Auth\Auth $auth) {
|
||||
if (isset($_POST)) {
|
||||
if (isset($_POST['action'])) {
|
||||
if ($_POST['action'] === 'login') {
|
||||
@ -47,16 +47,16 @@ function processRequestData(Delight\Auth\Auth $auth) {
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
catch (Delight\Auth\InvalidEmailException $e) {
|
||||
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||
return 'wrong email address';
|
||||
}
|
||||
catch (Delight\Auth\InvalidPasswordException $e) {
|
||||
catch (\Delight\Auth\InvalidPasswordException $e) {
|
||||
return 'wrong password';
|
||||
}
|
||||
catch (Delight\Auth\EmailNotVerifiedException $e) {
|
||||
catch (\Delight\Auth\EmailNotVerifiedException $e) {
|
||||
return 'email not verified';
|
||||
}
|
||||
catch (Delight\Auth\TooManyRequestsException $e) {
|
||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||
return 'too many requests';
|
||||
}
|
||||
}
|
||||
@ -83,16 +83,16 @@ function processRequestData(Delight\Auth\Auth $auth) {
|
||||
|
||||
return $auth->register($_POST['email'], $_POST['password'], $_POST['username'], $callback);
|
||||
}
|
||||
catch (Delight\Auth\InvalidEmailException $e) {
|
||||
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||
return 'invalid email address';
|
||||
}
|
||||
catch (Delight\Auth\InvalidPasswordException $e) {
|
||||
catch (\Delight\Auth\InvalidPasswordException $e) {
|
||||
return 'invalid password';
|
||||
}
|
||||
catch (Delight\Auth\UserAlreadyExistsException $e) {
|
||||
catch (\Delight\Auth\UserAlreadyExistsException $e) {
|
||||
return 'user already exists';
|
||||
}
|
||||
catch (Delight\Auth\TooManyRequestsException $e) {
|
||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||
return 'too many requests';
|
||||
}
|
||||
}
|
||||
@ -102,13 +102,13 @@ function processRequestData(Delight\Auth\Auth $auth) {
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
catch (Delight\Auth\InvalidSelectorTokenPairException $e) {
|
||||
catch (\Delight\Auth\InvalidSelectorTokenPairException $e) {
|
||||
return 'invalid token';
|
||||
}
|
||||
catch (Delight\Auth\TokenExpiredException $e) {
|
||||
catch (\Delight\Auth\TokenExpiredException $e) {
|
||||
return 'token expired';
|
||||
}
|
||||
catch (Delight\Auth\TooManyRequestsException $e) {
|
||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||
return 'too many requests';
|
||||
}
|
||||
}
|
||||
@ -118,10 +118,10 @@ function processRequestData(Delight\Auth\Auth $auth) {
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
catch (Delight\Auth\NotLoggedInException $e) {
|
||||
catch (\Delight\Auth\NotLoggedInException $e) {
|
||||
return 'not logged in';
|
||||
}
|
||||
catch (Delight\Auth\InvalidPasswordException $e) {
|
||||
catch (\Delight\Auth\InvalidPasswordException $e) {
|
||||
return 'invalid password(s)';
|
||||
}
|
||||
}
|
||||
@ -139,7 +139,7 @@ function processRequestData(Delight\Auth\Auth $auth) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function showDebugData(Delight\Auth\Auth $auth, $result) {
|
||||
function showDebugData(\Delight\Auth\Auth $auth, $result) {
|
||||
echo '<pre>';
|
||||
|
||||
echo 'Last operation'."\t\t\t\t";
|
||||
@ -171,9 +171,9 @@ function showDebugData(Delight\Auth\Auth $auth, $result) {
|
||||
echo "\n";
|
||||
|
||||
echo 'Auth::createRandomString()'."\t\t";
|
||||
var_dump(Delight\Auth\Auth::createRandomString());
|
||||
var_dump(\Delight\Auth\Auth::createRandomString());
|
||||
echo 'Auth::createUuid()'."\t\t\t";
|
||||
var_dump(Delight\Auth\Auth::createUuid());
|
||||
var_dump(\Delight\Auth\Auth::createUuid());
|
||||
|
||||
echo '</pre>';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user