cleanup, add type information
This commit is contained in:
parent
2e2fe4b85f
commit
2a35a1737e
|
@ -160,7 +160,7 @@ function _clean_domain($address) {
|
||||||
return preg_replace('/[^A-Za-z0-9_.+-]/', "", $username); // remove special characters
|
return preg_replace('/[^A-Za-z0-9_.+-]/', "", $username); // remove special characters
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect_to_random($domains) {
|
function redirect_to_random(array $domains) {
|
||||||
$wordLength = rand(3, 8);
|
$wordLength = rand(3, 8);
|
||||||
$container = new PronounceableWord_DependencyInjectionContainer();
|
$container = new PronounceableWord_DependencyInjectionContainer();
|
||||||
$generator = $container->getGenerator();
|
$generator = $container->getGenerator();
|
||||||
|
|
|
@ -4,13 +4,20 @@ abstract class Page {
|
||||||
|
|
||||||
function invoke() {
|
function invoke() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function if_invalid_redirect_to_random(User $user, array $config_domains) {
|
||||||
|
if ($user->isInvalid()) {
|
||||||
|
redirect_to_random($config_domains);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RedirectToAddressPage extends Page {
|
class RedirectToAddressPage extends Page {
|
||||||
private $username;
|
private $username;
|
||||||
private $domain;
|
private $domain;
|
||||||
|
|
||||||
public function __construct($username, $domain) {
|
public function __construct(string $username, string $domain) {
|
||||||
$this->username = $username;
|
$this->username = $username;
|
||||||
$this->domain = $domain;
|
$this->domain = $domain;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +34,7 @@ class DownloadEmailPage extends Page {
|
||||||
private $address;
|
private $address;
|
||||||
private $config_domains;
|
private $config_domains;
|
||||||
|
|
||||||
public function __construct($email_id, $address, $config_domains) {
|
public function __construct(string $email_id, string $address, array $config_domains) {
|
||||||
$this->email_id = $email_id;
|
$this->email_id = $email_id;
|
||||||
$this->address = $address;
|
$this->address = $address;
|
||||||
$this->config_domains = $config_domains;
|
$this->config_domains = $config_domains;
|
||||||
|
@ -36,12 +43,10 @@ class DownloadEmailPage extends Page {
|
||||||
|
|
||||||
function invoke() {
|
function invoke() {
|
||||||
$user = User::parseDomain($this->address);
|
$user = User::parseDomain($this->address);
|
||||||
|
$this->if_invalid_redirect_to_random($user, $this->config_domains);
|
||||||
|
|
||||||
$download_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
$download_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
||||||
if ($user->isInvalid()) {
|
download_email($download_email_id, $user);
|
||||||
redirect_to_random($this->config_domains);
|
|
||||||
} else {
|
|
||||||
download_email($download_email_id, $user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,13 +64,11 @@ class DeleteEmailPage extends Page {
|
||||||
|
|
||||||
function invoke() {
|
function invoke() {
|
||||||
$user = User::parseDomain($this->address);
|
$user = User::parseDomain($this->address);
|
||||||
|
$this->if_invalid_redirect_to_random($user, $this->all_domains);
|
||||||
|
|
||||||
$delete_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
$delete_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
||||||
if ($user->isInvalid()) {
|
delete_email($delete_email_id, $user);
|
||||||
redirect_to_random($this->all_domains);
|
header("location: ?" . $user->address);
|
||||||
} else {
|
|
||||||
delete_email($delete_email_id, $user);
|
|
||||||
header("location: ?" . $user->address);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +98,12 @@ class DisplayEmailsPage extends Page {
|
||||||
function invoke() {
|
function invoke() {
|
||||||
// print emails with html template
|
// print emails with html template
|
||||||
$user = User::parseDomain($this->address);
|
$user = User::parseDomain($this->address);
|
||||||
if ($user->isInvalid()) {
|
$this->if_invalid_redirect_to_random($user, $this->config['domains']);
|
||||||
redirect_to_random($this->config['domains']);
|
|
||||||
} else {
|
global $emails;
|
||||||
global $emails;
|
global $config;
|
||||||
global $config;
|
$emails = get_emails($user);
|
||||||
$emails = get_emails($user);
|
require "frontend.template.php";
|
||||||
require "frontend.template.php";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,4 +111,4 @@ class InvalidRequestPage extends Page {
|
||||||
function invoke() {
|
function invoke() {
|
||||||
error(400, "Bad Request");
|
error(400, "Bad Request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Router {
|
||||||
private $query_string;
|
private $query_string;
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
public function __construct($method, $action, $get_vars, $post_vars, $query_string, $config) {
|
public function __construct(string $method, string $action = NULL, array $get_vars, array $post_vars, string $query_string, array $config) {
|
||||||
$this->method = $method;
|
$this->method = $method;
|
||||||
$this->action = $action;
|
$this->action = $action;
|
||||||
$this->get_vars = $get_vars;
|
$this->get_vars = $get_vars;
|
||||||
|
@ -20,28 +20,36 @@ class Router {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function init() {
|
static function init(): Router {
|
||||||
global $config;
|
global $config;
|
||||||
return new Router($_SERVER['REQUEST_METHOD'], $_GET['action'] ?? array(), $_GET, $_POST, $_SERVER['QUERY_STRING'], $config);
|
return new Router($_SERVER['REQUEST_METHOD'], $_GET['action'] ?? NULL, $_GET, $_POST, $_SERVER['QUERY_STRING'], $config);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function route() {
|
function route(): Page {
|
||||||
// TODO: use $this->action
|
// TODO: use $this->action
|
||||||
if (isset($this->post_vars['username']) && isset($this->post_vars['domain'])) {
|
if (isset($this->post_vars['username']) && isset($this->post_vars['domain'])) {
|
||||||
return new RedirectToAddressPage($this->post_vars['username'], $this->post_vars['domain']);
|
return new RedirectToAddressPage($this->post_vars['username'], $this->post_vars['domain']);
|
||||||
|
|
||||||
} elseif (isset($this->get_vars['download_email_id']) && isset($this->get_vars['address'])) {
|
} elseif (isset($this->get_vars['download_email_id']) && isset($this->get_vars['address'])) {
|
||||||
return new DownloadEmailPage($this->get_vars['download_email_id'], $this->get_vars['address'], $this->config['domains']);
|
return new DownloadEmailPage($this->get_vars['download_email_id'], $this->get_vars['address'], $this->config['domains']);
|
||||||
|
|
||||||
} elseif (isset($this->get_vars['delete_email_id']) && isset($this->get_vars['address'])) {
|
} elseif (isset($this->get_vars['delete_email_id']) && isset($this->get_vars['address'])) {
|
||||||
return new DeleteEmailPage($this->get_vars['delete_email_id'], $this->get_vars['address'], $this->config['domains']);
|
return new DeleteEmailPage($this->get_vars['delete_email_id'], $this->get_vars['address'], $this->config['domains']);
|
||||||
|
|
||||||
} elseif (isset($this->get_vars['random'])) {
|
} elseif (isset($this->get_vars['random'])) {
|
||||||
return new RedirectToRandomAddressPage($this->config['domains']);
|
return new RedirectToRandomAddressPage($this->config['domains']);
|
||||||
|
|
||||||
} elseif (empty($this->query_string)) {
|
} elseif (empty($this->query_string)) {
|
||||||
return new RedirectToRandomAddressPage($this->config['domains']);
|
return new RedirectToRandomAddressPage($this->config['domains']);
|
||||||
|
|
||||||
} elseif (!empty($this->query_string)) {
|
} elseif (!empty($this->query_string)) {
|
||||||
return new DisplayEmailsPage($this->query_string, $this->config);
|
return new DisplayEmailsPage($this->query_string, $this->config);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return new InvalidRequestPage();
|
return new InvalidRequestPage();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ class User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function parseDomain($address) {
|
public static function parseDomain(string $address) {
|
||||||
$clean_address = _clean_address($address);
|
$clean_address = _clean_address($address);
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->username = _clean_username($clean_address);
|
$user->username = _clean_username($clean_address);
|
||||||
|
@ -25,7 +25,7 @@ class User {
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function parseUsernameAndDomain($username, $domain) {
|
public static function parseUsernameAndDomain(string $username, string $domain) {
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->username = _clean_username($username);
|
$user->username = _clean_username($username);
|
||||||
$user->domain = _clean_domain($domain);
|
$user->domain = _clean_domain($domain);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user