implemented image upload and cropping system, mostly work. it's too zoomed in and appears to be using the xy coords from the top left of the crop selector.

This commit is contained in:
2025-03-29 22:57:43 -06:00
parent 9a45075010
commit ff7e799b7f
14 changed files with 609 additions and 130 deletions
+120 -76
View File
@@ -29,35 +29,52 @@ function delete_self()
return -1;
}
function create_account($username, $email, $password, $verify_password, $role_id, $profile_picture)
function cookies($user, $time)
{
if ($password != $verify_password) {
$error_msg = '
<div class="error">
Passwords do not match!
</div>
';
setcookie('user_id', $user['user_id'], $time);
setcookie('username', $user['username'], $time);
setcookie('email', $user['email'], $time);
setcookie('role_id', $user['role_id'], $time);
setcookie('profile_picture', $user['profile_picture'], $time);
}
return $error_msg;
function logout()
{
foreach (array_keys($_COOKIE) as $key) {
echo 'unsetting ' . $key . ' now.';
setcookie($key, '', time() - 3600, '/');
unset($_COOKIE[$key]);
}
$password_hash = hash('sha256', $password);
header('Location: articles.php');
}
$id = rand(1000, 999999999);
while (user_id_exists($id))
$id = rand(1000, 999999999);
function login_form($error_msg = '')
{
$form = '
<div class="form_card">
<h3 class="underline">Log In</h3>
<form method="post">
<input type="hidden" name="form_id" value="login_form">
if (!empty($profile_picture)) {
$filetype = explode('.', $profile_picture);
$pic_path = $id . $filetype[count($filetype) - 1];
}
<label for="username">Username / Email</label>
<input id="username" name="username" required>
$stmt = 'INSERT INTO user (user_id, username, email, password_hash, role_id' . (!empty($profile_picture) ? ', profile_picture' : '') . ') VALUES (' . $id . ', "' . $username . '", "' . $email . '", "' . $password_hash . '", ' . $role_id . (!empty($profile_picture) ? '", "' . $pic_path . '"' : '') . ');';
exec_statement($stmt, 0);
<label for="password">Password</label>
<input id="password" name="password" type="password" required>
login($username, $password, false);
<label class="form_checkbox_container">Stay Logged In?
<input name="stay_logged_in" type="checkbox" value="true">
<span class="checkmark"></span>
</label>
return true;
<input class="button" type="submit" value="Log In">
' . $error_msg . '
</form>
</div>
';
return $form;
}
function login($username, $password, $stay_logged_in)
@@ -86,58 +103,17 @@ function login($username, $password, $stay_logged_in)
return true;
}
function cookies($user, $time)
{
setcookie('user_id', $user['user_id'], $time);
setcookie('username', $user['username'], $time);
setcookie('email', $user['email'], $time);
setcookie('role_id', $user['role_id'], $time);
setcookie('profile_picture', $user['profile_picture'], $time);
}
function logout()
{
foreach (array_keys($_COOKIE) as $key) {
echo 'unsetting ' . $key . ' now.';
setcookie($key, '', time() - 3600, '/');
unset($_COOKIE[$key]);
}
header('Location: articles.php');
}
function login_form($error_msg = '')
{
$form = '
<div class="form_card">
<h3 class="underline">Log In</h3>
<form method="post">
<label for="username">Username / Email</label>
<input id="username" name="username" required>
<label for="password">Password</label>
<input id="password" name="password" type="password" required>
<label class="form_checkbox_container">Stay Logged In?
<input name="stay_logged_in" type="checkbox" value="true">
<span class="checkmark"></span>
</label>
<input class="button" type="submit" value="Log In">
' . $error_msg . '
</form>
</div>
';
return $form;
}
function signup_form($error_msg = '')
{
$form = '
<div class="form_card">
<h3 class="underline">Sign Up</h3>
<form method="post">
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="form_id" value="signup_form">
<input type="hidden" name="crop_x" value="" id="crop_x">
<input type="hidden" name="crop_y" value="" id="crop_y">
<input type="hidden" name="crop_width" value="" id="crop_width">
<label for="username">Username</label>
<input id="username" name="username" required>
@@ -150,8 +126,9 @@ function signup_form($error_msg = '')
<label for="verify_password">Verify Password</label>
<input id="verify_password" name="verify_password" type="password" required>
<label for="profile_picture_upload" class="upload_button">Upload a Profile Picture</label>
<input id="profile_picture_upload" name="profile_picture_upload" type="file" accept="image/png, image/jpeg">
<label for="profile_picture" class="upload_button modal_button" id="profile_cropper_button">Upload a Profile Picture</label>
<input id="profile_picture" class="file_input" name="profile_picture" type="file" accept="image/png, image/jpeg, image/jpg">
<small class="file_input_feedback">No file selected.</small>
<label class="form_checkbox_container">Stay Logged In?
<input name="stay_logged_in" type="checkbox" value="true">
@@ -161,12 +138,80 @@ function signup_form($error_msg = '')
<input class="button" type="submit" value="Sign Up">
' . $error_msg . '
</form>
<div id="user_actions_modal" class="modal">
<div id="modal_content">
</div>
</div>
<div style="display: none;">
<div id="profile_cropper" class="modal_form">' . profile_cropper() . '</div>
</div>
</div>
';
return $form;
}
function signup($username, $email, $password, $verify_password, $role_id, $upload = null, $x = null, $y = null, $crop_width = null)
{
if ($password != $verify_password) {
$error_msg = '
<div class="error">
Passwords do not match!
</div>
';
return $error_msg;
}
$password_hash = hash('sha256', $password);
$id = rand(1000, 999999999);
while (user_id_exists($id))
$id = rand(1000, 999999999);
if (!empty($upload)) {
$orig_size = getimagesize($upload['profile_picture']['tmp_name']);
$orig_width = $orig_size[0];
$orig_height = $orig_size[1];
$crop_size = min($orig_width, $orig_height) * .56;
crop_image($upload['profile_picture']['tmp_name'], $x, $y, $crop_size, $crop_size);
$target = upload($upload['profile_picture'], $_ENV['PROFILE_IMAGES_FQ_PATH'], $id);
}
$stmt = 'INSERT INTO user (user_id, username, email, password_hash, role_id' . (!empty($target) ? ', profile_picture' : '') . ') VALUES (' . $id . ', "' . $username . '", "' . $email . '", "' . $password_hash . '", ' . $role_id . (!empty($target) ? ', "' . $target . '"' : '') . ');';
exec_statement($stmt, 0);
login($username, $password, false);
return true;
}
function profile_cropper()
{
$display = '
<div class="form_card">
<img src="IMG_UPLOAD_PATH" id="img_to_crop"/>
<div id="img_crop_selection">
<div class="corner" id="corner_nw"></div>
<div class="corner" id="corner_ne"></div>
<div class="corner" id="corner_sw"></div>
<div class="corner" id="corner_se"></div>
</div>
<div class="row">
<button id="crop_button" class="button">Crop</button>
<button id="crop_cancel" class="button">Cancel</button>
</div>
</div>
';
return $display;
}
function reset_pw_form()
{
$form = '
@@ -413,7 +458,7 @@ function user_view($user_id)
<div class="row">
<h1>' . $user['username'] . '</h1>
<div class="card_pic_box">
<img src="/profile_pictures/' . $user['profile_picture'] . '" class="profile_picture" />
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $user['profile_picture'] . '" class="profile_picture" />
</div>
</div>
<div class="line"></div>
@@ -425,15 +470,14 @@ function user_view($user_id)
// <div id="request_role_form" class="modal_form">' . request_role_change_form() . '</div>
$view .= '
<div class="user_actions">
<a class="modal_button underline">Reset Password</a>
<a class="modal_button underline">Update Email</a>
<a class="modal_button underline">Update Username</a>
<a class="modal_button underline">Delete Account</a>
<button id="reset_pw_form_button" class="modal_button underline">Reset Password</button>
<button id="update_email_form_button" class="modal_button underline">Update Email</button>
<button id="update_username_form_button" class="modal_button underline">Update Username</button>
<button id="delete_account_form_button" class="modal_button underline">Delete Account</button>
</div>
<div id="user_actions_modal" class="modal">
<div class="modal_content">
<div id="modal_content"></div>
<div id="modal_content">
</div>
</div>