mirror of
https://github.com/p08dev/Bloggr.git
synced 2026-06-17 12:43:56 +02:00
Added register, login, logout pages
Added roles file
This commit is contained in:
20
index.php
20
index.php
@ -11,6 +11,24 @@ require_once(__DIR__."/lib/autoload.php");
|
||||
<title>Home - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?></title>
|
||||
</head>
|
||||
<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>
|
||||
</html>
|
||||
|
||||
36
lib/Bloggr/roles.php
Normal file
36
lib/Bloggr/roles.php
Normal 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;
|
||||
}
|
||||
?>
|
||||
@ -23,3 +23,7 @@ if(!($request_uri == "/setup")) {
|
||||
$pdo = new \PDO('mysql:dbname='.DB_NAME.';host='.DB_HOST.';charset=utf8mb4', DB_USER, DB_PASS);
|
||||
$auth = new \Bloggr\Auth($pdo);
|
||||
}
|
||||
|
||||
echo '<pre>';
|
||||
print_r($_SESSION);
|
||||
echo '</pre>';
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
define('SITE_TITLE', 'aaaaaaaaaaaa');
|
||||
define('SITE_TITLE', 'A Bloggr Site');
|
||||
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_NAME', 'bloggr');
|
||||
define('DB_USER', 'root');
|
||||
define('DB_PASS', '');
|
||||
|
||||
define('ADMIN_USER', 'kein');
|
||||
define('ADMIN_EMAIL', 'adsasd@hsadashd.com');
|
||||
define('ADMIN_USER', 'admin');
|
||||
define('ADMIN_EMAIL', 'test@test.com');
|
||||
|
||||
52
login.php
Normal file
52
login.php
Normal 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
5
logout.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
include_once(__DIR__."/lib/autoload.php");
|
||||
$auth->logout();
|
||||
header("Location: /");
|
||||
die();
|
||||
66
register.php
Normal file
66
register.php
Normal 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>
|
||||
@ -71,7 +71,7 @@ if (isset($_POST['check'])) {
|
||||
if(count($error) <= 0) {
|
||||
$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)) {
|
||||
foreach($register as $regErr) {
|
||||
array_push($error, $regErr);
|
||||
|
||||
Reference in New Issue
Block a user