/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/application/controllers/start.php

  • Committer: a11emmjo
  • Date: 2013-05-27 13:44:24 UTC
  • mfrom: (107 lenasys_b)
  • mto: This revision was merged to the branch mainline in revision 109.
  • Revision ID: a11emmjo@student.his.se-20130527134424-27818lm7fmk5x3wx
Updated branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
                        $this->load->view('bannermenu', $data);
78
78
                        $this->load->view('startview', $data);
79
79
                }
 
80
 
 
81
                /* Login and logout functionality */
 
82
                public function login() {
 
83
                        $this->load->library('user_agent');
 
84
                        $this->load->library('form_validation');
 
85
 
 
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');
 
89
                        
 
90
                        //Run validation
 
91
                        if($this->form_validation->run() == FALSE) {
 
92
                                //Field validation failed. Display login form (with error message).
 
93
                                echo validation_errors();
 
94
                        } else {
 
95
                                $username = $this->input->post('username');
 
96
                                $password = $this->input->post('password');
 
97
 
 
98
                                $this->load->model('user');
 
99
                                
 
100
                                //Try to login
 
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']);
 
104
                                } else {
 
105
                                        echo "Wrong username or password";
 
106
                                }
 
107
                        }
 
108
                }
 
109
 
 
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']);
 
115
                        } else {
 
116
                                echo "You're not logged in!";
 
117
                        }
 
118
                }
80
119
        }
81
120
?>