realfan/public/signup/index.php

81 lines
1.5 KiB
PHP

<?php require_once '/src/base.php' ?>
<?php
$function = null;
$signup_method = null;
if (isset($_SERVER['REDIRECT_URL'])) {
# process URI
$path = trim($_SERVER['REDIRECT_URL'], '/');
$args = explode('/', $path);
# no args is very unlikely, but still
if (count($args) === 0) {
die('Unexpected error');
}
# get the signup method from URL
if (str_contains($args[1], ':')) {
$ps = explode(':', $args[1]);
$signup_method = $ps[0];
$function = $ps[1];
} else {
$signup_method = $args[1];
$function = 'view';
}
if (!in_array($signup_method, ['mastodon'])) {
die('The given signup method does not exist');
}
if (!in_array($function, ['view', 'oauth'])) {
die('The given function is not correct');
}
} else {
$function = 'view';
}
if ($function === 'oauth') {
$ID = $_GET['id'] ?? '';
$code = $_GET['code'] ?? '';
if (empty($code) || empty($ID)) {
header('Location: /signup'); die;
}
switch ($signup_method) {
case 'mastodon':
require '/src/action/oauth/mastodon.php';
break;
}
}
?>
<?php require '/src/views/head.php' ?>
<?php require '/src/views/public/head.php' ?>
<main>
SIGNUP: <?php echo $signup_method ?>
<br>
FUNCTION: <?php echo $function ?>
</main>
<?php require '/src/js/api.php' ?>
<script>
window.onload = function(e) {
<?php if ($function === 'view'): ?>
console.log('view');
<?php elseif ($function === 'oauth'): ?>
console.log('oauth');
<?php endif ?>
}
</script>
<?php require '/src/views/public/foot.php' ?>
<?php require '/src/views/foot.php' ?>