fontawesome und jeeede menge reworks
All checks were successful
Build and push / Pulling repo on server (push) Successful in 20s
All checks were successful
Build and push / Pulling repo on server (push) Successful in 20s
This commit is contained in:
74
web/pages/admin/controller.php
Normal file
74
web/pages/admin/controller.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
class Admin extends Page {
|
||||
|
||||
function loginas()
|
||||
{
|
||||
$user = $_REQUEST['email'];
|
||||
|
||||
$u = new User();
|
||||
if($u->load($user))
|
||||
{
|
||||
$u->login();
|
||||
$this->redirect('/');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->set('message', 'User '.escape($user).' not found');
|
||||
$this->set('template', 'notfound.html');
|
||||
}
|
||||
}
|
||||
|
||||
function edituser()
|
||||
{
|
||||
$user = $_REQUEST['email'];
|
||||
|
||||
$u = new User();
|
||||
if($u->load($user))
|
||||
{
|
||||
$data = $u->data;
|
||||
$this->set('userdata', $data);
|
||||
$this->set('userid', $user);
|
||||
$this->set('template', 'edituser.html');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->set('message', 'User '.escape($user).' not found');
|
||||
$this->set('template', 'notfound.html');
|
||||
}
|
||||
}
|
||||
|
||||
function edituserdata()
|
||||
{
|
||||
$user = $_REQUEST['email'];
|
||||
|
||||
$u = new User();
|
||||
if(!$u->load($user))
|
||||
{
|
||||
$this->set('message', 'User '.escape($user).' not found');
|
||||
$this->set('template', '/templates/notfound.html');
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($_REQUEST as $key => $value)
|
||||
{
|
||||
if($key == 'email') continue;
|
||||
$u->$key = $value;
|
||||
}
|
||||
|
||||
try{
|
||||
$u->save();
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->set('message', $e->getMessage());
|
||||
$this->set('template', '/templates/error.html');
|
||||
return;
|
||||
|
||||
}
|
||||
$this->set('message', 'Speichern erfolgreich');
|
||||
$this->set('template', '/templates/success.html');
|
||||
}
|
||||
|
||||
function maySeeThisPage(){return true;}
|
||||
}
|
37
web/pages/admin/edituser.html
Normal file
37
web/pages/admin/edituser.html
Normal file
@ -0,0 +1,37 @@
|
||||
<form hx-post="/admin/edituserdata" hx-target="#response">
|
||||
<div id="defaultModal" tabindex="-1" aria-hidden="true" class="z-50 w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
||||
<div class="relative w-full max-w-2xl max-h-full">
|
||||
<!-- Modal content -->
|
||||
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
||||
<!-- Modal header -->
|
||||
<div class="flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600">
|
||||
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">
|
||||
Edit user <?= $userid ?>
|
||||
</h3>
|
||||
</div>
|
||||
<!-- Modal body -->
|
||||
<div class="p-6 space-y-6">
|
||||
<div class="flex flex-col">
|
||||
<label for="id" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
ID
|
||||
</label>
|
||||
<input type="text" name="id" disabled id="id" value="<?= $userid ?>" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
||||
</div>
|
||||
<?php foreach (array_keys($userdata) as $key) : ?>
|
||||
<div class="flex flex-col">
|
||||
<label for="<?= $key ?>" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
<?= $key ?>
|
||||
</label>
|
||||
<input type="text" name="<?= $key ?>" id="<?= $key ?>" value="<?= $userdata[$key] ?>" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<!-- Modal footer -->
|
||||
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
|
||||
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Save</button>
|
||||
<div id="response"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -4,15 +4,17 @@ class Home extends Page
|
||||
{
|
||||
function setMenu()
|
||||
{
|
||||
$this->menu_text = 'home';
|
||||
$this->menu_image = 'mdi-action-home';
|
||||
$this->menu_text = 'Home';
|
||||
$this->menu_image = 'far fa-home';
|
||||
$this->menu_priority = 0;
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
$u = new User();
|
||||
$this->set('userdata', $u->getAll());
|
||||
$this->set('template', "home.html");
|
||||
return $this->renderPagecontent();
|
||||
//return $this->renderPagecontent();
|
||||
}
|
||||
|
||||
function maySeeThisPage(){return true;}
|
||||
|
@ -1,9 +1,6 @@
|
||||
<div class="hidden sm:mb-8 sm:flex sm:justify-center">
|
||||
<div
|
||||
class="relative rounded-full px-3 py-1 text-sm leading-6 text-gray-600 ring-1 ring-gray-900/10 hover:ring-gray-900/20">
|
||||
Announcing our next round of funding. <a href="#" class="font-semibold text-indigo-600"><span
|
||||
class="absolute inset-0" aria-hidden="true"></span>Read more <span
|
||||
aria-hidden="true">→</span></a>
|
||||
<div class="relative rounded-full px-3 py-1 text-sm leading-6 text-gray-600 ring-1 ring-gray-900/10 hover:ring-gray-900/20">
|
||||
Currently logged in as: <?= $_SESSION['userid']?:'nobody' ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@ -11,14 +8,14 @@
|
||||
<p class="mt-6 text-lg leading-8 text-gray-600">Anim aute id magna aliqua ad ad non deserunt sunt.
|
||||
Qui irure qui lorem cupidatat commodo. Elit sunt amet fugiat veniam occaecat fugiat aliqua.</p>
|
||||
<div class="mt-10 flex items-center justify-center gap-x-6">
|
||||
<a href="#"
|
||||
class="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Get
|
||||
<a href="#" class="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Get
|
||||
started</a>
|
||||
<a href="#" class="text-sm font-semibold leading-6 text-gray-900">Learn more <span
|
||||
aria-hidden="true">→</span></a>
|
||||
<a href="#" class="text-sm font-semibold leading-6 text-gray-900">Learn more <span aria-hidden="true">→</span></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl p-6 text-center">Admin stuff</h1>
|
||||
|
||||
<div class="container flex justify-center mx-auto">
|
||||
<div class="flex flex-col">
|
||||
<div class="w-full">
|
||||
@ -26,54 +23,37 @@
|
||||
<table class="divide-y divide-gray-300 ">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<?php foreach (array_keys($userdata[0]) as $key) : ?>
|
||||
<th class="px-6 py-2 text-xs text-gray-500">
|
||||
ID
|
||||
<?= $key ?>
|
||||
</th>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<th class="px-6 py-2 text-xs text-gray-500">
|
||||
Name
|
||||
</th>
|
||||
<th class="px-6 py-2 text-xs text-gray-500">
|
||||
Email
|
||||
</th>
|
||||
<th class="px-6 py-2 text-xs text-gray-500">
|
||||
Created_at
|
||||
Login
|
||||
</th>
|
||||
<th class="px-6 py-2 text-xs text-gray-500">
|
||||
Edit
|
||||
</th>
|
||||
<th class="px-6 py-2 text-xs text-gray-500">
|
||||
Delete
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-300">
|
||||
<?php foreach ([
|
||||
['id' => 1, 'name' => 'Max', 'email' => 'test@test.ts'],
|
||||
['id' => 2, 'name' => 'Roxie', 'email' => 'loxie@test.ts'],
|
||||
] as $user) : ?>
|
||||
<?php foreach ($userdata as $user) : ?>
|
||||
|
||||
<tr class="whitespace-nowrap">
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
<?= $user['id'] ?>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="text-sm text-gray-900">
|
||||
<?= $user['name'] ?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="text-sm text-gray-500"><?= $user['email'] ?></div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
2021-1-12
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<a href="#" class="px-4 py-1 text-sm text-indigo-600 bg-indigo-200 rounded-full">Edit</a>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<a href="#" class="px-4 py-1 text-sm text-red-400 bg-red-200 rounded-full">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="whitespace-nowrap">
|
||||
<?php foreach (array_keys($user) as $key) : ?>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
<?= $user[$key] ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<td class="px-6 py-4">
|
||||
<button name="email" value="<?= $user['email'] ?>" hx-post="/admin/loginas/" class="px-4 py-1 text-sm text-indigo-600 bg-indigo-200 rounded-full">Login as this user</button>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<button name="email" value="<?= $user['email'] ?>" hx-post="/admin/edituser/" hx-target="#main" class="px-4 py-1 text-sm text-red-400 bg-red-200 rounded-full">Edit</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
|
@ -2,6 +2,16 @@
|
||||
|
||||
class Login extends Page {
|
||||
|
||||
function setMenu()
|
||||
{
|
||||
if($_SESSION['user'])
|
||||
$this->menu_text = $_SESSION['userid'];
|
||||
else
|
||||
$this->menu_text = 'Login';
|
||||
$this->menu_image = 'far fa-user';
|
||||
$this->menu_priority = 99;
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
$this->set('hello','world');
|
||||
|
@ -31,7 +31,7 @@
|
||||
Sign in
|
||||
</button>
|
||||
<p class="text-sm font-light text-gray-500 dark:text-gray-400">
|
||||
Don’t have an account yet? <a href="#" class="font-medium text-primary-600 hover:underline dark:text-primary-500">Sign up</a>
|
||||
Don’t have an account yet? <a href="#" hx-get="/register" hx-push-url="/register" hx-target="#main" class="font-medium text-primary-600 hover:underline dark:text-primary-500">Sign up</a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
91
web/pages/register/controller.php
Normal file
91
web/pages/register/controller.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class Register extends Page {
|
||||
|
||||
function index()
|
||||
{
|
||||
$this->set('template', 'register.html');
|
||||
}
|
||||
|
||||
function validate()
|
||||
{
|
||||
$email = trim($_REQUEST['email']);
|
||||
$password = trim($_REQUEST['password']);
|
||||
$password2 = trim($_REQUEST['password2']);
|
||||
|
||||
$hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
|
||||
$u = new User();
|
||||
|
||||
$err = false;
|
||||
if(!$email)
|
||||
$err = "Email is required";
|
||||
else if(!filter_var($email, FILTER_VALIDATE_EMAIL))
|
||||
$err = "Email is invalid";
|
||||
else if(!$password)
|
||||
$err = "Password is required";
|
||||
else if($password != $password2)
|
||||
$err = "Passwords do not match";
|
||||
else if(strlen($password) < 8)
|
||||
$err = "Password must be at least 8 characters long";
|
||||
else if($u->exists($email))
|
||||
$err = "Email already exists";
|
||||
|
||||
if($err)
|
||||
{
|
||||
$this->set('template', '/templates/error.html');
|
||||
$this->set('title', 'Error');
|
||||
$this->set('message', $err);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$u->id = $email;
|
||||
$u->email = $email;
|
||||
$u->password = $hash;
|
||||
$u->active = 0;
|
||||
try
|
||||
{
|
||||
$u->save();
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->set('template', '/templates/error.html');
|
||||
$this->set('title', 'Error');
|
||||
$this->set('message', $e->getMessage());
|
||||
return;
|
||||
}
|
||||
//$this->redirect('/register/success');
|
||||
return;
|
||||
}
|
||||
|
||||
return print_r(['email'=>$email,'password'=>$password,'password2'=>$password2], true);
|
||||
}
|
||||
|
||||
function success()
|
||||
{
|
||||
$this->set('template', '/templates/success.html');
|
||||
$this->set('title', 'Success');
|
||||
$this->set('message', 'You have successfully registered. Activate your account from the Link in your email');
|
||||
}
|
||||
|
||||
function test()
|
||||
{
|
||||
$u = new User();
|
||||
$u->id = 'chris@chris.ch';
|
||||
$u->email = 'chris@chris.ch';
|
||||
$u->password = '123456';
|
||||
$u->save();
|
||||
|
||||
return nl2br(print_r($u, true));
|
||||
}
|
||||
|
||||
function test2()
|
||||
{
|
||||
$u = new User();
|
||||
$response = $u->load('chris@chasdris.ch');
|
||||
|
||||
return nl2br(print_r($response, true));
|
||||
}
|
||||
}
|
30
web/pages/register/register.html
Normal file
30
web/pages/register/register.html
Normal file
@ -0,0 +1,30 @@
|
||||
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto lg:py-0">
|
||||
<div class="w-full bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md xl:p-0 dark:bg-gray-800 dark:border-gray-700">
|
||||
<div class="p-6 space-y-4 md:space-y-6 sm:p-8">
|
||||
<h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white">
|
||||
Register
|
||||
</h1>
|
||||
<div id="response" class="text-gray-900 dark:text-white">
|
||||
<?= $hello ?>
|
||||
</div>
|
||||
<form class="space-y-4 md:space-y-6" hx-post="/register/validate" hx-target="#response">
|
||||
<div>
|
||||
<label for="email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your email</label>
|
||||
<input type="email" name="email" id="email" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="name@company.com" required="">
|
||||
</div>
|
||||
<div>
|
||||
<label for="password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Password</label>
|
||||
<input type="password" name="password" id="password" placeholder="••••••••" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required="">
|
||||
</div>
|
||||
<div>
|
||||
<label for="password2" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Repeat Password</label>
|
||||
<input type="password" name="password2" id="password2" placeholder="••••••••" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required="">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="bg-sky-500 hover:bg-sky-700 p-2 rounded">
|
||||
Account erstellen
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user