Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. //MembersController
  2.  
  3. class MembersController extends AppController{
  4.  
  5. var $name = 'Members';
  6. var $components = array('Auth');
  7.  
  8. function beforeFilter(){
  9.  
  10. $this->Auth->loginRedirect = array('controller' => 'members', 'action' => 'index');
  11. $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'index');
  12. $this->Auth->loginAction = array('controller' => 'members', 'action' => 'login');
  13.  
  14. $this->Auth->allow('signup');
  15. $this->Auth->authorize = 'controller';
  16.  
  17. //change the username to the email field
  18. //cakephp looks for the username as the default login
  19. $this->Auth->fields = array('username' => 'email', 'password' => 'password');
  20. $this->Auth->autoRedirect = false;
  21.  
  22. $this->set('user', $this->Auth->user());
  23.  
  24. }
  25.  
  26. //we need this for Auth to work properly
  27. function isAuthorized(){
  28. return true;
  29. }
  30.  
  31. //show the members section
  32. function index(){
  33.  
  34. }
  35.  
  36. //We need to signup new users
  37. function signup() {
  38.  
  39. if (!empty($this->data)) {
  40.  
  41. //lets check to see if the password & confirm password are empty
  42. if(isset($this->data['Member']['password']) && isset($this->data['Member']['password2'])){
  43.  
  44. $this->data['Member']['passwordhashed'] = $this->Auth->password($this->data['Member']['password']);
  45. $this->data['Member']['password2hashed'] = $this->Auth->password($this->data['Member']['password2']);
  46.  
  47. $this->data['Member']['password'] = $this->data['Member']['passwordhashed'];
  48.  
  49. }
  50.  
  51. $this->Member->create();
  52. $this->data['Member']['joined'] = date('Y-m-d');
  53.  
  54. if ($this->Member->save($this->data)) {
  55.  
  56. $this->Session->setFlash('Your account has been created!');
  57. $this->redirect(array('action'=>'index'), null, true);
  58.  
  59. } else {
  60.  
  61. $this->Session->setFlash('You account could not be created. Try again!');
  62.  
  63. }
  64.  
  65. }
  66.  
  67. }
  68.  
  69. //Let the user login
  70. function login(){
  71.  
  72. }
  73.  
  74. //Logout the user
  75. function logout(){
  76. $this->redirect($this->Auth->redirect());
  77. }
  78.  
  79. }
Add Comment
Please, Sign In to add comment