2021-07-10 19:18:17 +01:00
|
|
|
<?php
|
2021-07-10 18:21:03 -04:00
|
|
|
define('IN_PONEPASTE', 1);
|
|
|
|
require_once('includes/common.php');
|
2021-07-10 19:18:17 +01:00
|
|
|
require_once('includes/functions.php');
|
2021-07-24 14:45:46 -04:00
|
|
|
require_once('includes/passwords.php');
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-11-01 16:56:17 -04:00
|
|
|
use PonePaste\Models\Paste;
|
|
|
|
|
2021-07-10 19:18:17 +01:00
|
|
|
// Check if already logged in
|
2021-07-17 18:17:29 -04:00
|
|
|
if ($current_user === null) {
|
2021-07-12 09:03:02 -04:00
|
|
|
header("Location: ./login.php");
|
2021-07-17 18:17:29 -04:00
|
|
|
die();
|
2021-07-10 19:18:17 +01:00
|
|
|
}
|
2021-07-17 18:17:29 -04:00
|
|
|
|
|
|
|
$user_username = $current_user->username;
|
2021-07-11 12:44:31 -04:00
|
|
|
$row = $query->fetch();
|
2021-11-01 16:56:17 -04:00
|
|
|
$user_id = $current_user->id;
|
|
|
|
$user_date = $current_user->date;
|
|
|
|
$user_ip = $current_user->ip;
|
|
|
|
$user_password = $current_user->password;
|
2021-07-10 19:18:17 +01:00
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
|
if (isset($_POST['cpassword'])) {
|
2021-07-12 09:03:02 -04:00
|
|
|
$user_new_full = trim(htmlspecialchars($_POST['full']));
|
|
|
|
$user_old_pass = $_POST['old_password'];
|
2021-07-17 12:33:08 -04:00
|
|
|
if (pp_password_verify($user_old_pass, $user_password)) {
|
|
|
|
$user_new_cpass = pp_password_hash($_POST['password']);
|
2021-07-11 12:44:31 -04:00
|
|
|
|
2021-07-24 14:45:46 -04:00
|
|
|
$conn->prepare('UPDATE users SET password = ? WHERE id = ?')
|
|
|
|
->execute([$user_new_cpass, $user_id]);
|
2021-07-11 12:44:31 -04:00
|
|
|
|
2021-08-26 05:35:21 -04:00
|
|
|
$success = 'Your profile has been updated.';
|
2021-07-10 19:18:17 +01:00
|
|
|
} else {
|
2021-08-26 05:35:21 -04:00
|
|
|
$error = 'Your old password is incorrect.';
|
2021-07-10 19:18:17 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-08-26 05:35:21 -04:00
|
|
|
$error = 'All fields must be filled out.';
|
2021-07-10 19:18:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-11 12:44:31 -04:00
|
|
|
updatePageViews($conn);
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-11-01 16:56:17 -04:00
|
|
|
$total_user_pastes = Paste::where('user_id', $current_user->user_id)->count();
|
2021-07-10 19:18:17 +01:00
|
|
|
|
|
|
|
// Theme
|
2021-08-22 21:45:26 -04:00
|
|
|
$page_template = 'profile';
|
2021-08-26 05:35:21 -04:00
|
|
|
$page_title = 'My Profile';
|
2021-08-22 21:45:26 -04:00
|
|
|
require_once('theme/' . $default_theme . '/common.php');
|
|
|
|
|