Guest User

Untitled

a guest
Apr 17th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. public function user_create()
  2. {
  3. $user = ORM::factory('user');
  4. $user->username = "user";
  5.  
  6. $this->auth = Auth::instance();
  7.  
  8. $user->email = "info@test.com";
  9. $user->password = $this->auth->hash_password('admin');
  10. $user->add(ORM::factory('role', 'login'));
  11. $user->add(ORM::factory('role', 'admin'));
  12.  
  13. if ($user->save())
  14. {
  15. $this->template->title = "user saved";
  16. $this->template->content = "user saved";
  17. }
  18. }
  19.  
  20. $user = $this->input->post('username');
  21. $password = $this->input->post('password');
  22.  
  23. if(!empty($user))
  24. {
  25. $find_user = ORM::factory('user')->where('username', $user)->find();
  26. $username = $find_user->username;
  27.  
  28. $this->auth = Auth::instance();
  29.  
  30. if($this->auth->login($username, $password))
  31. {
  32. $error = "logged in";
  33. }
  34. else
  35. {
  36. $error = "not logged in at all";
  37. }
  38. }
  39.  
  40. $this->template->content = new View('admin/login_view');
  41. $this->template->content->user_info = $username . " " . $password;
  42. $this->template->title = "Login Admin";
  43. $this->template->content->bind('error', $error);
  44.  
  45. public function user_create()
  46. {
  47. $user = ORM::factory('user');
  48. $user->username = "user";
  49.  
  50. $this->auth = Auth::instance();
  51.  
  52. $user->email = "info@test.com";
  53. $user->password = 'admin';
  54. ...
  55.  
  56. public function __set($key, $value)
  57. {
  58. if ($key === 'password')
  59. {
  60. // Use Auth to hash the password
  61. $value = Auth::instance()->hash_password($value);
  62. }
  63.  
  64. parent::__set($key, $value);
  65. }
Add Comment
Please, Sign In to add comment