Merge branch 'main' of https://github.com/quaxlyqueen/vintagecoding.net
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
$create_account_fields = [
|
||||||
|
'method' => 'post',
|
||||||
|
'action' => 'process.php?action=create_account',
|
||||||
|
'create_account_username' => [
|
||||||
|
'label' => 'username',
|
||||||
|
'type' => 'text',
|
||||||
|
'placeholder' => 'e.g., jsmith',
|
||||||
|
'validators' => [
|
||||||
|
'no_spaces',
|
||||||
|
'check_sql',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'create_account_first_name' => [
|
||||||
|
'label' => 'first name',
|
||||||
|
'type' => 'text',
|
||||||
|
'placeholder' => 'e.g., John',
|
||||||
|
'validators' => [
|
||||||
|
'no_spaces',
|
||||||
|
'only_letters',
|
||||||
|
'check_sql',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'create_account_last_name' => [
|
||||||
|
'label' => 'last name',
|
||||||
|
'type' => 'text',
|
||||||
|
'placeholder' => 'e.g., Smith',
|
||||||
|
'validators' => [
|
||||||
|
'no_spaces',
|
||||||
|
'only_letters',
|
||||||
|
'check_sql',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'create_account_email' => [
|
||||||
|
'label' => 'email address',
|
||||||
|
'type' => 'text',
|
||||||
|
'placeholder' => 'e.g., jsmith@email.com',
|
||||||
|
'validators' => [
|
||||||
|
'valid_email',
|
||||||
|
'check_sql',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'create_account_password' => [
|
||||||
|
'label' => 'password',
|
||||||
|
'type' => 'password',
|
||||||
|
'placeholder' => '',
|
||||||
|
'validators' => [
|
||||||
|
'no_spaces',
|
||||||
|
'pw_strength',
|
||||||
|
'no_backslash',
|
||||||
|
'check_sql',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'verify_create_account_password' => [
|
||||||
|
'label' => 'password',
|
||||||
|
'type' => 'password',
|
||||||
|
'placeholder' => '',
|
||||||
|
'validators' => [
|
||||||
|
'no_spaces',
|
||||||
|
'pw_strength',
|
||||||
|
'no_backslash',
|
||||||
|
'check_sql',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
@@ -8,7 +8,7 @@ $login_fields = [
|
|||||||
'placeholder' => 'e.g., jsmith',
|
'placeholder' => 'e.g., jsmith',
|
||||||
'validators' => [
|
'validators' => [
|
||||||
'no_spaces',
|
'no_spaces',
|
||||||
// 'check_sql',
|
'check_sql',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'login_password' => [
|
'login_password' => [
|
||||||
@@ -17,9 +17,9 @@ $login_fields = [
|
|||||||
'placeholder' => '',
|
'placeholder' => '',
|
||||||
'validators' => [
|
'validators' => [
|
||||||
'no_spaces',
|
'no_spaces',
|
||||||
// 'pw_strength',
|
'pw_strength',
|
||||||
// 'no_backslash',
|
'no_backslash',
|
||||||
// 'check_sql',
|
'check_sql',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,52 +1,121 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Author: Joshua Ashton <me@joshashton.dev>
|
||||||
|
* Date: 06 March 2025
|
||||||
|
* Version: v0.1.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* A data format standard for easily creating forms with input validation.
|
||||||
|
*
|
||||||
|
*
|
||||||
* This file provides functions for validating form input data. For any given
|
* This file provides functions for validating form input data. For any given
|
||||||
* field in an associative array, provide an array of validation requirements.
|
* field in an associative array, provide an array of validation requirements.
|
||||||
* This is to enable modular data fields while ensuring data integrity and
|
* This is to enable modular data fields while ensuring data integrity and
|
||||||
* safety from SQL injection.
|
* safety from SQL injection.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* Each function accepts at least an input string, and will return either true
|
* Each function accepts at least an input string, and will return either true
|
||||||
* or false. It is up to the client to interpret that and create error messages
|
* or false. It is up to the client to interpret that and create error messages
|
||||||
* and ensure data format consistency accordingly.
|
* and ensure data format consistency accordingly.
|
||||||
*
|
*
|
||||||
* EXAMPLE CLIENT DATA IMPLEMENTATION
|
|
||||||
*
|
*
|
||||||
* $standard_fields = [
|
* *****************************************************************************
|
||||||
* 'ca-username' => [
|
|
||||||
* // Placeholder text
|
|
||||||
* 'e.g., jsmith',
|
|
||||||
*
|
*
|
||||||
* // Validation requirements
|
*
|
||||||
* [
|
* EXAMPLE LOGIN DATA IMPLEMENTATION
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* $login_fields = [
|
||||||
|
* 'method' => 'post',
|
||||||
|
* 'action' => 'process.php?action=login',
|
||||||
|
* 'login_username' => [
|
||||||
|
* 'label' => 'username',
|
||||||
|
* 'type' => 'text',
|
||||||
|
* 'placeholder' => 'e.g., jsmith',
|
||||||
|
* 'validators' => [
|
||||||
* 'no_spaces',
|
* 'no_spaces',
|
||||||
* 'checkSQL',
|
* 'check_sql',
|
||||||
|
* ],
|
||||||
|
* ],
|
||||||
|
*
|
||||||
|
* 'login_password' => [
|
||||||
|
* 'label' => 'password',
|
||||||
|
* 'type' => 'password',
|
||||||
|
* 'placeholder' => '',
|
||||||
|
* 'validators' => [
|
||||||
|
* 'no_spaces',
|
||||||
|
* 'pw_strength',
|
||||||
|
* 'no_backslash',
|
||||||
|
* 'check_sql',
|
||||||
* ],
|
* ],
|
||||||
* ],
|
* ],
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* EXAMPLE CLIENT IMPLEMENTATION
|
|
||||||
*
|
*
|
||||||
* function validate($standard_fields, $admin_fields) {
|
* *****************************************************************************
|
||||||
* include('includes/input_validation.php');
|
|
||||||
* $error = '';
|
|
||||||
* foreach($standard_fields as $field => $arr) {
|
|
||||||
* // Get the requirements from the associative array.
|
|
||||||
* $validationRequirements = $arr[1];
|
|
||||||
*
|
*
|
||||||
* foreach($validationRequirements as $validReq) {
|
*
|
||||||
* switch($validReq) {
|
* CLIENT VALIDATION IMPLEMENTATION
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* function validate($input, $validators)
|
||||||
|
* {
|
||||||
|
* include_once ('includes/input_validation.php');
|
||||||
|
*
|
||||||
|
* foreach ($validators as $v) {
|
||||||
|
* switch ($v) {
|
||||||
* case 'no_spaces':
|
* case 'no_spaces':
|
||||||
* if(no_spaces($_POST[$field])) {
|
* if (!no_spaces($input))
|
||||||
* $error .= '<p>' . $field . ' does not allow spaces.</p>';
|
* return false;
|
||||||
* }
|
|
||||||
* break;
|
* break;
|
||||||
* default:
|
* case 'no_digits':
|
||||||
* $error .= '<p>Something went wrong...</p>';
|
* if (!no_digits($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'no_backslash':
|
||||||
|
* if (!no_backslash($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'no_special':
|
||||||
|
* if (!no_special($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'only_digits':
|
||||||
|
* if (!only_digits($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'only_digits_x':
|
||||||
|
* if (!only_digits_x($input, 5))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'only_letters':
|
||||||
|
* if (!only_letters($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'only_letters_x':
|
||||||
|
* if (!only_letters_x($input, 5))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'valid_email':
|
||||||
|
* if (!valid_email($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'valid_phone':
|
||||||
|
* if (!valid_phone($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'pw_strength':
|
||||||
|
* if (!pw_strength($input))
|
||||||
|
* return false;
|
||||||
|
* break;
|
||||||
|
* case 'check_sql':
|
||||||
|
* if (check_sql($input))
|
||||||
|
* return false;
|
||||||
* break;
|
* break;
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
* }
|
* return true;
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -13,10 +13,13 @@ define('USER', $db_user);
|
|||||||
define('PASS', $db_pass);
|
define('PASS', $db_pass);
|
||||||
define('DB', 'vintagecodingdotnet');
|
define('DB', 'vintagecodingdotnet');
|
||||||
|
|
||||||
|
// **************** ACCOUNT QUERIES *************** //
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For use by an administrator.
|
* IMPORTANT: This should only be called once a user has been authorized as an
|
||||||
|
* administrator.
|
||||||
*
|
*
|
||||||
* TODO: Use JOIN to get role, profile picture, etc.
|
* TODO: Use JOIN to get other columns like roles and profile pictures.
|
||||||
*/
|
*/
|
||||||
function get_all_accounts()
|
function get_all_accounts()
|
||||||
{
|
{
|
||||||
@@ -50,6 +53,8 @@ function get_account_role($username)
|
|||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// **************** ARTICLE QUERIES *************** //
|
||||||
|
|
||||||
function get_all_article_cards()
|
function get_all_article_cards()
|
||||||
{
|
{
|
||||||
$conn = mysqli_connect(HOST, USER, PASS, DB);
|
$conn = mysqli_connect(HOST, USER, PASS, DB);
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ switch ($action) {
|
|||||||
unset($_POST['login_password']);
|
unset($_POST['login_password']);
|
||||||
|
|
||||||
// auth() handles setting $_SESSION variables, user is now OK to proceed to home.php.
|
// auth() handles setting $_SESSION variables, user is now OK to proceed to home.php.
|
||||||
// header('Location: ' . $success_location);
|
header('Location: ' . $success_location);
|
||||||
default:
|
default:
|
||||||
// code...
|
// code...
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ create_db() {
|
|||||||
CREATE TABLE accounts (
|
CREATE TABLE accounts (
|
||||||
account_id INT PRIMARY KEY,
|
account_id INT PRIMARY KEY,
|
||||||
username VARCHAR(32) UNIQUE NOT NULL,
|
username VARCHAR(32) UNIQUE NOT NULL,
|
||||||
|
first_name VARCHAR(64) NOT NULL,
|
||||||
|
last_name VARCHAR(64) NOT NULL,
|
||||||
email VARCHAR(64) UNIQUE NOT NULL,
|
email VARCHAR(64) UNIQUE NOT NULL,
|
||||||
password_hash VARCHAR(64) NOT NULL,
|
password_hash VARCHAR(64) NOT NULL,
|
||||||
role INT NOT NULL,
|
role INT NOT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user