Added register, login, logout pages

Added roles file
This commit is contained in:
Furentes
2019-05-09 13:59:54 +02:00
parent 36826f48a8
commit 135b0bb9c2
8 changed files with 186 additions and 5 deletions

View File

@ -11,6 +11,24 @@ require_once(__DIR__."/lib/autoload.php");
<title>Home - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?></title> <title>Home - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?></title>
</head> </head>
<body> <body>
<?php
if (!$auth->isLoggedIn()) {
?>
<p>
<a href="/login.php">Login</a>
</p>
<p>
<a href="/register.php">Registrieren</a>
</p>
<?php
}
if ($auth->isLoggedIn()) {
?>
<p>
<a href="/logout.php">Logout</a>
</p>
<?php
}
?>
</body> </body>
</html> </html>

36
lib/Bloggr/roles.php Normal file
View File

@ -0,0 +1,36 @@
<?php
namespace Bloggr;
class Roles
{
const ADMIN = 1;
const AUTHOR = 2;
const COLLABORATOR = 4;
const CONSULTANT = 8;
const CONSUMER = 16;
const CONTRIBUTOR = 32;
const COORDINATOR = 64;
const CREATOR = 128;
const DEVELOPER = 256;
const DIRECTOR = 512;
const EDITOR = 1024;
const EMPLOYEE = 2048;
const MAINTAINER = 4096;
const MANAGER = 8192;
const MODERATOR = 16384;
const PUBLISHER = 32768;
const REVIEWER = 65536;
const SUBSCRIBER = 131072;
const SUPER_ADMIN = 262144;
const SUPER_EDITOR = 524288;
const SUPER_MODERATOR = 1048576;
const TRANSLATOR = 2097152;
// const XYZ = 4194304;
// const XYZ = 8388608;
// const XYZ = 16777216;
// const XYZ = 33554432;
// const XYZ = 67108864;
// const XYZ = 134217728;
// const XYZ = 268435456;
// const XYZ = 536870912;
}
?>

View File

@ -23,3 +23,7 @@ if(!($request_uri == "/setup")) {
$pdo = new \PDO('mysql:dbname='.DB_NAME.';host='.DB_HOST.';charset=utf8mb4', DB_USER, DB_PASS); $pdo = new \PDO('mysql:dbname='.DB_NAME.';host='.DB_HOST.';charset=utf8mb4', DB_USER, DB_PASS);
$auth = new \Bloggr\Auth($pdo); $auth = new \Bloggr\Auth($pdo);
} }
echo '<pre>';
print_r($_SESSION);
echo '</pre>';

View File

@ -1,10 +1,10 @@
<?php <?php
define('SITE_TITLE', 'aaaaaaaaaaaa'); define('SITE_TITLE', 'A Bloggr Site');
define('DB_HOST', 'localhost'); define('DB_HOST', 'localhost');
define('DB_NAME', 'bloggr'); define('DB_NAME', 'bloggr');
define('DB_USER', 'root'); define('DB_USER', 'root');
define('DB_PASS', ''); define('DB_PASS', '');
define('ADMIN_USER', 'kein'); define('ADMIN_USER', 'admin');
define('ADMIN_EMAIL', 'adsasd@hsadashd.com'); define('ADMIN_EMAIL', 'test@test.com');

52
login.php Normal file
View File

@ -0,0 +1,52 @@
<?php
include_once(__DIR__."/lib/autoload.php");
// print_r($auth->register('Furentes', 'furentes@furentes.de', '123456789'));
// print_r($auth->login('Furentes', '123456789'));
// echo $auth->isLoggedIn();
// echo $auth->logout();
if ($auth->isLoggedIn()) {
header('Location: /');
}
$errors = [];
if (isset($_POST['login'])) {
$login = $auth->login($_POST['user'], $_POST['password']);
if (is_array($login)) {
$errors = $login;
} else {
header('Location: /');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Login - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="/css/main.css">
</head>
<body>
<div>
<h2>Login</h2>
<?php
foreach ($errors as $key=>$value):
?>
<span style="color: red;">
<?= $value ?>
</span><br>
<?php
endforeach;
?>
<form action="/login.php" method="post" class="clearfix">
<label for="user">Username/E-Mail</label>
<input type="text" name="user" id="user" value="<?= (isset($_POST['user'])) ? $_POST['user'] : ''; ?>">
<label for="password">Password</label>
<input type="password" name="password" id="password"">
<input type="submit" name="login" value="login" class="float-right">
</form>
</div>
</body>
</html>

5
logout.php Normal file
View File

@ -0,0 +1,5 @@
<?php
include_once(__DIR__."/lib/autoload.php");
$auth->logout();
header("Location: /");
die();

66
register.php Normal file
View File

@ -0,0 +1,66 @@
<?php
include_once(__DIR__."/lib/autoload.php");
// print_r($auth->register('Furentes', 'furentes@furentes.de', '123456789'));
// print_r($auth->login('Furentes', '123456789'));
// echo $auth->isLoggedIn();
// echo $auth->logout();
if ($auth->isLoggedIn()) {
header('Location: /');
}
$errors = [];
$success = false;
if (isset($_POST['register'])) {
if ($_POST['password'] !== $_POST['password2']) {
array_push($errors, 'Passwörter sind nicht gleich');
} else {
$register = $auth->register($_POST['username'], $_POST['email'], $_POST['password']);
if (is_array($register)) {
$errors = $register;
} else {
$success = true;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Register - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="/css/main.css">
</head>
<body>
<div>
<h2>Login</h2>
<?php
foreach ($errors as $key=>$value):
?>
<span style="color: red;">
<?= $value ?>
</span><br>
<?php
endforeach;
if($success == true) {
echo '<span style="color: green;">Account erstellt!</span><br>';
} else {
?>
<form action="/register.php" method="post" class="clearfix">
<label for="username">Username</label>
<input type="text" name="username" id="username" value="<?= (isset($_POST['username'])) ? $_POST['username'] : ''; ?>"><br>
<label for="email">E-Mail</label>
<input type="text" name="email" id="email" value="<?= (isset($_POST['email'])) ? $_POST['email'] : ''; ?>"><br>
<label for="password">Password</label>
<input type="password" name="password" id="password""><br>
<label for="password2">Password wiederholen</label>
<input type="password" name="password2" id="password2""><br>
<input type="submit" name="register" value="Registrieren">
</form>
<?php } ?>
</div>
</body>
</html>

View File

@ -71,7 +71,7 @@ if (isset($_POST['check'])) {
if(count($error) <= 0) { if(count($error) <= 0) {
$auth = new \Bloggr\Auth($pdo); $auth = new \Bloggr\Auth($pdo);
$register = $auth->register($user, $email, $pass, 1); $register = $auth->register($user, $email, $pass, \Bloggr\Roles::ADMIN);
if (is_array($register)) { if (is_array($register)) {
foreach($register as $regErr) { foreach($register as $regErr) {
array_push($error, $regErr); array_push($error, $regErr);