This repository has been archived on 2023-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
dogstats/web/pages/profile/controller.php
Chris 33a21003c5
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
error message
2023-10-30 22:45:42 +01:00

86 lines
3.3 KiB
PHP

<?php
class Profile extends Page {
function index()
{
$this->set('user', $_SESSION['user']->data);
$this->set('template', 'profile.html');
}
function edit()
{
if($_REQUEST['submit']=='true')
{
$error = false;
$_SESSION['user']->data['firstname'] = trim($_REQUEST['firstname']);
$_SESSION['user']->data['lastname'] = trim($_REQUEST['lastname']);
//$_SESSION['user']->data['email'] = $_REQUEST['email'];
$_SESSION['user']->data['birthday'] = $_REQUEST['birthday'];
$_SESSION['user']->data['club'] = trim($_REQUEST['club']);
//$_SESSION['user']->data['timezone'] = $_REQUEST['timezone'];
if(!strtotime($_SESSION['user']->data['birthday']))
$error = 'Das Geburstdatum ist ungültig. Bitte die Eingabe prüfen';
$newphoto = false;
if($_FILES['photo'])
{
$photo = $_FILES['photo'];
$photo_name = $photo['name'];
$photo_tmp_name = $photo['tmp_name'];
$photo_size = $photo['size'];
$photo_error = $photo['error'];
$photo_type = $photo['type'];
$allowed = ['jpg','jpeg','png','gif'];
$photo_ext = strtolower(end(explode('.', $photo_name)));
if(in_array($photo_ext, $allowed))
{
if($photo_error === 0)
{
if($photo_size < 10000000)
{
$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']);
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Beim Upload der Datei ist ein Fehler aufgetreten']);
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieser Dateityp ist nicht erlaubt. Bitte nur jpg, jpeg oder png Dateien hochladen']);
}
if($newphoto)
$_SESSION['user']->data['photo'] = $newphoto;
try{
$_SESSION['user']->save();
}
catch(Exception $e)
{
return partial('error.html', ['errorMessage' => 'Fehler beim Speichern des Profils: '.$e->getMessage()]);
}
$this->redirect('/profile');
}
$this->set('user', $_SESSION['user']->data);
$this->set('template', 'edit_profile.html');
}
function maySeeThisPage() {
if($_SESSION['user']) //wenn eingeloggt, kein problem
return true;
else return false;
}
}