X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1ee3e779e4b9b0a92f701a72f21a72c83cb1ce68..refs/pull/2902/head:/app/Auth/Access/UserTokenService.php diff --git a/app/Auth/Access/UserTokenService.php b/app/Auth/Access/UserTokenService.php index 09a2f761b..565dcb948 100644 --- a/app/Auth/Access/UserTokenService.php +++ b/app/Auth/Access/UserTokenService.php @@ -1,4 +1,6 @@ -getEntryByToken($token); @@ -70,40 +79,47 @@ class UserTokenService /** * Creates a unique token within the email confirmation database. + * * @return string */ - protected function generateToken() : string + protected function generateToken(): string { $token = Str::random(24); while ($this->tokenExists($token)) { $token = Str::random(25); } + return $token; } /** * Generate and store a token for the given user. + * * @param User $user + * * @return string */ - protected function createTokenForUser(User $user) : string + protected function createTokenForUser(User $user): string { $token = $this->generateToken(); $this->db->table($this->tokenTable)->insert([ - 'user_id' => $user->id, - 'token' => $token, + 'user_id' => $user->id, + 'token' => $token, 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now() + 'updated_at' => Carbon::now(), ]); + return $token; } /** * Check if the given token exists. + * * @param string $token + * * @return bool */ - protected function tokenExists(string $token) : bool + protected function tokenExists(string $token): bool { return $this->db->table($this->tokenTable) ->where('token', '=', $token)->exists(); @@ -111,7 +127,9 @@ class UserTokenService /** * Get a token entry for the given token. + * * @param string $token + * * @return object|null */ protected function getEntryByToken(string $token) @@ -123,13 +141,14 @@ class UserTokenService /** * Check if the given token entry has expired. + * * @param stdClass $tokenEntry + * * @return bool */ - protected function entryExpired(stdClass $tokenEntry) : bool + protected function entryExpired(stdClass $tokenEntry): bool { return Carbon::now()->subHours($this->expiryTime) ->gt(new Carbon($tokenEntry->created_at)); } - -} \ No newline at end of file +}