1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-06 16:16:29 +02:00

Add tests for method 'changeEmail' from class 'Auth'

This commit is contained in:
Marco
2017-07-30 21:01:41 +02:00
parent 3329c6a985
commit 3809b9d5d5

View File

@@ -246,6 +246,37 @@ function processRequestData(\Delight\Auth\Auth $auth) {
return 'invalid password(s)';
}
}
else if ($_POST['action'] === 'changeEmail') {
try {
$auth->changeEmail($_POST['newEmail'], function ($selector, $token) {
echo '<pre>';
echo 'Email confirmation';
echo "\n";
echo ' > Selector';
echo "\t\t\t\t";
echo htmlspecialchars($selector);
echo "\n";
echo ' > Token';
echo "\t\t\t\t";
echo htmlspecialchars($token);
echo '</pre>';
});
return 'ok';
}
catch (\Delight\Auth\InvalidEmailException $e) {
return 'invalid email address';
}
catch (\Delight\Auth\UserAlreadyExistsException $e) {
return 'email address already exists';
}
catch (\Delight\Auth\EmailNotVerifiedException $e) {
return 'account not verified';
}
catch (\Delight\Auth\NotLoggedInException $e) {
return 'not logged in';
}
}
else if ($_POST['action'] === 'setPasswordResetEnabled') {
try {
$auth->setPasswordResetEnabled($_POST['enabled'] == 1);
@@ -536,6 +567,12 @@ function showAuthenticatedUserForm(\Delight\Auth\Auth $auth) {
echo '<button type="submit">Change password</button>';
echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="changeEmail" />';
echo '<input type="text" name="newEmail" placeholder="New email address" /> ';
echo '<button type="submit">Change email address</button>';
echo '</form>';
showConfirmEmailForm();
echo '<form action="" method="post" accept-charset="utf-8">';