Login ready
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 19/12/2017
|
||||
* Time: 16:52
|
||||
*/
|
||||
|
||||
class CreateUserSession {
|
||||
|
||||
private $ci;
|
||||
private $user;
|
||||
private $sessionArray;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 19/12/2017
|
||||
* Time: 17:13
|
||||
*/
|
||||
|
||||
class RetrieveUserSession {
|
||||
|
||||
private $ci;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<h1>loggedin</h1>
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="modal" tabindex="-1" role="dialog" id="notify-me">
|
||||
<div class="modal modal-3d-flip-vertical" tabindex="-1" role="dialog" id="notify-me" data-bind="css:modalClass">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@@ -18,7 +18,7 @@
|
||||
data-bind="text:noText; click:closeNo"></button>
|
||||
<!-- /ko -->
|
||||
<!-- ko if : ! notify() -->
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal"
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal"
|
||||
data-bind="click:closeOk">OK</button>
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user