From 68493c4401bf98ea189d65ad2094d647bc2092a0 Mon Sep 17 00:00:00 2001 From: Synox Date: Fri, 23 Feb 2018 22:21:05 +0100 Subject: [PATCH] redirect_to_random --- src/index.php | 12 ------------ src/pages.php | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/index.php b/src/index.php index 5a151b8..9f40ae4 100644 --- a/src/index.php +++ b/src/index.php @@ -39,18 +39,6 @@ function error($status, $text) { -function redirect_to_random(array $domains) { - $wordLength = rand(3, 8); - $container = new PronounceableWord_DependencyInjectionContainer(); - $generator = $container->getGenerator(); - $word = $generator->generateWordOfGivenLength($wordLength); - $nr = rand(51, 91); - $name = $word . $nr; - - $domain = $domains[array_rand($domains)]; - header("location: ?$name@$domain"); -} - /** * deletes messages older than X days. */ diff --git a/src/pages.php b/src/pages.php index 43a4908..c46cf62 100644 --- a/src/pages.php +++ b/src/pages.php @@ -7,10 +7,24 @@ abstract class Page { function if_invalid_redirect_to_random(User $user, array $config_domains) { if ($user->isInvalid()) { - redirect_to_random($config_domains); + $this->redirect_to_random($config_domains); exit(); } } + + + function redirect_to_random(array $domains) { + $wordLength = rand(3, 8); + $container = new PronounceableWord_DependencyInjectionContainer(); + $generator = $container->getGenerator(); + $word = $generator->generateWordOfGivenLength($wordLength); + $nr = rand(51, 91); + $name = $word . $nr; + + $domain = $domains[array_rand($domains)]; + header("location: ?$name@$domain"); + } + } class RedirectToAddressPage extends Page { @@ -80,7 +94,7 @@ class RedirectToRandomAddressPage extends Page { } function invoke(ImapClient $imapClient) { - redirect_to_random($this->config_domains); + $this->redirect_to_random($this->config_domains); } }