-
Notifications
You must be signed in to change notification settings - Fork 0
/
Start.php
executable file
·81 lines (70 loc) · 2 KB
/
Start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Start.
*
* This is the default controller of this application. It serves the landing page and logout operation.
*/
class Start extends CI_Controller
{
/**
* Start constructor.
*
* Initialize the database, loads the myredis library and audit model.
*/
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('myredis');
$this->load->model('audit_model');
}
/**
* Default function.
*
* Renders the landing page view.
*/
public function index()
{
$this->load->view('start');
}
/**
* Logout function.
*
* Destroys the user session and redirects the control over to logoutflash function to setup the logout
* flash message for the user.
* Records the logout user's ID in the Redis storage.
*/
public function logout()
{
$userId = $this->session->userdata('id_user');
if (!$userId) {
redirect('/');
}
$auditData = [
'type' => AUDIT_LOGOUT,
'id_user' => $userId,
'ip_address' => $this->input->ip_address()
];
$this->audit_model->save_audit($auditData);
/*
* Record all logout user's ID in Redis
*/
$redis = $this->myredis->get_instance();
$redis->rpush('LOGOUT_USERS', $userId);
$data = array('id_user' => '', 'name' => '', 'user_email' => '');
$this->session->unset_userdata($data);
$this->session->sess_destroy();
redirect('/start/logoutflash');
}
/**
* Logoutflash function.
*
* Setup the logout flash message for the user and redirects the user to landing page.
*/
public function logoutflash()
{
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">You have been logged out!</div>');
redirect('/');
}
}