Continued work on functions needed during install process

This commit is contained in:
xevidos 2020-07-27 13:20:12 -04:00
parent 9530cd2580
commit 74bba55567
10 changed files with 362 additions and 26 deletions

View File

@ -22,9 +22,16 @@ class Data {
);
public $connection = null;
public $fss = null;
protected static $instance = null;
function __construct() {}
function __construct() {
if( DBTYPE === "filesystem" ) {
$this->fss = FileSystemStorage::get_instance();
}
}
public function close() {
@ -140,8 +147,57 @@ class Data {
if( is_callable( $query ) ) {
$return = call_user_func( $query );
} else {
try {
$connection = $this->connect();
$statement = $connection->prepare( $query );
$statement->execute( $bind_variables );
switch( $action ) {
case( 'rowCount' ):
$return = $statement->rowCount();
break;
case( 'fetch' ):
$return = $statement->fetch( \PDO::FETCH_ASSOC );
break;
case( 'fetchAll' ):
$return = $statement->fetchAll( \PDO::FETCH_ASSOC );
break;
case( 'fetchColumn' ):
$return = $statement->fetchColumn();
break;
default:
$return = $statement->fetchAll( \PDO::FETCH_ASSOC );
break;
}
} catch( Throwable $error ) {
$return = $default;
if( $errors == "message" ) {
$return = json_encode( array( $error->getMessage() ) );
} elseif( $errors == "exception" ) {
throw $error;
}
}
$this->close();
}
return $return;
}
}

View File

