Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. Anyway, here's some code -
  2.  
  3. IF ($this->form_validation->run()){ //<---Form validation.
  4. IF (!$this->User->login( //<---Attempt to log in the user with POST data
  5. addslashes(strtolower($this->input->post('username', TRUE))), //<-Username
  6. addslashes($this->input->post('password', TRUE)), //<- Password
  7. $this->getIP())){ //<-IP
  8. /*If the login failed stuff goes here bla bla not relevant.*/
  9. } ELSE {
  10. SWITCH($this->User->stale('Permissions')){ //<- This works
  11. CASE 'ADMIN':
  12. redirect('Admin');
  13. BREAK;
  14. /*Some other stuff but not relevant*/
  15. }
  16. }
  17.  
  18. I've set a breakpoint in the Admin controller class constructor :
  19.  
  20. CLASS Admin EXTENDS CI_Controller{
  21. public FUNCTION __construct(){
  22. PARENT::__construct(); //<-This gets hit.
  23. $this->load->model('User_Model', 'User'); //<- So does this, but when the $_SESSION value appears in the Variables view, it only has a single value in it.
  24. $this->User->ID = $this->session->UserID;
  25. /*Some other stuff that goes here; again, not relevant.*/
  26. }
  27. }
  28.  
  29. Then there's also where the session data is being set; within the `User_Model` `Login( ... )` method -
  30.  
  31. CLASS User_Model EXTENDS MY_Model{ //<----- MY_Model is just an extension of the CI_Model class that lets me use some of our Database stuff. Testing shows that it all checks out.
  32. public FUNCTION login($userName, $password, $IP){
  33. $row = $this->database->get_where('users', ARRAY('UserName' => $userName))->row_array()['UserName'];
  34. IF (!ISSET($row)){
  35. /*bla bla bad username handle it.*/
  36. } ELSE {
  37. /*Check password against username*/
  38. IF (/*Stuff*/) {
  39. /*Bla bla bad password handle it.*/
  40. } ELSEIF(/*check for already logged in*/){
  41. /*Bla bla logged in already handle it.*/
  42. } ELSE {
  43. /*Login was successful and there was much rejoicing (yaaay) handle it...*/
  44. /*Then I try and set the session values so that they are accessible after the redirect to the Admin controller:*/
  45. $this->session->UserID = $row['UserID'];
  46. /*and many others which aren't persisting*/
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement