diff --git a/index.php b/index.php index 97e4645..810d45c 100644 --- a/index.php +++ b/index.php @@ -11,6 +11,24 @@ require_once(__DIR__."/lib/autoload.php"); Home - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?> - + isLoggedIn()) { + ?> +

+ Login +

+

+ Registrieren +

+ isLoggedIn()) { + ?> +

+ Logout +

+ diff --git a/lib/Bloggr/roles.php b/lib/Bloggr/roles.php new file mode 100644 index 0000000..9ad7cf7 --- /dev/null +++ b/lib/Bloggr/roles.php @@ -0,0 +1,36 @@ + \ No newline at end of file diff --git a/lib/autoload.php b/lib/autoload.php index f573460..c883366 100644 --- a/lib/autoload.php +++ b/lib/autoload.php @@ -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 '
';
+print_r($_SESSION);
+echo '
'; diff --git a/lib/config.php b/lib/config.php index 965addf..5c75f8c 100644 --- a/lib/config.php +++ b/lib/config.php @@ -1,10 +1,10 @@ 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: /'); + } +} +?> + + + + + + Login - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?> + + + + +
+

Login

+ + $value): + ?> + + +
+ + +
+ + + + + +
+
+ + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..acc6b24 --- /dev/null +++ b/logout.php @@ -0,0 +1,5 @@ +logout(); +header("Location: /"); +die(); diff --git a/register.php b/register.php new file mode 100644 index 0000000..ca0293c --- /dev/null +++ b/register.php @@ -0,0 +1,66 @@ +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; + } + } +} +?> + + + + + + Register - <?= (defined("SITE_TITLE")) ? SITE_TITLE : 'A Bloggr Site' ?> + + + + +
+

Login

+ + $value): + ?> + + +
+ Account erstellt!
'; + } else { + ?> + +
+ +
+ +
+ +
+ +
+ +
+ +
+ + diff --git a/setup.php b/setup.php index 8f8351e..0e3bfe0 100644 --- a/setup.php +++ b/setup.php @@ -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);