diff --git a/assets/js/codiad.js b/assets/js/codiad.js index e9635e1..936f8ef 100644 --- a/assets/js/codiad.js +++ b/assets/js/codiad.js @@ -1,4 +1,21 @@ ( function( global, $ ) { - var codiad = global.codiad = {}; + var codiad = global.codiad = { + + theme: global.theme, + themes: global.themes, + + init: function() {}, + + addCSS: function( url, container ) { + + console.log( url, container ); + return container.append( `` ); + }, + + addThemeCSS: function( file ) { + + return this.addCSS( `themes/${this.theme}/${file}`, $( 'body,html' ) ); + }, + }; })( this, jQuery ); \ No newline at end of file diff --git a/assets/js/forms.js b/assets/js/forms.js index c5243f6..432a462 100644 --- a/assets/js/forms.js +++ b/assets/js/forms.js @@ -1569,7 +1569,7 @@ values.push( pass ); if( pass ) { - value.element.parent().css( 'color', 'black' ); + value.element.parent().css( 'color', '' ); } else { value.element.parent().css( 'color', 'red' ); diff --git a/assets/js/login.js b/assets/js/login.js new file mode 100644 index 0000000..c145f0a --- /dev/null +++ b/assets/js/login.js @@ -0,0 +1,86 @@ +( function( global, $ ) { + + // Define core + let codiad = global.codiad, + scripts = document.getElementsByTagName( 'script' ), + path = scripts[scripts.length-1].src.split( '?' )[0], + curpath = path.split( '/' ).slice( 0, -1 ).join( '/' ) + '/'; + + $( document ).ready( function() { + + codiad.login.init(); + }); + + codiad.login = { + + form: null, + + init: function() { + + console.log( codiad ); + this.load_styles(); + + let d = { + + username: { + + default: "", + label: "Username: ", + name: "username", + required: true, + type: "text", + }, + password: { + + default: "", + label: "Password: ", + name: "password", + required: true, + type: "text", + }, + }; + this.form = new codiad.forms({ + data: d, + container: $( "#container" ), + submit_label: "Login", + }); + this.form.submit = this.submit; + }, + + load_styles: function() { + + codiad.addThemeCSS( "jquery.toastmessage.css" ); + codiad.addThemeCSS( "reset.css" ); + codiad.addThemeCSS( "fonts.css" ); + codiad.addThemeCSS( "screen.css" ); + codiad.addThemeCSS( "forms/screen.css" ); + }, + + submit: async function() { + + let _this = this; + let submit = _this.v.controls.find( `[type="submit"]` ); + + if( _this.saving ) { + + return; + } + + _this.saving = true; + submit.attr( "disabled", true ); + submit.text( "Submitting ..." ); + + let data = await _this.m.get_values(); + //let response = await codiad.common.ajax( "./index.php", "POST", data ); + + console.log( data ); + + submit.attr( "disabled", true ); + submit.text( "Logging In ..." ); + + submit.text( _this.submit_label ); + submit.attr( "disabled", false ); + _this.saving = false; + }, + }; +})( self, jQuery ); \ No newline at end of file diff --git a/components/authentication/class.authentication.php b/components/authentication/class.authentication.php index f629e7e..78e8ae9 100644 --- a/components/authentication/class.authentication.php +++ b/components/authentication/class.authentication.php @@ -8,61 +8,15 @@ class Authentication { function authenticate( $username, $password ) { - $type = AUTH_TYPE; - $result = false; - $path = "types/$type"; - if( is_file( $path ) ) { - - require_once( $path ); - - $t_class = ucfirst( $type ); - - if( class_exists( $type ) && method_exists( $type, "get_instance" ) ) { - - $t_i = $type::get_instance(); - $result = $t_i->authenticate( $username, $password ); - - if( $result === true ) { - - $this->generate_session( $username ); - } - } - } return $result; } + static function check_session() {} + static function check_token() { - $_ = self::get_instance(); - $url = Common::get_current_url(); - $type = AUTH_TYPE; - $path = "types/$type"; - if( isset( $_SESSION["username"] ) && isset( $_SESSION["token"] ) ) { - - if( is_file( $path ) ) { - - require_once( $path ); - - $t_class = ucfirst( $type ); - - if( class_exists( $type ) && method_exists( $type, "get_instance" ) ) { - - $t_i = $type::get_instance(); - $result = $t_i->check_token(); - - if( $result === true ) { - - $this->refresh_session(); - } - } - } - } else { - - header( "Location: " . Common::get_current_url() . "login.php?redirect=" . urlencode( base64_encode( $url ) ) ); - exit(); - } } function generate_session( $username ) { diff --git a/index.php b/index.php index 404ce16..4494e8d 100644 --- a/index.php +++ b/index.php @@ -1,16 +1,16 @@