mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-07-30 21:00:13 +02:00
Move method 'createConfirmationRequest' from 'Auth' to 'UserManager'
This commit is contained in:
46
src/Auth.php
46
src/Auth.php
@@ -190,52 +190,6 @@ final class Auth extends UserManager {
|
||||
return $this->createUserInternal(true, $email, $password, $username, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a request for email confirmation
|
||||
*
|
||||
* 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 verify
|
||||
* @param callable $callback the function that sends the confirmation email to the user
|
||||
* @throws AuthError if an internal problem occurred (do *not* catch)
|
||||
*/
|
||||
private function createConfirmationRequest($email, callable $callback) {
|
||||
$selector = self::createRandomString(16);
|
||||
$token = self::createRandomString(16);
|
||||
$tokenHashed = password_hash($token, PASSWORD_DEFAULT);
|
||||
|
||||
// the request shall be valid for one day
|
||||
$expires = time() + 60 * 60 * 24;
|
||||
|
||||
try {
|
||||
$this->db->insert(
|
||||
'users_confirmations',
|
||||
[
|
||||
'email' => $email,
|
||||
'selector' => $selector,
|
||||
'token' => $tokenHashed,
|
||||
'expires' => $expires
|
||||
]
|
||||
);
|
||||
}
|
||||
catch (Error $e) {
|
||||
throw new DatabaseError();
|
||||
}
|
||||
|
||||
if (isset($callback) && is_callable($callback)) {
|
||||
$callback($selector, $token);
|
||||
}
|
||||
else {
|
||||
throw new MissingCallbackError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to sign in a user with their email address and password
|
||||
*
|
||||
|
@@ -118,4 +118,50 @@ abstract class UserManager {
|
||||
*/
|
||||
abstract protected function throttle($actionType, $customSelector = null);
|
||||
|
||||
/**
|
||||
* Creates a request for email confirmation
|
||||
*
|
||||
* 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 verify
|
||||
* @param callable $callback the function that sends the confirmation email to the user
|
||||
* @throws AuthError if an internal problem occurred (do *not* catch)
|
||||
*/
|
||||
private function createConfirmationRequest($email, callable $callback) {
|
||||
$selector = self::createRandomString(16);
|
||||
$token = self::createRandomString(16);
|
||||
$tokenHashed = password_hash($token, PASSWORD_DEFAULT);
|
||||
|
||||
// the request shall be valid for one day
|
||||
$expires = time() + 60 * 60 * 24;
|
||||
|
||||
try {
|
||||
$this->db->insert(
|
||||
'users_confirmations',
|
||||
[
|
||||
'email' => $email,
|
||||
'selector' => $selector,
|
||||
'token' => $tokenHashed,
|
||||
'expires' => $expires
|
||||
]
|
||||
);
|
||||
}
|
||||
catch (Error $e) {
|
||||
throw new DatabaseError();
|
||||
}
|
||||
|
||||
if (isset($callback) && is_callable($callback)) {
|
||||
$callback($selector, $token);
|
||||
}
|
||||
else {
|
||||
throw new MissingCallbackError();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user