ponepaste/public/profile.php

58 lines
1.8 KiB
PHP
Raw Normal View History

2021-07-10 19:18:17 +01:00
<?php
2022-07-30 17:55:17 -04:00
/** @noinspection PhpDefineCanBeReplacedWithConstInspection */
define('IN_PONEPASTE', 1);
require_once(__DIR__ . '/../includes/common.php');
2021-07-10 19:18:17 +01:00
2021-11-01 16:56:17 -04:00
use PonePaste\Models\Paste;
if ($current_user === null) {
2022-04-23 18:22:16 -04:00
header("Location: /login");
die();
2021-07-10 19:18:17 +01:00
}
$user_username = $current_user->username;
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') {
2022-03-14 15:43:01 -04:00
if (!verifyCsrfToken()) {
$error = 'Invalid CSRF token (do you have cookies enabled?)';
} else if (isset($_POST['cpassword']) && !empty($_POST['old_password']) && !empty($_POST['password'])) {
if (pp_password_verify($_POST['old_password'], $user_password)) {
2021-07-17 12:33:08 -04:00
$user_new_cpass = pp_password_hash($_POST['password']);
2021-07-11 12:44:31 -04:00
2021-11-02 08:46:40 -04:00
$current_user->password = $user_new_cpass;
$current_user->save();
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 if (isset($_POST['reset_recovery_code'])) {
if (pp_password_verify($_POST['old_password'], $user_password)) {
$user_new_code = pp_random_token();
$current_user->recovery_code_hash = pp_password_hash($user_new_code);
$current_user->save();
$success = 'Your recovery code has been updated - please see below.';
} else {
$error = 'Your 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
}
}
2022-03-12 13:56:32 -05:00
updatePageViews();
2021-07-10 19:18:17 +01:00
2021-11-02 08:46:40 -04:00
$total_user_pastes = Paste::where('user_id', $current_user->id)->count();
2022-03-14 15:43:01 -04:00
$csrf_token = setupCsrfToken();
2021-07-10 19:18:17 +01:00
2021-08-22 21:45:26 -04:00
$page_template = 'profile';
2021-08-26 05:35:21 -04:00
$page_title = 'My Profile';
2022-07-30 17:55:17 -04:00
require_once(__DIR__ . '/../theme/' . $default_theme . '/common.php');
2021-08-22 21:45:26 -04:00