1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-07-11 03:26:20 +02:00

Add public method 'loginWithUsername' to class 'Auth'

This commit is contained in:
Marco
2017-02-20 21:36:45 +01:00
parent 690485ba6d
commit 3cb2284870
2 changed files with 23 additions and 1 deletions

View File

@ -137,6 +137,8 @@ catch (\Delight\Auth\TooManyRequestsException $e) {
} }
``` ```
If you want to sign in with usernames on the other hand, either in addition to the login via email address or as a replacement, that's possible as well. Simply call the method `loginWithUsername` instead of method `login`. Then, instead of catching `InvalidEmailException`, make sure to catch both `UnknownUsernameException` and `AmbiguousUsernameException`. You may also want to read the notes about the uniqueness of usernames in the section that explains how to [sign up new users](#registration-sign-up).
### Email verification ### Email verification
Extract the selector and token from the URL that the user clicked on in the verification email. Extract the selector and token from the URL that the user clicked on in the verification email.

View File

@ -254,7 +254,7 @@ class Auth {
} }
/** /**
* Attempts to sign in a user * Attempts to sign in a user with their email address and password
* *
* @param string $email the user's email address * @param string $email the user's email address
* @param string $password the user's password * @param string $password the user's password
@ -268,6 +268,26 @@ class Auth {
$this->authenticateUserInternal($password, $email, null, $rememberDuration); $this->authenticateUserInternal($password, $email, null, $rememberDuration);
} }
/**
* Attempts to sign in a user with their username and password
*
* When using this method to authenticate users, you should ensure that usernames are unique
*
* Consistently using {@see registerWithUniqueUsername} instead of {@see register} can be helpful
*
* @param string $username the user's username
* @param string $password the user's password
* @param int|bool|null $rememberDuration (optional) the duration in seconds to keep the user logged in ("remember me"), e.g. `60 * 60 * 24 * 365.25` for one year
* @throws UnknownUsernameException if the specified username does not exist
* @throws AmbiguousUsernameException if the specified username is ambiguous, i.e. there are multiple users with that name
* @throws InvalidPasswordException if the password was invalid
* @throws EmailNotVerifiedException if the email address has not been verified yet via confirmation email
* @throws AuthError if an internal problem occurred (do *not* catch)
*/
public function loginWithUsername($username, $password, $rememberDuration = null) {
$this->authenticateUserInternal($password, null, $username, $rememberDuration);
}
/** /**
* Validates an email address * Validates an email address
* *