Compare commits

...

2 Commits

Author SHA1 Message Date
Chris 8656fd5d60 Merge branch 'master' of gitea.haschek.at:Crispi/dogstats
Build and push / Pulling repo on server (push) Successful in 3s Details
2023-10-30 19:27:46 +01:00
Chris 298e8e6cd1 implemented profile 2023-10-30 19:27:44 +01:00
8 changed files with 57 additions and 226 deletions

View File

@ -9,6 +9,8 @@ class User extends Model {
'email' => ['type'=>'email','unique'],
'firstname' => ['type'=>'text'],
'lastname' => ['type'=>'text'],
'birthday' => ['type' => 'text'],
'club' => ['type'=>'text'],
'last_login' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'],
'token' => ['type'=>'text','required','unique','autoValMethod'=>'uuid4'],
'timezone' => ['type'=>'int'],

View File

@ -90,9 +90,9 @@ class Dogs extends Page {
$dog_size = intval($_REQUEST['dog_size']);
$dog_birthday = $_REQUEST['dog_birthday'];
$agi_height_category = $_REQUEST['agi_height_category'];
$newphoto = false;
$active = intval($_REQUEST['agi_active']);
$newphoto = false;
if($_FILES['photo'])
{
$photo = $_FILES['photo'];
@ -104,8 +104,6 @@ class Dogs extends Page {
$allowed = ['jpg','jpeg','png','gif'];
$photo_ext = strtolower(end(explode('.', $photo_name)));
$photo_name = $name.'.'.$photo_ext;
$photo_path = 'uploads/'.$photo_name;
if(in_array($photo_ext, $allowed))
{

View File

@ -1,9 +0,0 @@
<?php
class Features extends Page {
function index() {
$this->set('template', 'features.html');
}
}

View File

@ -1,62 +0,0 @@
<section class="text-gray-600 body-font">
<div class="container px-5 py-24 mx-auto">
<h1 class="sm:text-3xl text-2xl font-medium title-font text-center text-gray-900 mb-20">Raw Denim Heirloom Man Braid
<br class="hidden sm:block">Selfies Wayfarers
</h1>
<div class="flex flex-wrap sm:-m-4 -mx-4 -mb-10 -mt-4 md:space-y-0 space-y-6">
<div class="p-4 md:w-1/3 flex">
<div class="w-12 h-12 inline-flex items-center justify-center rounded-full bg-indigo-100 text-indigo-500 mb-4 flex-shrink-0">
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="w-6 h-6" viewBox="0 0 24 24">
<path d="M22 12h-4l-3 9L9 3l-3 9H2"></path>
</svg>
</div>
<div class="flex-grow pl-6">
<h2 class="text-gray-900 text-lg title-font font-medium mb-2">Shooting Stars</h2>
<p class="leading-relaxed text-base">Blue bottle crucifix vinyl post-ironic four dollar toast vegan taxidermy. Gastropub indxgo juice poutine, ramps microdosing banh mi pug VHS try-hard ugh iceland kickstarter tumblr live-edge tilde.</p>
<a class="mt-3 text-indigo-500 inline-flex items-center">Learn More
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="w-4 h-4 ml-2" viewBox="0 0 24 24">
<path d="M5 12h14M12 5l7 7-7 7"></path>
</svg>
</a>
</div>
</div>
<div class="p-4 md:w-1/3 flex">
<div class="w-12 h-12 inline-flex items-center justify-center rounded-full bg-indigo-100 text-indigo-500 mb-4 flex-shrink-0">
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="w-6 h-6" viewBox="0 0 24 24">
<circle cx="6" cy="6" r="3"></circle>
<circle cx="6" cy="18" r="3"></circle>
<path d="M20 4L8.12 15.88M14.47 14.48L20 20M8.12 8.12L12 12"></path>
</svg>
</div>
<div class="flex-grow pl-6">
<h2 class="text-gray-900 text-lg title-font font-medium mb-2">The Catalyzer</h2>
<p class="leading-relaxed text-base">Blue bottle crucifix vinyl post-ironic four dollar toast vegan taxidermy. Gastropub indxgo juice poutine, ramps microdosing banh mi pug VHS try-hard ugh iceland kickstarter tumblr live-edge tilde.</p>
<a class="mt-3 text-indigo-500 inline-flex items-center">Learn More
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="w-4 h-4 ml-2" viewBox="0 0 24 24">
<path d="M5 12h14M12 5l7 7-7 7"></path>
</svg>
</a>
</div>
</div>
<div class="p-4 md:w-1/3 flex">
<div class="w-12 h-12 inline-flex items-center justify-center rounded-full bg-indigo-100 text-indigo-500 mb-4 flex-shrink-0">
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="w-6 h-6" viewBox="0 0 24 24">
<path d="M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2"></path>
<circle cx="12" cy="7" r="4"></circle>
</svg>
</div>
<div class="flex-grow pl-6">
<h2 class="text-gray-900 text-lg title-font font-medium mb-2">Neptune</h2>
<p class="leading-relaxed text-base">Blue bottle crucifix vinyl post-ironic four dollar toast vegan taxidermy. Gastropub indxgo juice poutine, ramps microdosing banh mi pug VHS try-hard ugh iceland kickstarter tumblr live-edge tilde.</p>
<a class="mt-3 text-indigo-500 inline-flex items-center">Learn More
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="w-4 h-4 ml-2" viewBox="0 0 24 24">
<path d="M5 12h14M12 5l7 7-7 7"></path>
</svg>
</a>
</div>
</div>
</div>
</div>
</section>

View File

@ -18,6 +18,7 @@ class Login extends Page {
{
if($_SESSION['user'])
{
$this->addSubmenuItem('Profil', '/profile', 'fas fa-user');
$this->addSubmenuItem('Settings', '/settings', 'fas fa-cog');
$this->addSubmenuItem('Logout', '/login/logout', 'fas fa-sign-out-alt', 'bg-red-500');
}

View File

@ -2,47 +2,30 @@
class Profile extends Page {
function setSubmenu()
function index()
{
if($_SESSION['user'] > 0)
$this->set('user', $_SESSION['user']->data);
$this->set('template', 'profile.html');
}
function edit()
{
if($_REQUEST['submit']=='true')
{
$this->addSubmenuItem('Mein Profil','/profile','fa-regular fa-id-badge');
}
}
function index() {
$user = $_SESSION['user'];
}
$error = false;
function delete(){
$dogid = $this->params[0];
$d = new Dog();
$user = $_SESSION['user'];
$user->data['firstname'] = trim($_REQUEST['firstname']);
$user->data['lastname'] = trim($_REQUEST['lastname']);
//$user->data['email'] = $_REQUEST['email'];
$user->data['birthday'] = $_REQUEST['birthday'];
$user->data['club'] = trim($_REQUEST['club']);
//$user->data['timezone'] = $_REQUEST['timezone'];
if(!$d->isMyDog($dogid))
return 'Not your dog :(';
$d->load($dogid);
$d->delete();
$_SESSION['user']->removeDog($dogid);
$this->redirect('/');
}
function edit() {
if($_REQUEST['submit'])
{
$id = $_REQUEST['dog_id'];
$name = $_REQUEST['name'];
$kennel_name = $_REQUEST['kennel_name'];
$dog_breed = $_REQUEST['dog_breed'];
$dog_size = intval($_REQUEST['dog_size']);
$dog_birthday = $_REQUEST['dog_birthday'];
$agi_height_category = $_REQUEST['agi_height_category'];
if(!strtotime($user->data['birthday']))
$error = 'Das Geburstdatum ist ungültig. Bitte die Eingabe prüfen';
$newphoto = false;
$active = intval($_REQUEST['agi_active']);
if($_FILES['photo'])
{
$photo = $_FILES['photo'];
@ -54,8 +37,6 @@ class Profile extends Page {
$allowed = ['jpg','jpeg','png','gif'];
$photo_ext = strtolower(end(explode('.', $photo_name)));
$photo_name = $name.'.'.$photo_ext;
$photo_path = 'uploads/'.$photo_name;
if(in_array($photo_ext, $allowed))
{
@ -66,6 +47,8 @@ class Profile extends Page {
$answer = pictshareUploadImage($photo_tmp_name);
if($answer['status']=='ok' && in_array($answer['filetype'],['jpeg','png','gif']))
$newphoto = $answer['url'];
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Fehler beim CDN Upload: '.json_encode($answer,true)]);
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Die Datei ist zu groß. Bitte eine kleinere Datei hochladen']);
@ -77,96 +60,15 @@ class Profile extends Page {
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieser Dateityp ist nicht erlaubt. Bitte nur jpg, jpeg oder png Dateien hochladen']);
}
$error = false;
if(!$name || !$dog_birthday )
$error = 'Bitte zumindest Name und Geburtsdatum angeben';
else if(!strtotime($dog_birthday))
$error = 'Das Geburstdatum ist ungültig. Bitte die Eingabe prüfen';
if($error){
$this->set('errorMessage', $error);
$this->set('template', '/templates/partials/error.html');
return;
}
else
{
$dog = new Dog();
if($id)
$dog->load($id);
if($newphoto)
$user->data['photo'] = $newphoto;
$dog->name = $name;
$dog->kennel_name = $kennel_name;
$dog->breed = $dog_breed;
$dog->size = $dog_size;
$dog->birthday = $dog_birthday;
$dog->agility_size = $agi_height_category;
$dog->active = $active;
if($newphoto)
$dog->photo = $newphoto;
try
{
$dogid = $dog->save();
}
catch(Exception $e)
{
$this->set('template', '/templates/partials/error.html');
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $e->getMessage());
return;
}
//var_dump($_SESSION['user']->data['dogs']);
if(!is_array($_SESSION['user']->data['dogs']) || !in_array($dogid, $_SESSION['user']->data['dogs'])) // new dog!
{
$_SESSION['user']->data['dogs'][] = $dogid;
try
{
$_SESSION['user']->save();
}
catch(Exception $e)
{
$this->set('template', '/templates/partials/error.html');
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $e->getMessage());
return;
}
$this->redirect('/dogs');
}
else
{
$this->set('template', '/templates/partials/success.html');
$this->set('successMessage', "Daten erfolgreich gespeichert");
return;
}
}
$user->save();
$this->redirect('/profile');
}
else
{
//checken ob der den hund eh bearbeiten darf
$id = $this->params[0];
$dog = new Dog();
$dog->load($id);
$this->set('dogdata',$dog->data);
$this->set('dogid',$dog->id);
$this->set('template', 'edit.html');
}
}
function overview()
{
$dogid = $this->params[0];
$d = new Dog();
if(!$d->isMyDog($dogid))
return 'Not your dog :(';
$d->load($dogid);
$this->set('dogdata', $d->data);
$this->set('dogid', $dogid);
$this->set('template', 'dog.html');
$this->set('user', $_SESSION['user']->data);
$this->set('template', 'edit_profile.html');
}
function maySeeThisPage() {

View File

@ -1,30 +1,29 @@
<div>
<h1>Hund <?= $dogid?'Bearbeiten':'Hinzufügen'; ?></h1>
<h1>Mein Profil bearbeiten</h1>
<form id="dogeditform" hx-post="/dogs/edit" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="dog_id" value="<?= $dogid; ?>">
<div class="mb-3 mb-md-4">
<label for="name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Name</label>
<input type="text" value="<?= $user['name']; ?>" id="name" name="name" class="form-control" placeholder="Max" required>
<form id="dogeditform" hx-post="/profile/edit" hx-encoding='multipart/form-data' hx-target="#response">
<div>
<label for="firstname">Vorname</label>
<input type="text" value="<?= $user['firstname']; ?>" id="firstname" name="firstname" class="form-control" placeholder="Max">
</div>
<div class="mb-3 mb-md-4">
<label for="surname" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Nachname</label>
<input type="text" value="<?= $user['surname']; ?>" id="surname" name="surname" class="form-control" placeholder="Mustermann">
<div>
<label for="lastname">Nachname</label>
<input type="text" value="<?= $user['lastname']; ?>" id="lastname" name="lastname" class="form-control" placeholder="Mustermann">
</div>
<div class="mb-3 mb-md-4">
<label for="user_birthday" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Geburtstag</label>
<input type="date" value="<?= $user['birthday']; ?>" id="user_birthday" name="user_birthday" class="form-control" placeholder="" required>
<div>
<label for="birthday">Geburtstag</label>
<input type="date" value="<?= $user['birthday']; ?>" id="birthday" name="birthday" class="form-control" placeholder="">
</div>
<div class="mb-3 mb-md-4">
<label for="email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">E-Mail</label>
<input type="text" value="<?= $user['email']; ?>" id="email" name="email" class="form-control" placeholder="max@max.com">
<div>
<label for="email">E-Mail</label>
<input type="text" value="<?= $user['email']; ?>" id="email" name="email" class="form-control" placeholder="max@max.com" disabled>
</div>
<div class="mb-3 mb-md-4">
<label for="club" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Verein</label>
<input type="number" value="<?= $user['club']; ?>" id="club" name="club" class="form-control" placeholder="Vereinsname">
<div>
<label for="club">Verein</label>
<input type="text" value="<?= $user['club']; ?>" id="club" name="club" class="form-control" placeholder="Vereinsname">
</div>
<div class="mb-3 mb-md-4">
<label for="photo" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Photo</label>
<div>
<label for="photo">Photo</label>
<input type="file" accept="image/png, image/jpeg, image/gif" id="photo" name="photo">
</div>
<button type="submit" name="submit" value="true" class="btn btn-primary">Speichern</button>

View File

@ -4,19 +4,19 @@
<h1>Profil</h1>
<div class="row">
<div class="col-3">
<img src="<?= $user['photo']?:'https://pictshare.net/1ch3e5.png' ?>/300x170/forcesize" class="card-img-top" alt="<?= escape($user['name']); ?>'s profile Picture">
<img src="<?= $user['photo']?:'https://pictshare.net/pj7vzx.jpg' ?>/300x300/forcesize" class="card-img-top" alt="<?= escape($user['name']); ?>'s profile Picture">
</div>
<div class="col-9">
<h3 class="card-title"><?= escape($user['name']); ?> <?= escape($user['surname']); ?></h3>
<div>
<?php if($user['birthday']): ?><p>Alter: <?= date_diff(date_create($user['birthday']), date_create('now'))->y ?></p> <?php endif; ?>
<?php if($user['email']): ?><p>Rasse: <?= escape($user['email']); ?></p> <?php endif; ?>
<?php if($user['club']): ?><p>Zuchtname: <?= escape($user['club']); ?></p> <?php endif; ?>
<h3 class="card-title"><?= escape($user['firstname'].' '.$user['lastname']); ?></h3>
<div>
<?php if($user['birthday']): ?><p>Geburstag: <?= $user['birthday'].' ('.date_diff(date_create($user['birthday']), date_create('now'))->y.')' ?></p> <?php endif; ?>
<?php if($user['email']): ?><p>Email: <?= escape($user['email']); ?></p> <?php endif; ?>
<?php if($user['club']): ?><p>Verein: <?= escape($user['club']); ?></p> <?php endif; ?>
</div>
<div class="d-flex justify-content-end">
<button type="button" class="btn btn-secondary" hx-get="/user/edit/<?= $userid; ?>" hx-target="#main">
<button type="button" class="btn btn-secondary" hx-get="/profile/edit" hx-target="#main">
<i class="fas fa-edit"></i>
</button>
</div>