16
*Temporary function to be able to be logged in to reach the page
18
public function tempLogin() {
19
$this->load->model('user');
20
$loginDetails = array(
21
'username' => 'tempTeacher',
23
'usertype' => 'Teacher',
25
'activeCourse' => 'DA525G');
26
$this->session->set_userdata('authenticated', $loginDetails);
27
redirect(base_url().'start', 'refresh');
29
public function tempLogout() {
30
$this->load->model('user');
31
$this->session->unset_userdata('authenticated');
32
redirect(base_url().'home', 'refresh');
36
16
* This function runs when the user navigates directly to the start controller
38
18
public function index() {
39
19
if($this->user->isLoggedIn()) {
40
20
//User already logged in
41
redirect(base_url().'cms', 'refresh');
21
redirect(base_url().'home', 'refresh');
43
23
//Display the start page
44
24
$this->drawStartPage('');
51
31
private function drawStartPage() {
52
32
$userName = $this->user->getUserName();
53
33
$userType = $this->user->getUserType();
54
//Creates an array with active course info.
55
$activeCourse = $this->user->getActiveCourse();
56
34
//Creates an array with all courses.
57
35
$courses = $this->admin_model->getCourses();
60
37
//Creates an array with the variables that the bannermenu-view is expecting.
62
39
'userType' => $userType,
63
40
'userName' => $userName,
64
'activeCourse' => $activeCourse,
65
41
'courses' => $courses
68
44
//Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
69
45
$headTagData = array(
70
46
'cssFiles' => array('bannermenu', 'startview'),
71
'jsFiles' => array('bannermenu', 'login')
47
'jsFiles' => array('bannermenu')
74
50
//Puts the array above in <head></head>
77
53
$this->load->view('bannermenu', $data);
78
54
$this->load->view('startview', $data);
81
/* Login and logout functionality */
82
public function login() {
83
$this->load->library('user_agent');
84
$this->load->library('form_validation');
86
//Sets validation rules
87
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
88
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
91
if($this->form_validation->run() == FALSE) {
92
//Field validation failed. Display login form (with error message).
93
echo validation_errors();
95
$username = $this->input->post('username');
96
$password = $this->input->post('password');
98
$this->load->model('user');
101
if ($this->user->login($username, $password)) {
102
// If the login is successful, Redirects user to the page it came from
103
redirect($_SERVER['HTTP_REFERER']);
105
echo "Wrong username or password";
110
public function logout() {
111
$this->load->model('user');
112
if($this->user->isLoggedIn()) {
113
$this->session->unset_userdata('authenticated');
114
redirect($_SERVER['HTTP_REFERER']);
116
echo "You're not logged in!";