@ -2,6 +2,9 @@
require_once( "filesystemstorage/class.data.php" );
require_once( "filesystemstorage/class.user.php" );
class FileSystemStorage {
protected static $instance = null;
@ -83,7 +86,9 @@ class FileSystemStorage {
}
} else {
$return["data"] = $i->get_data( $fields );
$return["status"] = "success";
$return["message"] = "";
$return["value"] = $i->get_data( $fields );
}
} else {
@ -339,16 +344,16 @@ class FileSystemStorage {
if( is_callable( $update ) ) {
$data = file_get_contents( $path );
$handle = fopen( $path, "w+" );
if( flock( $handle, LOCK_EX ) ) {
$data = fread( $handle, filesize( $path ) );
$c = unserialize( $data );
try {
$c->set_data( $update( $c->get_data() ) );
$c->set_data( $update( $c->headers, $c->get_data() ) );
} catch( Throwable $e ) {
$return["status"] = "error";

View File

@ -40,7 +40,7 @@ class Data {
//Add checks to validate Data with headers
//$this->data = $data;
$return = \Common::get_default_return();
return false;
}
public function set_meta( $meta, $uniques = array() ) {

View File

@ -0,0 +1,56 @@
<?php
namespace FileSystemStorage;
class User {
protected static $instance = null;
function __construct() {}
public static function create_user( $user ) {
global $data;
$result = $data->fss->update_data( "users", self::create_user_call );
echo var_dump( $result );
return;
}
public static function create_user_callback( $headers, $d ) {
$new = array();
foreach( $headers as $h ) {
if( isset( $user[$h] ) ) {
$new[$h] = $user[$h];
}
}
$d[] = $data;
return $d;
}
/**
* Return an instance of this class.
*
* @since ${current_version}
* @return object A single instance of this class.
*/
public static function get_instance() {
if( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
public static function get_users() {
global $data;
return $data->fss->get_data( "users" );
}
}
?>

View File

@ -63,23 +63,19 @@ class Initialize {
}
}
$this->register_constants();
$this->register_globals();
$bases = self::BASES;
$this->register_constants();
foreach( $bases as $base ) {
$name = strtolower( $base );
$class = ucfirst( $base );
require_once( COMPONENTS . "/$name/class.$name.php" );
if( class_exists( $class ) ) {
$class::get_instance();
}
}
$this->register_globals();
if( ! $installing ) {
$this->check_extensions();
@ -219,7 +215,7 @@ class Initialize {
global $data;
$data = null;
$data = Data::get_instance();
}
}

View File

@ -25,8 +25,9 @@ class Options {
public function get_option( $option ) {
global $data;
$query = array(
"*" => "SELECT * FROM user_options WHERE name=? AND user=?",
"default" => "SELECT * FROM user_options WHERE name=? AND user=?",
"pgsql" => 'SELECT value FROM user_options WHERE name=? AND "user"=?;',
"filesystem" => array(
"options",
@ -34,8 +35,7 @@ class Options {
$option
),
);
$Data = Data::get_instance();
return $Data->query( $query );
return $data->query( $query );
}
public function update_option( $option, $value ) {}

View File

@ -0,0 +1,24 @@
<?php
class Permissions {
const LEVELS = array(
"none" => 0,
"read" => 1,
"write" => 2,
"create" => 4,
"delete" => 8,
"manager" => 16,
"owner" => 32,
"admin" => 64,
);
const SYSTEM_LEVELS = array(
"user" => 32,
"admin" => 64,
);
function __construct() {}
}

View File

@ -0,0 +1,98 @@
<?php
class User {
protected static $instance = null;
function __construct() {}
function create_user( $user ) {
global $data;
$pass = true;
$return = Common::get_default_return();
$requirements = array(
"username",
"password",
"password1",
"access",
);
foreach( $requirements as $r ) {
if( ! isset( $user[$r] ) ) {
$return["status"] = "error";
$return["message"] = "Error, $r is required but was not provided.";
$pass = false;
break;
}
}
if( $pass && $user["password"] !== $user["password1"] ) {
$return["status"] = "error";
$return["message"] = "Error, the passwords provided do not match.";
$pass = false;
}
if( $pass ) {
$query = array(
"default" => "INSERT INTO users( username, password, access, project ) VALUES ( ?, ?, ?, ? );",
"filesystem" => array( "FileSystemStorage\\User", "create_user", $user ),
);
$bind_vars = array(
$user["username"],
$user["password"],
$user["access"],
null,
);
$return = $data->query( $query, array(), array() );
}
return $return;
}
/**
* Return an instance of this class.
*
* @since ${current_version}
* @return object A single instance of this class.
*/
public static function get_instance() {
if( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
function get_user( $identifier ) {
if( is_int( ) ) {
} else {
}
}
function get_user_by_id( $id ) {}
function get_user_by_username( $username ) {}
function get_users() {
global $data;
$query = array(
"default" => "SELECT * FROM users",
"filesystem" => array( "FileSystemStorage\\User", "get_users" ),
);
return $data->query( $query, array(), array() );
}
}
?>

View File

@ -1,5 +1,5 @@
<?php
define( 'DBTYPE', "filesystem" );
ini_set( 'display_errors', 1 );
ini_set( 'display_startup_errors', 1 );
error_reporting( E_ALL );
@ -8,6 +8,22 @@ require_once( __DIR__ . "/../components/initialize/class.initialize.php" );
Initialize::get_instance();
require_once( __DIR__ . "/../components/user/class.user.php" );
//$data->install( "filesystem" );
$u = User::get_instance();
echo var_dump( $u->create_user( array(
"username" => "test",
"password" => "test",
"password1" => "test",
"access" => 0,
) ) );
exit();
$checks_html = "";
$check_paths = Initialize::PATHS;
$extensions = Initialize::EXTENSIONS;
@ -110,6 +126,19 @@ if( isset( $_POST["storage"] ) ) {
exit( json_encode( $return ) );
}
if( isset( $_POST["username"] ) ) {
$pass = true;
$return = Common::get_default_return();
$User = User::get_instance();
if( $pass ) {
}
exit( json_encode( $return ) );
}
$components = scandir( COMPONENTS );
unset( $components["."], $components[".."] );

View File

@ -38,7 +38,7 @@
init: function() {
let _this = this;
let _ = this;
this.d = {
@ -58,35 +58,107 @@
},
dbhost: {
conditions: $.extend( true, {}, _this.dbconditions ),
conditions: $.extend( true, {}, _.dbconditions ),
default: "localhost",
label: "Database Host: ",
type: "text",
},
dbname: {
conditions: $.extend( true, {}, _this.dbconditions ),
conditions: $.extend( true, {}, _.dbconditions ),
default: "",
label: "Database Name: ",
type: "text",
},
dbuser: {
conditions: $.extend( true, {}, _this.dbconditions ),
conditions: $.extend( true, {}, _.dbconditions ),
default: "",
label: "Database User: ",
type: "text",
},
dbpass: {
conditions: $.extend( true, {}, _this.dbconditions ),
conditions: $.extend( true, {}, _.dbconditions ),
default: "",
label: "Database Password: ",
type: "text",
},
dbpass1: {
conditions: $.extend( true, {}, _this.dbconditions ),
conditions: $.extend( true, {}, _.dbconditions ),
default: "",
label: "Repeat Password: ",
type: "text",
},
};
this.form = new codiad.forms({
data: _.d,
container: $( "#installation" ),
submit_label: "Check Data Storage Method",
});
this.form.submit = async function() {
let _this = this;
let invalid_values;
if( _this.saving ) {
return;
}
_this.saving = true;
let data = await _this.m.get_values();
let submit = _this.v.controls.find( `[type="submit"]` );
submit.attr( "disabled", true );
submit.text( "Submitting ..." );
let response = await codiad.common.ajax( "./index.php", "POST", data );
console.log( response );
let r = JSON.parse( response );
if( r.status == "error" ) {
codiad.message.error( r.message );
$( "#data_status" ).html( "<br><br>Data Status:<br>" + r.value );
} else {
_.user_setup();
}
submit.text( _this.submit_label );
submit.attr( "disabled", false );
_this.saving = false;
}
},
user_setup: function() {
let _this = this;
this.d = {
username: {
default: "",
label: "Username: ",
type: "text",
},
email: {
default: "",
label: "Email: ",
type: "email",
},
password: {
default: "",
label: "Password: ",
type: "text",
},
password: {
default: "",
label: "Repeat Password: ",
type: "text",
@ -95,7 +167,7 @@
this.form = new codiad.forms({
data: _this.d,
container: $( "#installation" ),
submit_label: "Check Data Storage Method",
submit_label: "Create User",
});
this.form.submit = async function() {
@ -130,6 +202,6 @@
submit.attr( "disabled", false );
_this.saving = false;
}
}
},
};
})( this, jQuery );