Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if($this->session->userdata('log')!=''){
- redirect('home');
- }
- else{
- redirect('login');
- }
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Login extends MY_Controller {
- public function __construct(){
- parent::__construct();
- }
- public function index(){
- $data['module'] = 'Login';
- $this->load->view('header',$data);
- $this->load->view('login');
- if($this->session->userdata('log')!=''){
- redirect('home');
- }
- else{
- redirect('login');
- }
- }
- public function getAccess(){
- $username = $this->input->post('username', TRUE);
- $password = $this->input->post('password', TRUE);
- $result = $this->user->login($username,$password);
- if (!empty($this->input->post('username')) && !empty($this->input->post('password'))) {
- if (!$result) {
- $this->json(array('error' => 'invalid username or password'));
- }else{
- $data_session = array(
- 'id' => $result['id'],
- 'first_name' => $result['first_name'],
- 'last_name' => $result['last_name'],
- 'type' => $result['profile_id'],
- 'logged_in' => TRUE
- );
- $this->session->set_userdata('log',$data_session);
- }
- } else {
- $this->json(array('empty' => 'You did not fill out the required fields.'));
- }
- }
- public function logout(){
- $this->session->sess_destroy();
- redirect('login','refresh');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement