mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
Renamed Profile to Account, Added a user Side nav to seperate various user preference entities
This commit is contained in:
133
post/profile.php
133
post/profile.php
@@ -4,17 +4,15 @@
|
||||
* ITFlow - GET/POST request handler for user profiles (tech/agent)
|
||||
*/
|
||||
|
||||
if (isset($_POST['edit_profile'])) {
|
||||
if (isset($_POST['edit_your_user_details'])) {
|
||||
|
||||
// CSRF Check
|
||||
validateCSRFToken($_POST['csrf_token']);
|
||||
|
||||
$user_id = $session_user_id;
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
$email = sanitizeInput($_POST['email']);
|
||||
$new_password = trim($_POST['new_password']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT user_avatar FROM users WHERE user_id = $user_id");
|
||||
$sql = mysqli_query($mysqli,"SELECT user_avatar FROM users WHERE user_id = $session_user_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$existing_file_name = sanitizeInput($row['user_avatar']);
|
||||
|
||||
@@ -22,21 +20,12 @@ if (isset($_POST['edit_profile'])) {
|
||||
$extended_log_description = '';
|
||||
|
||||
// Email notification when password or email is changed
|
||||
$user_old_email_sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT user_email FROM users WHERE user_id = $user_id"));
|
||||
$user_old_email_sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT user_email FROM users WHERE user_id = $session_user_id"));
|
||||
$user_old_email = $user_old_email_sql['user_email'];
|
||||
|
||||
if (!empty($config_smtp_host) && (!empty($new_password) || $user_old_email !== $email)) {
|
||||
if (!empty($config_smtp_host) && ($user_old_email !== $email)) {
|
||||
|
||||
// Determine exactly what changed
|
||||
if ($user_old_email !== $email && !empty($new_password)) {
|
||||
$details = "Your e-mail address and password were changed. New email: $email.";
|
||||
}
|
||||
elseif ($user_old_email !== $email) {
|
||||
$details = "Your email address was changed. New email: $email.";
|
||||
}
|
||||
elseif (!empty($new_password)) {
|
||||
$details = "Your password was changed.";
|
||||
}
|
||||
$details = "Your email address was changed. New email: $email.";
|
||||
|
||||
$subject = "$config_app_name account update confirmation for $name";
|
||||
$body = "Hi $name, <br><br>Your $config_app_name account has been updated, details below: <br><br> <b>$details</b> <br><br> If you did not perform this change, contact your $config_app_name administrator immediately. <br><br>Thanks, <br>ITFlow<br>$session_company_name";
|
||||
@@ -61,15 +50,15 @@ if (isset($_POST['edit_profile'])) {
|
||||
$file_tmp_path = $_FILES['file']['tmp_name'];
|
||||
|
||||
// directory in which the uploaded file will be moved
|
||||
$upload_file_dir = "uploads/users/$user_id/";
|
||||
$upload_file_dir = "uploads/users/$session_user_id/";
|
||||
$dest_path = $upload_file_dir . $new_file_name;
|
||||
move_uploaded_file($file_tmp_path, $dest_path);
|
||||
|
||||
// Delete old file
|
||||
unlink("uploads/users/$user_id/$existing_file_name");
|
||||
unlink("uploads/users/$session_user_id/$existing_file_name");
|
||||
|
||||
// Set Avatar
|
||||
mysqli_query($mysqli,"UPDATE users SET user_avatar = '$new_file_name' WHERE user_id = $user_id");
|
||||
mysqli_query($mysqli,"UPDATE users SET user_avatar = '$new_file_name' WHERE user_id = $session_user_id");
|
||||
|
||||
// Extended Logging
|
||||
$extended_log_description .= ", profile picture updated";
|
||||
@@ -81,38 +70,12 @@ if (isset($_POST['edit_profile'])) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($new_password)) {
|
||||
$new_password = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
$user_specific_encryption_ciphertext = encryptUserSpecificKey($_POST['new_password']);
|
||||
mysqli_query($mysqli,"UPDATE users SET user_password = '$new_password', user_specific_encryption_ciphertext = '$user_specific_encryption_ciphertext' WHERE user_id = $user_id");
|
||||
|
||||
$extended_log_description .= ", password changed";
|
||||
$logout = true;
|
||||
}
|
||||
|
||||
// Enable extension access, only if it isn't already setup (user doesn't have cookie)
|
||||
if (isset($_POST['extension']) && $_POST['extension'] == 'Yes') {
|
||||
if (!isset($_COOKIE['user_extension_key'])) {
|
||||
$extension_key = randomString(156);
|
||||
mysqli_query($mysqli, "UPDATE users SET user_extension_key = '$extension_key' WHERE user_id = $user_id");
|
||||
|
||||
$extended_log_description .= ", extension access enabled";
|
||||
$logout = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Disable extension access
|
||||
if (!isset($_POST['extension'])) {
|
||||
mysqli_query($mysqli, "UPDATE users SET user_extension_key = '' WHERE user_id = $user_id");
|
||||
$extended_log_description .= ", extension access disabled";
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"UPDATE users SET user_name = '$name', user_email = '$email' WHERE user_id = $user_id");
|
||||
mysqli_query($mysqli,"UPDATE users SET user_name = '$name', user_email = '$email' WHERE user_id = $session_user_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'User Preferences', log_action = 'Modify', log_description = '$session_name modified their preferences$extended_log_description', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'User Details', log_action = 'Modify', log_description = '$session_name modified their details $extended_log_description', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||
|
||||
$_SESSION['alert_message'] = "User preferences updated";
|
||||
$_SESSION['alert_message'] = "User details updated";
|
||||
|
||||
if ($logout) {
|
||||
header('Location: post.php?logout');
|
||||
@@ -122,6 +85,80 @@ if (isset($_POST['edit_profile'])) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_your_user_password'])) {
|
||||
|
||||
// CSRF Check
|
||||
validateCSRFToken($_POST['csrf_token']);
|
||||
|
||||
$new_password = trim($_POST['new_password']);
|
||||
|
||||
// Email notification when password or email is changed
|
||||
$user_sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT user_name, user_email FROM users WHERE user_id = $session_user_id"));
|
||||
$name = $user_sql['user_name'];
|
||||
$user_email = $user_sql['user_email'];
|
||||
|
||||
if (!empty($config_smtp_host)){
|
||||
|
||||
$details = "Your password was changed.";
|
||||
|
||||
$subject = "$config_app_name account update confirmation for $name";
|
||||
$body = "Hi $name, <br><br>Your $config_app_name account has been updated, details below: <br><br> <b>$details</b> <br><br> If you did not perform this change, contact your $config_app_name administrator immediately. <br><br>Thanks, <br>ITFlow<br>$session_company_name";
|
||||
|
||||
$data = [
|
||||
[
|
||||
'from' => $config_mail_from_email,
|
||||
'from_name' => $config_mail_from_name,
|
||||
'recipient' => $user_email,
|
||||
'recipient_name' => $name,
|
||||
'subject' => $subject,
|
||||
'body' => $body
|
||||
]
|
||||
];
|
||||
$mail = addToMailQueue($mysqli, $data);
|
||||
}
|
||||
|
||||
$new_password = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
$user_specific_encryption_ciphertext = encryptUserSpecificKey($_POST['new_password']);
|
||||
mysqli_query($mysqli,"UPDATE users SET user_password = '$new_password', user_specific_encryption_ciphertext = '$user_specific_encryption_ciphertext' WHERE user_id = $session_user_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'User Preferences', log_action = 'Modify', log_description = '$session_name changed their password', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Your password was updated";
|
||||
|
||||
header('Location: post.php?logout');
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_your_user_browser_extention'])) {
|
||||
|
||||
// CSRF Check
|
||||
validateCSRFToken($_POST['csrf_token']);
|
||||
|
||||
// Enable extension access, only if it isn't already setup (user doesn't have cookie)
|
||||
if (isset($_POST['extension']) && $_POST['extension'] == 'Yes') {
|
||||
if (!isset($_COOKIE['user_extension_key'])) {
|
||||
$extension_key = randomString(156);
|
||||
mysqli_query($mysqli, "UPDATE users SET user_extension_key = '$extension_key' WHERE user_id = $session_user_id");
|
||||
|
||||
$extended_log_description .= "enabled browser extension access";
|
||||
$logout = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Disable extension access
|
||||
if (!isset($_POST['extension'])) {
|
||||
mysqli_query($mysqli, "UPDATE users SET user_extension_key = '' WHERE user_id = $session_user_id");
|
||||
$extended_log_description .= "disabled browser extension access";
|
||||
}
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'User Preferences', log_action = 'Modify', log_description = '$session_name $extended_log_description', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||
|
||||
$_SESSION['alert_message'] = "User preferences updated";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
}
|
||||
|
||||
|
||||
if (isset($_POST['verify'])) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user