Advertisement
Guest User

Untitled

a guest
Aug 26th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. if($this->session->userdata('log')!=''){
  2. redirect('home');
  3. }
  4. else{
  5. redirect('login');
  6. }
  7.  
  8. <?php
  9. defined('BASEPATH') OR exit('No direct script access allowed');
  10.  
  11. class Login extends MY_Controller {
  12. public function __construct(){
  13. parent::__construct();
  14. }
  15.  
  16. public function index(){
  17. $data['module'] = 'Login';
  18. $this->load->view('header',$data);
  19. $this->load->view('login');
  20. if($this->session->userdata('log')!=''){
  21. redirect('home');
  22. }
  23. else{
  24. redirect('login');
  25. }
  26. }
  27.  
  28. public function getAccess(){
  29. $username = $this->input->post('username', TRUE);
  30. $password = $this->input->post('password', TRUE);
  31. $result = $this->user->login($username,$password);
  32. if (!empty($this->input->post('username')) && !empty($this->input->post('password'))) {
  33. if (!$result) {
  34. $this->json(array('error' => 'invalid username or password'));
  35. }else{
  36. $data_session = array(
  37. 'id' => $result['id'],
  38. 'first_name' => $result['first_name'],
  39. 'last_name' => $result['last_name'],
  40. 'type' => $result['profile_id'],
  41. 'logged_in' => TRUE
  42. );
  43. $this->session->set_userdata('log',$data_session);
  44. }
  45. } else {
  46. $this->json(array('empty' => 'You did not fill out the required fields.'));
  47. }
  48. }
  49.  
  50. public function logout(){
  51. $this->session->sess_destroy();
  52. redirect('login','refresh');
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement