Started making /paamelding

This commit is contained in:
Peder Bergebakken Sundt 2017-11-11 22:11:10 +01:00
parent 5981eea827
commit 518ee8baf2
1 changed files with 68 additions and 58 deletions

View File

@ -1,80 +1,90 @@
<?php
require_once '../../lib/OAuth2-Client/OAuth2Client.php';
require_once '../../dataporten_config.php';
require_once __DIR__ . '/../../inc/navbar.php';
require_once __DIR__ . '/../../lib/OAuth2-Client/OAuth2Client.php';
require_once __DIR__ . '/../../dataporten_config.php';
require_once __DIR__ . '/../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php';
session_start();
$as = new SimpleSAML_Auth_Simple('default-sp');
$attrs = $as->getAttributes();
$oauth2 = new Kasperrt\Oauth2($dataportenConfig);
session_start();
if (isset($_GET['logout'])) {
session_destroy();
header('Location: http://[::1]:1080/paamelding/');
header('Location: ' . $dataportenConfig["redirect_uri"]);
die();
}
if (isset($_GET['code'])) {
$token = $oauth2 -> get_access_token();
error_log($token);
$_SESSION['userdata'] = $oauth2 -> get_identity($token, 'https://auth.dataporten.no/userinfo');
header('Location: http://[::1]:1080/paamelding/');
die();
}
if (!isset($_SESSION['userdata'])) {
if (isset($_GET['login'])) {
$oauth2 -> redirect();
die();
}
if (isset($_GET['code'])) {
$token = $oauth2 -> get_access_token();
$_SESSION['userdata'] = $oauth2 -> get_identity($token, 'https://auth.dataporten.no/userinfo');
//var_export($_SESSION);
//exit;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if($_POST["firstname"] == null &&
$_POST["lastname"] == null &&
$_POST["username"] == null &&
$_POST["email"] == null) {
var_export($_POST);
}
else {
$membersFile = "members.json";
$members = json_decode(file_get_contents($membersFile), true);
$newMember = array(
'firstname' => $_POST["firstname"],
'lastname' => $_POST["lastname"],
'username' => $_POST["username"],
'email' => $_POST["email"]);
array_push($members, $newMember);
file_put_contents($membersFile, json_encode($members));
}
header('Location: .');
header('Location: ' . $dataportenConfig["redirect_uri"]);
die();
}
?>
if (isset($_SESSION['userdata'])) { // if logged in with feide
$mailBody
= "Hei, jeg vil bli medlem på PVV.\n"
. "Navn: " . htmlspecialchars($_SESSION['userdata']['user']['name']) . "\n"
. "Brukernavn: " . htmlspecialchars($_SESSION['userdata']['user']['userid_sec'][0]) . "\n"
. "Epost: " . htmlspecialchars($_SESSION['userdata']['user']['email']) . "\n";
}
?>
<!DOCTYPE html>
<title>PVV registrering</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../css/events.css">
<header>Programvareverkstedet</header>
<div>
<form>
<div>
Full name:
<input type="text" name="lastname" value="<?= $_SESSION['userdata']['user']['name'] ?>" readonly>
</div>
<div>
NTNU username:
<input type="text" name="username" value="<?= $_SESSION['userdata']['user']['userid_sec'][0] ?>" readonly>
</div>
<div>
Email adress:
<input type="text" name="email" value="<?= $_SESSION['userdata']['user']['email'] ?>">
</div>
<input type="submit" value="Submit">
</form>
</div>
<header>Registrerings&shy;verks&shy;stedet</header>
<main>
<article>
<h2>Registrer deg som bruker</h2>
<p>
PVV har for øyeblikket et manuelt system for å legge til nye brukere.
Vi foretrekker at du kommer inn besøk <a href="https://use.mazemap.com/?v=1&left=10.4032&right=10.4044&top=63.4178&bottom=63.4172&campusid=1&zlevel=2&sharepoitype=point&sharepoi=10.40355%2C63.41755%2C2&utm_medium=longurl">våre lokaler stripa</a>
for å sette sette opp din PVV bruker. Hvis du vil, kan du også sende oss
en melding fra denne siden med ditt navn, epost og NTNU brukernavn.
For å aktivere din brukerkonto PVV, du møte opp
lokalene våre slik at vi kan satt et passord.
</p>
<h3>Meldingen som du kan sendes:</h3>
<?php if($attrs) { //logged in with pvv account?>
<p>
Du er logget in som <i><?= htmlspecialchars($attrs['uid'][0]) ?></i>,
du trenger ikke sende melding om ny bruker fordi du helt klart har en.
</p>
<?php } elseif (isset($_SESSION['userdata'])) { //logged in with feide ?>
<code>
Til: drift@pvv.ntnu.no<br>
Fra: nettsiden<br>
<br/>
<?= nl2br($mailBody) ?>
</code><br>
<br>
Todo: Legg til en "send mail" knapp
<?php } else { // not logged in?>
<a class="btn" href=".?login">æ kanj itj lææv uten piær!</a>
<?php }?>
</article>
</main>
<nav>
<?= navbar(1); ?>
<?= loginbar(); ?>
</nav>