generated from jric11/baseProject
a bunch of stuff happened. I'll do better next commit...
This commit is contained in:
+33
-26
@@ -8,7 +8,6 @@ class Users extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
|
||||
private $current_user_serial = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
@@ -25,6 +24,8 @@ class Users extends Base {
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->current_user_serial = (int) ($_SESSION[self::USER_SERIAL] ?? 0);
|
||||
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
$this->pagination_page = $_SESSION[self::PAGINATION_PAGE] ?? 1;
|
||||
@@ -120,18 +121,18 @@ class Users extends Base {
|
||||
|
||||
( user_name,
|
||||
user_email,
|
||||
user_client_name,
|
||||
user_password,
|
||||
user_first_name,
|
||||
user_password_hash,
|
||||
user_role,
|
||||
user_change_password,
|
||||
user_active,
|
||||
user_status,
|
||||
user_creator,
|
||||
user_created )
|
||||
|
||||
values ( :user_name,
|
||||
:user_email,
|
||||
:user_client_name,
|
||||
:user_password,
|
||||
:user_password_hash,
|
||||
:user_role,
|
||||
:user_change_password,
|
||||
:user_active,
|
||||
@@ -143,10 +144,10 @@ class Users extends Base {
|
||||
$statement->bindValue(":user_name", $user_name);
|
||||
$statement->bindValue(":user_email", $user_email);
|
||||
$statement->bindValue(":user_client_name", $user_client_name);
|
||||
$statement->bindValue(":user_password", $user_temp_password);
|
||||
$statement->bindValue(":user_password_hash", $user_temp_password);
|
||||
$statement->bindValue(":user_role", $user_role);
|
||||
$statement->bindValue(":user_change_password", $user_change_password, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":user_active", $user_active, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":user_active", $user_active ? 'active' : 'inactive');
|
||||
$statement->bindValue(":user_creator", $this->current_user_name);
|
||||
$statement->bindValue(":user_created", $this->getTimestamp());
|
||||
|
||||
@@ -241,9 +242,9 @@ class Users extends Base {
|
||||
$SQL = "update users
|
||||
set user_name = :user_name,
|
||||
user_email = :user_email,
|
||||
user_client_name = :user_client_name,
|
||||
user_first_name = :user_client_name,
|
||||
user_role = :user_role,
|
||||
user_active = :user_active,
|
||||
user_status = :user_active,
|
||||
user_changer = :user_changer,
|
||||
user_changed = :user_changed
|
||||
where user_serial = :user_serial";
|
||||
@@ -255,7 +256,7 @@ class Users extends Base {
|
||||
$statement->bindValue(":user_email", $user_email);
|
||||
$statement->bindValue(":user_client_name", $user_client_name);
|
||||
$statement->bindValue(":user_role", $user_role);
|
||||
$statement->bindValue(":user_active", $user_active, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":user_active", $user_active ? 'active' : 'inactive');
|
||||
$statement->bindValue(":user_changer", $this->current_user_name);
|
||||
$statement->bindValue(":user_changed", $this->getTimestamp());
|
||||
|
||||
@@ -288,11 +289,9 @@ class Users extends Base {
|
||||
|
||||
public function getUserByUserName($user_name) {
|
||||
|
||||
$SQL = "select view_users.*
|
||||
from view_users
|
||||
where user_name = '{$user_name}'";
|
||||
|
||||
return $this->getTable("user", $SQL);
|
||||
$statement = $this->connect()->prepare('select * from view_users where user_name = :user_name');
|
||||
$statement->execute([':user_name' => $user_name]);
|
||||
return $this->getTableXML('user', $statement);
|
||||
}
|
||||
|
||||
// =====================
|
||||
@@ -484,9 +483,9 @@ class Users extends Base {
|
||||
// Change Password
|
||||
// ===============
|
||||
|
||||
public function changePassword() {
|
||||
public function changePassword($forcePrompt = false) {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
$step = $forcePrompt ? 'prompt' : (filter_input(INPUT_POST, "step") ?: "prompt");
|
||||
|
||||
switch ($step) {
|
||||
|
||||
@@ -502,12 +501,19 @@ class Users extends Base {
|
||||
|
||||
case "change":
|
||||
|
||||
if (!$this->validAuthRequest()) {
|
||||
http_response_code(403);
|
||||
return;
|
||||
}
|
||||
|
||||
$user_serial = $_SESSION[self::USER_SERIAL];
|
||||
$user_new_password = filter_input(INPUT_POST, "user_new_password") ?: "";
|
||||
$user_verify_password = filter_input(INPUT_POST, "user_verify_password") ?: "";
|
||||
|
||||
if (!$user_new_password == $user_verify_password) {
|
||||
$this->initializeSession();
|
||||
if ($user_serial <= 0 || $user_new_password === '' || $user_new_password !== $user_verify_password) {
|
||||
http_response_code(422);
|
||||
echo 'Enter a nonempty password and matching confirmation.';
|
||||
return;
|
||||
}
|
||||
|
||||
$user_new_hashed_password = password_hash($user_new_password, PASSWORD_DEFAULT);
|
||||
@@ -517,7 +523,7 @@ class Users extends Base {
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "update users
|
||||
set user_password = :user_password,
|
||||
set user_password_hash = :user_password_hash,
|
||||
user_change_password = :user_change_password,
|
||||
user_changer = :user_changer,
|
||||
user_changed = :user_changed
|
||||
@@ -526,7 +532,7 @@ class Users extends Base {
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_password", $user_new_hashed_password);
|
||||
$statement->bindValue(":user_password_hash", $user_new_hashed_password);
|
||||
$statement->bindValue(":user_change_password", 0);
|
||||
$statement->bindValue(":user_changer", $this->current_user_name);
|
||||
$statement->bindValue(":user_changed", $this->getTimestamp());
|
||||
@@ -536,6 +542,7 @@ class Users extends Base {
|
||||
}
|
||||
|
||||
(new Journal())->journalEntry("{$_SESSION[self::USER_NAME]} changed their password.");
|
||||
session_regenerate_id(true);
|
||||
|
||||
break;
|
||||
|
||||
@@ -567,14 +574,14 @@ class Users extends Base {
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "update users
|
||||
set user_password = :user_password,
|
||||
set user_password_hash = :user_password_hash,
|
||||
user_change_password = :user_change_password
|
||||
where user_serial = :user_serial";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_password", $user_temp_password);
|
||||
$statement->bindValue(":user_password_hash", $user_temp_password);
|
||||
$statement->bindValue(":user_change_password", 1);
|
||||
|
||||
if (!$statement->execute()) {
|
||||
@@ -599,7 +606,7 @@ class Users extends Base {
|
||||
public function updateLogin() {
|
||||
|
||||
$SQL = "update users
|
||||
set user_login = :user_login
|
||||
set user_last_login = :user_login
|
||||
where user_serial = :user_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
@@ -620,7 +627,7 @@ class Users extends Base {
|
||||
$user_active = filter_input(INPUT_POST, "user_active", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$SQL = "update users
|
||||
set user_active = :user_active,
|
||||
set user_status = :user_active,
|
||||
user_changed = :user_changed,
|
||||
user_changer = :user_changer
|
||||
where user_serial = :user_serial";
|
||||
@@ -628,7 +635,7 @@ class Users extends Base {
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_active", $user_active);
|
||||
$statement->bindValue(":user_active", $user_active ? 'active' : 'inactive');
|
||||
$statement->bindValue(":user_changed", $this->getTimestamp());
|
||||
$statement->bindValue(":user_changer", $this->current_user_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user