Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function add($service_id = null)
- {
- if($service_id == null || $service_id==0) {
- throw new \Cake\Network\Exception\NotFoundException(__('Not Found'));
- }
- $serviceUser = $this->ServiceUsers->newEntity();
- if ($this->request->is('post')) {
- $hasher = new DefaultPasswordHasher;
- if (trim($this->request->data['password']) == null) {
- $this->Flash->error(__('Blank space is not allowed.'));
- return $this->redirect(['action' => 'add', $service_id]);
- } else {
- $this->request->data['password'] = $hasher->hash($this->request->data['password']);
- $serviceUser = $this->ServiceUsers->patchEntity($serviceUser, $this->request->data);
- }
- $serviceUser->service_id = $service_id;
- $serviceUser->tenant_id = $this->Auth->user('tenant_id');
- if ($this->ServiceUsers->save($serviceUser)) {
- $this->Flash->success(__('The service user has been saved.'));
- return $this->redirect(['action' => 'users', $service_id]);
- } else {
- $this->Flash->error(__('The service user could not be saved. Please, try again.'));
- }
- }
- $service = $this->ServiceUsers->Services->get($service_id);
- // $serviceUser['username'] = ' A';
- // $serviceUser->password = 'whatever name';
- $this->set(compact('service', 'serviceUser'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement