Files
web/user.php
T

114 lines
3.9 KiB
PHP

<?php
require_once 'functions/init.php';
require_once 'functions/functions.php';
include_once 'functions/account_functions.php';
// UI Components
foreach (glob('components/user/*.php') as $file)
require_once $file;
$msg = '';
if (isset($_POST['form_id'])) {
switch ($_POST['form_id']) {
case 'signup_form':
$msg = create_user(
$_POST['username'],
$_POST['email'],
$_POST['password'],
$_POST['verify_password'],
4, // TODO: Need to allow for other roles to be created, if the submission is from an administrator or owner.
(!empty($_FILES) ? $_FILES : ''),
(!empty($_POST['crop_x']) ? $_POST['crop_x'] : ''),
(!empty($_POST['crop_y']) ? $_POST['crop_y'] : ''),
(!empty($_POST['crop_width']) ? $_POST['crop_width'] : ''),
$_POST['required_field']
);
if ($msg === true) {
login($_POST['username'], $_POST['password'], false);
header('Location: user.php?action=view&user_id=' . $_SESSION['user_id']);
}
break;
case 'login_form':
$msg = login(
$_POST['username'],
$_POST['password'],
(isset($_POST['stay_logged_in']) ? true : false)
);
if ($msg === true)
if (isset($_GET['redirect']))
header('Location: ' . urldecode($_GET['redirect']));
else
header('Location: .');
break;
case 'reset_pw_form':
$msg = reset_password(
($_SESSION['role_id'] <= admin && $_SESSION['user_id'] != $_POST['user_id'] ? $_POST['user_id'] : $_SESSION['user_id']),
$_POST['new_pw'],
$_POST['verify_new_pw']
);
break;
case 'update_email_form':
$msg = update_email(
($_SESSION['role_id'] <= admin && $_SESSION['user_id'] != $_POST['user_id'] ? $_POST['user_id'] : $_SESSION['user_id']),
$_POST['new_email'],
$_POST['verify_new_email']
);
break;
case 'update_username_form':
$msg = update_username(
($_SESSION['role_id'] <= admin && $_SESSION['user_id'] != $_POST['user_id'] ? $_POST['user_id'] : $_SESSION['user_id']),
$_POST['new_username'],
$_POST['verify_new_username']
);
break;
case 'update_profile_picture_form':
update_profile_picture($_SESSION['user_id']);
break;
case 'request_role_change_form':
request_role_change(
$_SESSION['user_id'],
$_POST['requested_role']
);
break;
case 'delete_account_form':
$msg = delete_account(
($_SESSION['role_id'] <= admin && $_SESSION['user_id'] != $_POST['user_id'] ? $_POST['user_id'] : $_SESSION['user_id']),
$_POST['delete_password'],
$_POST['delete_verify_password']
);
break;
case 'follow':
follow_user($_SESSION['user_id'], $_POST['author_id'], ($_POST['follow'] == 'email_notify' ? 1 : 0));
break;
case 'unfollow':
unfollow_user($_SESSION['user_id'], $_POST['author_id']);
break;
}
echo $msg;
}
include_once 'components/head.php';
switch ($_GET['view']) {
case 'login':
echo login_form(($msg ? $msg : ''));
break;
case 'signup':
echo signup_form(($msg ? $msg : ''));
break;
case 'logout':
logout();
break;
case 'display':
echo (isset($_GET['user_id']) ? user_view($_GET['user_id']) : header('Location: .'));
break;
}
include_once 'components/foot.php';