Guest User

Untitled

a guest
Oct 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. function admin_index() {
  2. $this->layout = 'admin';
  3. $this->User->recursive = 0;
  4. $this->set('users', $this->paginate());
  5. }
  6.  
  7. function admin_edit($id = null) {
  8. $this->layout = 'admin';
  9. if (!$id && empty($this->data)) {
  10. $this->Session->setFlash(__('Invalid user', true));
  11. $this->redirect(array('action' => 'index'));
  12. }
  13. if (!empty($this->data)) {
  14. if ($this->User->save($this->data)) {
  15. debug($this->data);exit();
  16. if($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])){
  17. $this->User->saveField('role', 'admin');
  18. $this->redirect(array('action' => 'index'));
  19. }
  20. } else {
  21. $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
  22. }
  23. }
  24. if (empty($this->data)) {
  25. $this->data = $this->User->read(null, $id);
  26. }
  27. }
  28.  
  29. function admin_add() {
  30. $this->layout = 'admin';
  31. if (!empty($this->data)){
  32. if ($this->User->save($this->data)) {
  33. if($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])){
  34. $this->User->saveField('role', 'admin');
  35. $this->redirect(array('action' => 'index'));
  36. }
  37. }
  38. }
  39. }
  40.  
  41. function admin_delete($id = null) {
  42. if (!$id) {
  43. $this->Session->setFlash(__('Invalid id for user', true));
  44. $this->redirect(array('action'=>'index'));
  45. }
  46. if ($this->User->delete($id)) {
  47. $this->Session->setFlash(__('User deleted', true));
  48. $this->redirect(array('action'=>'index'));
  49. }
  50. $this->Session->setFlash(__('User was not deleted', true));
  51. $this->redirect(array('action' => 'index'));
  52. }
Add Comment
Please, Sign In to add comment