AutoPulse v 1.0.1
 
Loading...
Searching...
No Matches
C:/Users/ivans/OneDrive/Документы/ZWA/sem/process-editdata.php File Reference

This script provides validation of user editdata form inputs and updating user data in the database in case of successful validation. More...

Functions

 terminateEditdataWithError ($errorParam)
 
 validateInput ($pattern, $input)
 

Variables

 $person_type = $_POST['person_type'] ?? ''
 
 $first_name = $_POST['first_name'] ?? ''
 
 $last_name = $_POST['last_name'] ?? ''
 
 $company_name = $_POST['company_name'] ?? ''
 
 $current_password = $_POST['current_password'] ?? ''
 
 $new_password = $_POST['new_password'] ?? ''
 
 $confirm_password = $_POST['confirm_password'] ?? ''
 
 $patterns
 
 $isFormValid = true
 
 if (! $isFormValid)
 
if(isset($error) && $error==="db_access_failed") try
 
 $user = $stmt->fetch(PDO::FETCH_ASSOC)
 
if(! $user) if(!password_verify($current_password, $user['password'])) $hashed_password = password_hash($new_password, PASSWORD_BCRYPT)
 
 $stmt
 

Detailed Description

This script provides validation of user editdata form inputs and updating user data in the database in case of successful validation.

Terminates and redirects back to the form page with error context parameter and all the user inputs except passwords as parameters of the redirecting GET request in case of error of data validation or database communication.

Function Documentation

◆ terminateEditdataWithError()

terminateEditdataWithError ( $errorParam)

Redirects to the editdata page with the specified error parameter and current user inputs except passwords, and terminates the script.

Parameters
string$errorParamThe error parameter to be appended to the URL.

◆ validateInput()

validateInput ( $pattern,
$input )

Validates input based on the provided regular expression pattern.

Parameters
string$patternThe regex pattern to validate against.
string$inputThe input to be validated.
Returns
bool True if the input matches the pattern, otherwise false.

Variable Documentation

◆ $company_name

$company_name = $_POST['company_name'] ?? ''

◆ $confirm_password

$confirm_password = $_POST['confirm_password'] ?? ''

◆ $current_password

$current_password = $_POST['current_password'] ?? ''

◆ $first_name

$first_name = $_POST['first_name'] ?? ''

◆ $hashed_password

if(! $user) if (!password_verify( $current_password, $user[ 'password'])) $hashed_password = password_hash($new_password, PASSWORD_BCRYPT)

◆ $isFormValid

$isFormValid = true

◆ $last_name

$last_name = $_POST['last_name'] ?? ''

◆ $new_password

$new_password = $_POST['new_password'] ?? ''

◆ $patterns

$patterns
Initial value:
= [
'first_name' => '/^[a-zA-ZčČřŘžŽáÁíÍéÉěĚýÝůŮúÚóÓďĎťŤňŇ.\-]{2,20}$/',
'last_name' => '/^[a-zA-ZčČřŘžŽáÁíÍéÉěĚýÝůŮúÚóÓďĎťŤňŇ.\-]{2,20}$/',
'company_name' => '/^[a-zA-ZčČřŘžŽáÁíÍéÉěĚýÝůŮúÚóÓďĎťŤňŇ.\- ]{2,20}$/',
'password' => '/^(?=.*[0-9])(?=.*[!@#$%^&*-_])[a-zA-Z0-9!@#$%^&*-_]{8,32}$/'
]

◆ $person_type

$person_type = $_POST['person_type'] ?? ''

◆ $stmt

$stmt
Initial value:
= $pdo->prepare("
UPDATE users
SET
first_name = :first_name,
last_name = :last_name,
company_name = :company_name,
password = :password
WHERE id = :id
")
if(! $user) catch(PDOException $e) $pdo
Definition myprofile.php:59

◆ $user

$user = $stmt->fetch(PDO::FETCH_ASSOC)

◆ if

if(! $isFormValid) ( ! $isFormValid)

◆ try

if (isset( $error) &&$error==="db_access_failed") try
Initial value:
{
$stmt = $pdo->prepare("SELECT `password` FROM users WHERE id = :id")
if(! $userExists) $stmt
Definition process-accountDelete.php:48

Check if there was a database access error and terminate the process if so.