From d5f2b825ee60d97132017d483118aaf1f80806cb Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 15 Dec 2017 16:46:54 +0100 Subject: [PATCH 1/6] ucase --- application/controllers/main.php | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100755 application/controllers/main.php diff --git a/application/controllers/main.php b/application/controllers/main.php deleted file mode 100755 index 10d5336..0000000 --- a/application/controllers/main.php +++ /dev/null @@ -1,22 +0,0 @@ -authenticated == FALSE ) return $this->showLoginPage(); - - $this->load->view('main_view'); - } - - private function showLoginPage() - { - $this->load->view('pages/login/login_view'); - } -} From ab143a51b97f4642c0f272b9459226264fae6221 Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 15 Dec 2017 16:47:19 +0100 Subject: [PATCH 2/6] Ucase 2 --- application/controllers/Main.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 application/controllers/Main.php diff --git a/application/controllers/Main.php b/application/controllers/Main.php new file mode 100755 index 0000000..10d5336 --- /dev/null +++ b/application/controllers/Main.php @@ -0,0 +1,22 @@ +authenticated == FALSE ) return $this->showLoginPage(); + + $this->load->view('main_view'); + } + + private function showLoginPage() + { + $this->load->view('pages/login/login_view'); + } +} From 7f2314c00b20ad4e43c88a694fc472e2d27cf0c7 Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 15 Dec 2017 19:17:56 +0100 Subject: [PATCH 3/6] inrichten base applicatie --- .gitignore | 1 + application/config/autoload.php | 2 +- application/core/MY_Controller.php | 10 ++++-- application/views/pages/login/login_view.php | 21 ++++++++---- application/views/specials/notifyme_modal.php | 27 +++++++++++++++ composer.json | 3 +- public/index.php | 14 ++++++++ public/js/lib/modules/login/loginModule.js | 33 +++++++++---------- .../js/lib/modules/specials/notifyModule.js | 21 ++++++------ 9 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 application/views/specials/notifyme_modal.php diff --git a/.gitignore b/.gitignore index 93c4797..518f969 100755 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ user_guide_src/cilexer/pycilexer.egg-info/* /tests/tests/ /tests/results/ /resources +/.env diff --git a/application/config/autoload.php b/application/config/autoload.php index 7cdc901..d20f488 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -58,7 +58,7 @@ $autoload['packages'] = array(); | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database', 'session'); /* | ------------------------------------------------------------------- diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 4af4152..2016b03 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -19,12 +19,18 @@ class MY_Controller extends CI_Controller { private function handle() { - + $this->environment(); } function clean_input( $post ) { - return str_replace( 'null', '', $this->db->escape_str( $this->input->post( $post ), TRUE ) ); + $value = $this->input->post( $post ); + +// $escapedValue = $this->db->escape_string( $value, TRUE ); + + $denulledValue = str_replace( 'null', '', $value); + + return $denulledValue; } public function json($data) diff --git a/application/views/pages/login/login_view.php b/application/views/pages/login/login_view.php index 354d951..da009b3 100644 --- a/application/views/pages/login/login_view.php +++ b/application/views/pages/login/login_view.php @@ -34,25 +34,28 @@ -
> +load->view('specials/notifyme_modal'); ?> +
-
+
...

projectbeheer

-
+
- +
- +
- - + +
@@ -102,5 +105,9 @@ + + + + diff --git a/application/views/specials/notifyme_modal.php b/application/views/specials/notifyme_modal.php new file mode 100644 index 0000000..33c8c35 --- /dev/null +++ b/application/views/specials/notifyme_modal.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/composer.json b/composer.json index 30630e2..ac9671c 100755 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "source": "https://github.com/bcit-ci/CodeIgniter" }, "require": { - "php": ">=5.3.7" + "php": ">=5.3.7", + "vlucas/phpdotenv": "^2.4" }, "suggest": { "paragonie/random_compat": "Provides better randomness in PHP 5.x" diff --git a/public/index.php b/public/index.php index 82920d1..dcb94ad 100755 --- a/public/index.php +++ b/public/index.php @@ -1,4 +1,18 @@ load(); + + + /** * CodeIgniter * diff --git a/public/js/lib/modules/login/loginModule.js b/public/js/lib/modules/login/loginModule.js index 2fa702b..4086741 100644 --- a/public/js/lib/modules/login/loginModule.js +++ b/public/js/lib/modules/login/loginModule.js @@ -4,42 +4,42 @@ * Date: 05/12/2017 * Time: 11:17 */ -var pp = {}; +var dbo = {}; + $( function () { - pp.loginModel = { + dbo.loginModel = { username: ko.observable( '' ), password: ko.observable( '' ), login: function () { - pp.loginService.login(); + dbo.loginService.login(); } } - - ko.applyBindings( pp.loginModel, document.getElementById( "login-user" ) ); - +console.log( 'text' ); + ko.applyBindings( dbo.loginModel, document.getElementById( "login-form" ) ); } ); -pp.loginService = { +dbo.loginService = { login: function () { - var ds = pp.loginDataservice; - var self = pp.loginService; - var vm = pp.loginModel; + var ds = dbo.loginDataservice; + var self = dbo.loginService; + var vm = dbo.loginModel; - self.validateInput( function ( data ) { - if ( !data ) return self.notifyWrongPassword(); + self.validateInput( function ( submitDATA ) { + if ( ! submitDATA ) return self.notifyWrongPassword(); ds.login( submitDATA, function ( data ) { - if ( data ) return location.reload(); +// if ( data ) return location.reload(); } ); } ); }, validateInput: function ( callback ) { - var vm = pp.loginModel; + var vm = dbo.loginModel; if ( vm.username().length < 2 ) return callback( false ); if ( vm.password().length < 6 ) return callback( false ); @@ -55,14 +55,13 @@ pp.loginService = { notifyWrongPassword: function () { notifyMe( { title : 'Login fout', - message: 'Gebruikersnaam / wachtwoord komen niet overeen', - alert : true + message: 'Gebruikersnaam / wachtwoord komen niet overeen' } ); } }; -pp.loginDataservice = { +dbo.loginDataservice = { login: function ( submitDATA, callback ) { $.post( 'index.php/login/', submitDATA, function ( data ) { diff --git a/public/js/lib/modules/specials/notifyModule.js b/public/js/lib/modules/specials/notifyModule.js index 8ef53f0..7708a47 100644 --- a/public/js/lib/modules/specials/notifyModule.js +++ b/public/js/lib/modules/specials/notifyModule.js @@ -6,10 +6,10 @@ */ var notifyMe = function ( options, callback ) { - pp.notifyModel.init( options, callback ); + dbo.notifyModel.init( options, callback ); } -pp.notifyModel = { +dbo.notifyModel = { title : ko.observable( null ), message : ko.observable( null ), @@ -21,7 +21,7 @@ pp.notifyModel = { callback : null, init: function ( options, callback ) { - var vm = pp.notifyModel; + var vm = dbo.notifyModel; vm.callback = callback; @@ -31,36 +31,35 @@ pp.notifyModel = { }, setOptions: function ( options ) { - var vm = pp.notifyModel; + var vm = dbo.notifyModel; vm.title( options.title || '' ); vm.message( options.message || '' ); - vm.notify( options.notify || false ); - vm.alert( options.alert || false ); + vm.notify( options.notify || true ); vm.noText( options.noText || 'Nee' ); vm.yesText( options.yesText || 'Ja' ); vm.closeText( options.closeText || 'ok' ); }, closeNo: function () { - if ( typeof( pp.notifyModel.callback ) == 'function' ) callback( false ); + if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback( false ); }, closeYes: function () { - if ( typeof( pp.notifyModel.callback ) == 'function' ) callback( true ); + if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback( true ); }, closeOk: function () { - if ( typeof( pp.notifyModel.callback ) == 'function' ) callback(); + if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback(); }, close: function () { - if ( typeof( pp.notifyModel.callback ) == 'function' ) callback(); + if ( typeof( dbo.notifyModel.callback ) == 'function' ) callback(); } } -ko.applyBindings( pp.notifyModel, document.getElementById( "notify-me" ) ); +ko.applyBindings( dbo.notifyModel, document.getElementById( "notify-me" ) ); From a7de7ed80a9db5ecb74e0f4a3836032d9561ee8f Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 15 Dec 2017 19:44:52 +0100 Subject: [PATCH 4/6] Login --- application/config/autoload.php | 4 ++-- application/config/database.php | 8 ++++---- application/core/MY_Controller.php | 6 ++---- application/models/beheer/User.php | 26 ++++++++++++++++++++++++++ public/index.php | 3 ++- 5 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 application/models/beheer/User.php diff --git a/application/config/autoload.php b/application/config/autoload.php index d20f488..34afbb7 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -1,5 +1,5 @@ 'first'); */ -$autoload['model'] = array(); +$autoload['model'] = ['beheer/User']; diff --git a/application/config/database.php b/application/config/database.php index bf9857f..1b40188 100755 --- a/application/config/database.php +++ b/application/config/database.php @@ -75,10 +75,10 @@ $query_builder = TRUE; $db['default'] = array( 'dsn' => '', - 'hostname' => 'localhost', - 'username' => '', - 'password' => '', - 'database' => '', + 'hostname' => getenv('DB_HOST'), + 'username' => getenv('DB_USER'), + 'password' => getenv('DB_PASS'), + 'database' => getenv('DB_NAME'), 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 2016b03..ee5427f 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -19,14 +19,12 @@ class MY_Controller extends CI_Controller { private function handle() { - $this->environment(); + } function clean_input( $post ) { - $value = $this->input->post( $post ); - -// $escapedValue = $this->db->escape_string( $value, TRUE ); + $value = $this->input->input_stream( $post, TRUE ); $denulledValue = str_replace( 'null', '', $value); diff --git a/application/models/beheer/User.php b/application/models/beheer/User.php new file mode 100644 index 0000000..bf38e31 --- /dev/null +++ b/application/models/beheer/User.php @@ -0,0 +1,26 @@ +get( [ + 'UCASE(username)' => strtoupper( $username )], FALSE, TRUE); + + return $user; + } + +} \ No newline at end of file diff --git a/public/index.php b/public/index.php index dcb94ad..6c67e0f 100755 --- a/public/index.php +++ b/public/index.php @@ -11,6 +11,7 @@ include_once('../vendor/autoload.php'); $dotenv = new Dotenv\Dotenv('../'); $dotenv->load(); +$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'ENVIRONMENT']); /** @@ -67,7 +68,7 @@ $dotenv->load(); * * NOTE: If you change these, also change the error_reporting() code below */ - define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); + define('ENVIRONMENT', getenv('ENVIRONMENT')); /* *--------------------------------------------------------------- From 327dc4376cc7ed9fcdfff572e9f826b578a2f4a1 Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Tue, 19 Dec 2017 17:23:34 +0100 Subject: [PATCH 5/6] Login ready --- .gitignore | 1 + application/config/config.php | 4 +- application/controllers/Login.php | 10 +++- application/controllers/Main.php | 2 +- application/core/MY_Controller.php | 4 +- .../libraries/beheer/CreateUserSession.php | 47 +++++++++++++++++++ .../libraries/beheer/RetrieveUserSession.php | 41 ++++++++++++++++ application/views/main_view.php | 1 + application/views/specials/notifyme_modal.php | 4 +- public/js/lib/modules/login/loginModule.js | 4 +- .../js/lib/modules/specials/notifyModule.js | 20 ++++---- 11 files changed, 120 insertions(+), 18 deletions(-) create mode 100644 application/libraries/beheer/CreateUserSession.php create mode 100644 application/libraries/beheer/RetrieveUserSession.php create mode 100644 application/views/main_view.php diff --git a/.gitignore b/.gitignore index 518f969..023c02f 100755 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ user_guide_src/cilexer/pycilexer.egg-info/* /tests/results/ /resources /.env +/themeforest diff --git a/application/config/config.php b/application/config/config.php index 1031522..2cc405e 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -377,10 +377,10 @@ $config['encryption_key'] = ''; | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here. | */ -$config['sess_driver'] = 'files'; +$config['sess_driver'] = 'database'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; -$config['sess_save_path'] = NULL; +$config['sess_save_path'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE; diff --git a/application/controllers/Login.php b/application/controllers/Login.php index 145122f..d37b7ae 100644 --- a/application/controllers/Login.php +++ b/application/controllers/Login.php @@ -12,6 +12,8 @@ class Login extends MY_Controller { public function __construct() { parent::__construct(); + + $this->load->library( 'beheer/CreateUserSession' ); } public function index() @@ -23,7 +25,11 @@ class Login extends MY_Controller { if ( ! $user ) return $this->json( FALSE ); - $this->checkPassword( $user, $password ); + $passwordCheck = $this->checkPassword( $user, $password ); + + if ( $passwordCheck === TRUE ) $this->usersession->handle( $user ); + + $this->json( $passwordCheck ); } private function checkPassword( $user, $password ) @@ -32,7 +38,7 @@ class Login extends MY_Controller { $saltedPassword = $this->User->saltedPasswordRecipe( $password, $user->salt ); - if( $saltedPassword == $user->password ) return TRUE; + if ( $saltedPassword == $user->password ) return TRUE; return FALSE; } diff --git a/application/controllers/Main.php b/application/controllers/Main.php index 10d5336..8767f55 100755 --- a/application/controllers/Main.php +++ b/application/controllers/Main.php @@ -10,7 +10,7 @@ class Main extends MY_Controller { public function index() { - if( $this->authenticated == FALSE ) return $this->showLoginPage(); + if( AUTHENTICATED == FALSE ) return $this->showLoginPage(); $this->load->view('main_view'); } diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index ee5427f..31e6b32 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -14,12 +14,14 @@ class MY_Controller extends CI_Controller { { parent::__construct(); + $this->load->library( 'beheer/RetrieveUserSession' ); + $this->handle(); } private function handle() { - + $this->retrieveusersession->handle(); } function clean_input( $post ) diff --git a/application/libraries/beheer/CreateUserSession.php b/application/libraries/beheer/CreateUserSession.php new file mode 100644 index 0000000..9766b7f --- /dev/null +++ b/application/libraries/beheer/CreateUserSession.php @@ -0,0 +1,47 @@ +ci =& get_instance(); + } + + public function handle( $user ) + { + $this->setUser( $user ); + + $this->setSessionArray(); + + $this->createSession(); + } + + private function setUser( $user ) + { + $this->user = $user; + } + + private function setSessionArray() + { + $this->sessionArray = [ + 'userID' => $this->user->id, + 'role' => $this->user->role + ]; + } + + private function createSession() + { + $this->ci->session->set_userdata( $this->sessionArray ); + } + +} \ No newline at end of file diff --git a/application/libraries/beheer/RetrieveUserSession.php b/application/libraries/beheer/RetrieveUserSession.php new file mode 100644 index 0000000..3750d01 --- /dev/null +++ b/application/libraries/beheer/RetrieveUserSession.php @@ -0,0 +1,41 @@ +ci =& get_instance(); + } + + public function handle() + { + $this->setUserID(); + + $this->setRole(); + + $this->setAuthenticated(); + } + + private function setUserID() + { + define( 'USERID', $this->ci->session->userID ); + } + + private function setRole() + { + define( 'ROLE', $this->ci->session->role ); + } + + private function setAuthenticated() + { + define( 'AUTHENTICATED', USERID ? TRUE : FALSE ); + } +} \ No newline at end of file diff --git a/application/views/main_view.php b/application/views/main_view.php new file mode 100644 index 0000000..bc7daf7 --- /dev/null +++ b/application/views/main_view.php @@ -0,0 +1 @@ +

loggedin

\ No newline at end of file diff --git a/application/views/specials/notifyme_modal.php b/application/views/specials/notifyme_modal.php index 33c8c35..bf642dc 100644 --- a/application/views/specials/notifyme_modal.php +++ b/application/views/specials/notifyme_modal.php @@ -1,4 +1,4 @@ -