Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public function add($service_id = null)
  2. {
  3.  
  4. if($service_id == null || $service_id==0) {
  5.  
  6. throw new \Cake\Network\Exception\NotFoundException(__('Not Found'));
  7.  
  8. }
  9.  
  10. $serviceUser = $this->ServiceUsers->newEntity();
  11.  
  12. if ($this->request->is('post')) {
  13.  
  14. $hasher = new DefaultPasswordHasher;
  15.  
  16. if (trim($this->request->data['password']) == null) {
  17. $this->Flash->error(__('Blank space is not allowed.'));
  18. return $this->redirect(['action' => 'add', $service_id]);
  19. } else {
  20. $this->request->data['password'] = $hasher->hash($this->request->data['password']);
  21. $serviceUser = $this->ServiceUsers->patchEntity($serviceUser, $this->request->data);
  22. }
  23.  
  24. $serviceUser->service_id = $service_id;
  25. $serviceUser->tenant_id = $this->Auth->user('tenant_id');
  26.  
  27. if ($this->ServiceUsers->save($serviceUser)) {
  28.  
  29. $this->Flash->success(__('The service user has been saved.'));
  30. return $this->redirect(['action' => 'users', $service_id]);
  31.  
  32. } else {
  33.  
  34. $this->Flash->error(__('The service user could not be saved. Please, try again.'));
  35.  
  36. }
  37. }
  38.  
  39. $service = $this->ServiceUsers->Services->get($service_id);
  40.  
  41. // $serviceUser['username'] = ' A';
  42. // $serviceUser->password = 'whatever name';
  43.  
  44. $this->set(compact('service', 'serviceUser'));
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement