/** * * @return boolean * @throws Exception */ private function makeRegister() { $cpf = $this->request->getPost('cpf', 'alphanum'); $dataAdmissao = $this->request->getPost('dataAdmissao'); $empresa = $this->request->getPost('empresa', 'int'); $colaboradores = new Colaboradores(); $funcionarioProtheus = $colaboradores->validaDadosFuncionario($cpf, $empresa, $dataAdmissao); if (empty($funcionarioProtheus)) { throw new Exception('Não foi encontrado esse CPF na base de dados.'); } $user = new Users(); $user->setId($user->autoincrement()); $user->setName($this->request->getPost('name', 'string')); $user->setCpf($cpf); $email = $this->request->getPost('email', 'email'); $user->setEmail($email); $user->setUserName(explode('@', $email)[0]); $user->setPassword($this->security->hash($this->request->getPost('password'))); $user->setMustChangePassword('S'); $user->setStatus('A'); if (!$user->create()) { $msg = ''; foreach ($user->getMessages() as $message) { $msg .= $message . '<br>'; } throw new Exception($msg); } $userGroup = new UsersGroups(); $userGroup->setId($userGroup->autoincrement()); $userGroup->setUserId($user->getId()); $userGroup->setGroupId(3); if (!$userGroup->save()) { $msg = ''; foreach ($userGroup->getMessages() as $message) { $msg .= $message . '<br>'; } throw new Exception($msg); } return true; }
/** * Creates a new users_group */ public function createAction() { try { if (!$this->request->isPost()) { throw new Exception('Acesso não permitido a essa action.'); } $users_group = new UsersGroups(); $users_group->setId($users_group->autoincrement()); $users_group->setUserId($this->request->getPost('userId')); $users_group->setGroupId($this->request->getPost('groupId')); if (!$users_group->create()) { $msg = ''; foreach ($users_group->getMessages() as $message) { $msg .= $message . '<br />'; } throw new Exception($msg); } $this->flash->success('Grupo x Usuário gravado com sucesso!!!'); } catch (Exception $exc) { $this->flash->error($exc->getMessage()); } return $this->response->redirect('nucleo/users_groups'); }