1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-21 15:21:30 +02:00

Add method 'deleteUserById' and similar methods for email and username

This commit is contained in:
Marco
2017-02-25 17:32:35 +01:00
parent 63144d4dc0
commit 81bdd79906
3 changed files with 94 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ Completely framework-agnostic and database-agnostic.
* [Additional user information](#additional-user-information)
* [Administration (managing users)](administration-managing-users)
* [Creating new users](creating-new-users)
* [Deleting users](#deleting-users)
* [Utilities](#utilities)
* [Creating a random string](#creating-a-random-string)
* [Creating a UUID v4 as per RFC 4122](#creating-a-uuid-v4-as-per-rfc-4122)
@@ -391,6 +392,42 @@ The username in the third parameter is optional. You can pass `null` there if yo
If you want to enforce unique usernames, on the other hand, simply call `createUserWithUniqueUsername` instead of `createUser`, and be prepared to catch the `DuplicateUsernameException`.
#### Deleting users
```php
try {
$auth->admin()->deleteUserById($_POST['id']);
}
catch (\Delight\Auth\UnknownIdException $e) {
// unknown ID
}
```
or
```php
try {
$auth->admin()->deleteUserByEmail($_POST['email']);
}
catch (\Delight\Auth\InvalidEmailException $e) {
// unknown email address
}
```
or
```php
try {
$auth->admin()->deleteUserByUsername($_POST['username']);
}
catch (\Delight\Auth\UnknownUsernameException $e) {
// unknown username
}
catch (\Delight\Auth\AmbiguousUsernameException $e) {
// ambiguous username
}
```
### Utilities
#### Creating a random string