public function itemFormSubmitted(MyAppForm $form) { try { if ($form['save']->isSubmittedBy()) { $id = (int) $this->getParam('id'); $values = $form->getValues(); unset($values['password2']); $sendNotifyingEmail = $values['send_email']; unset($values['send_email']); // if not client-like user, unset supervisor if (!is_array($values['roles'])) { // depends on client view is ON/OFF $values['roles'] = array($values['roles']); } if (count(array_intersect(UsersModel::$clientRolesId, $values['roles'])) === 0) { $values['supervisor_id'] = null; } if ($id > 0) { $this->model->update($id, $values); $this->flashMessage('User updated.', self::FLASH_MESSAGE_SUCCESS); } else { if ($this->isClientMode) { $values['supervisor_id'] = $this->userId; } $values['approved'] = true; $id = $this->model->insert($values); $this->flashMessage('User created.', self::FLASH_MESSAGE_SUCCESS); if ($sendNotifyingEmail) { $this->sendRegBasicEmail($values); } } } } catch (InvalidStateException $e) { $form->addError($this->translate('Mail could not be sent. Try again later, please')); } catch (DibiDriverException $e) { // duplicate entry if ($e->getCode() === BaseModel::DUPLICATE_ENTRY_CODE) { $this->flashMessage("ERROR: " . $e->getMessage(), self::FLASH_MESSAGE_ERROR); } else { Debug::log($e); $this->flashMessage("ERROR: cannot save data!", self::FLASH_MESSAGE_ERROR); } } catch (OperationNotAllowedException $e) { $this->flashMessage(NOT_ALLOWED, self::FLASH_MESSAGE_ERROR); $this->redirect('this'); } $form->resetValues(); $this->refresh(null, 'add'); }
/** * save user info * * @param MyAppForm */ public function save(MyAppForm $form) { try { if ($form['save']->isSubmittedBy()) { $values = $form->getValues(); $loginOnSuccess = !empty($values['loginOnSuccess']); if ($loginOnSuccess) { unset($values['loginOnSuccess']); } $this->model->updateLoggedUser($values, true); // to allow relogin after change of credentials - used when user forgot password and was redirected from ForgottenPass::tempLogin() if ($loginOnSuccess) { $this->user->logout(TRUE); $this->flashMessage('Password has been successfully updated. Please log in using new password now.', $this::FLASH_MESSAGE_SUCCESS); $this->redirect(':Front:Login:login'); } else { $this->flashMessage('Data updated.', $this::FLASH_MESSAGE_SUCCESS); } } } catch (DibiDriverException $e) { $this->flashMessage("ERROR: cannot save data!", $this::FLASH_MESSAGE_ERROR); } catch (InvalidPasswordException $e) { $this->flashMessage($e->getMessage(), $this::FLASH_MESSAGE_ERROR); } $this->refresh(null, 'this'); }