From ff6d78942af183dde03816c0b7c5352fb932d25c Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 21 Feb 2017 09:26:10 +0100 Subject: [PATCH] Move method 'createConfirmationRequest' from 'Auth' to 'UserManager' --- src/Auth.php | 46 --------------------------------------------- src/UserManager.php | 46 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 8f9915c..e2774e9 100644 --- a/src/Auth.php +++ b/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 * diff --git a/src/UserManager.php b/src/UserManager.php index ceb2da9..aa39dab 100644 --- a/src/UserManager.php +++ b/src/UserManager.php @@ -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(); + } + } + }