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

Add method 'registerWithUniqueUsername'

This commit is contained in:
Marco
2017-02-15 17:19:16 +01:00
parent 4268e3fcd5
commit dac2850aba
2 changed files with 32 additions and 0 deletions

View File

@@ -105,6 +105,8 @@ catch (\Delight\Auth\TooManyRequestsException $e) {
The username in the third parameter is optional. You can pass `null` here if you don't want to manage usernames. The username in the third parameter is optional. You can pass `null` here if you don't want to manage usernames.
If you want to enforce unique usernames, on the other hand, simply call `registerWithUniqueUsername` instead of `register`, and be prepared to catch the `DuplicateUsernameException`, if necessary.
For email verification, you should build an URL with the selector and token and send it to the user, e.g.: For email verification, you should build an URL with the selector and token and send it to the user, e.g.:
```php ```php

View File

@@ -177,6 +177,36 @@ class Auth {
return $this->createUserInternal(false, $email, $password, $username, $callback); return $this->createUserInternal(false, $email, $password, $username, $callback);
} }
/**
* Attempts to sign up a user while ensuring that the username is unique
*
* If you want the user's account to be activated by default, pass `null` as the callback
*
* If you want to make the user verify their email address first, pass an anonymous function as the callback
*
* The callback function must have the following signature:
*
* `function ($selector, $token)`
*
* Both pieces of information must be sent to the user, usually embedded in a link
*
* When the user wants to verify their email address as a next step, both pieces will be required again
*
* @param string $email the email address to register
* @param string $password the password for the new account
* @param string|null $username (optional) the username that will be displayed
* @param callable|null $callback (optional) the function that sends the confirmation email to the user
* @return int the ID of the user that has been created (if any)
* @throws InvalidEmailException if the email address was invalid
* @throws InvalidPasswordException if the password was invalid
* @throws UserAlreadyExistsException if a user with the specified email address already exists
* @throws DuplicateUsernameException if the specified username wasn't unique
* @throws AuthError if an internal problem occurred (do *not* catch)
*/
public function registerWithUniqueUsername($email, $password, $username = null, callable $callback = null) {
return $this->createUserInternal(true, $email, $password, $username, $callback);
}
/** /**
* Creates a request for email confirmation * Creates a request for email confirmation
* *