diff --git a/.gitignore b/.gitignore index 93c4797..023c02f 100755 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ user_guide_src/cilexer/pycilexer.egg-info/* /tests/tests/ /tests/results/ /resources +/.env +/themeforest diff --git a/application/config/autoload.php b/application/config/autoload.php index 7cdc901..34afbb7 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -1,5 +1,5 @@ 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database', 'session'); /* | ------------------------------------------------------------------- @@ -132,4 +132,4 @@ $autoload['language'] = array(); | | $autoload['model'] = array('first_model' => 'first'); */ -$autoload['model'] = array(); +$autoload['model'] = ['beheer/User']; 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/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/controllers/Login.php b/application/controllers/Login.php index 145122f..f282263 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->createusersession->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 similarity index 83% rename from application/controllers/main.php rename to 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 4af4152..31e6b32 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -14,17 +14,23 @@ 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 ) { - return str_replace( 'null', '', $this->db->escape_str( $this->input->post( $post ), TRUE ) ); + $value = $this->input->input_stream( $post, TRUE ); + + $denulledValue = str_replace( 'null', '', $value); + + return $denulledValue; } public function json($data) 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/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/application/views/main_view.php b/application/views/main_view.php new file mode 100644 index 0000000..4963fc7 --- /dev/null +++ b/application/views/main_view.php @@ -0,0 +1,52 @@ + + +
+ + + + + + + + +