mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-03 22:57:27 +02:00
Document method 'changeEmail' from class 'Auth'
This commit is contained in:
33
README.md
33
README.md
@@ -54,6 +54,7 @@ Migrating from an earlier version of this project? See our [upgrade guide](Migra
|
||||
* [Keeping the user logged in](#keeping-the-user-logged-in)
|
||||
* [Password reset ("forgot password")](#password-reset-forgot-password)
|
||||
* [Changing the current user's password](#changing-the-current-users-password)
|
||||
* [Changing the current user's email address](#changing-the-current-users-email-address)
|
||||
* [Logout](#logout)
|
||||
* [Accessing user information](#accessing-user-information)
|
||||
* [Login state](#login-state)
|
||||
@@ -305,6 +306,38 @@ catch (\Delight\Auth\InvalidPasswordException $e) {
|
||||
}
|
||||
```
|
||||
|
||||
### Changing the current user's email address
|
||||
|
||||
If a user is currently logged in, they may change their email address.
|
||||
|
||||
```php
|
||||
try {
|
||||
$auth->changeEmail($_POST['newEmail'], function ($selector, $token) {
|
||||
// send `$selector` and `$token` to the user (e.g. via email)
|
||||
});
|
||||
|
||||
// the change will take effect as soon as the email address has been confirmed
|
||||
}
|
||||
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||
// invalid email address
|
||||
}
|
||||
catch (\Delight\Auth\UserAlreadyExistsException $e) {
|
||||
// email address already exists
|
||||
}
|
||||
catch (\Delight\Auth\EmailNotVerifiedException $e) {
|
||||
// account not verified
|
||||
}
|
||||
catch (\Delight\Auth\NotLoggedInException $e) {
|
||||
// not logged in
|
||||
}
|
||||
```
|
||||
|
||||
For email verification, you should build an URL with the selector and token and send it to the user, e.g.:
|
||||
|
||||
```php
|
||||
$url = 'https://www.example.com/verify_email?selector='.urlencode($selector).'&token='.urlencode($token);
|
||||
```
|
||||
|
||||
### Logout
|
||||
|
||||
```php
|
||||
|
Reference in New Issue
Block a user