/** * Register a new user this controller can save User, Contact and Company * Only if attributes are provided by the POST request shall the model be saved */ public function actionRegister() { \GO::config()->password_validate = false; $user = new \GO\Base\Model\User(); $contact = new \GO\Addressbook\Model\Contact(); // $user->setValidationRule('passwordConfirm', 'required', true); //$company = new \GO\Addressbook\Model\Company(); //set additional required fields // $company->setValidationRule('address', 'required', true); // $company->setValidationRule('zip', 'required', true); // $company->setValidationRule('city', 'required', true); // $company->setValidationRule('country', 'required', true); if (\GO\Base\Util\Http::isPostRequest()) { //if username is deleted from form then use the e-mail adres as username if (!isset($_POST['User']['username'])) { $_POST['User']['username'] = $_POST['User']['email']; } $user->setAttributes($_POST['User']); $contact->setAttributes($_POST['Contact']); //$company->setAttributes($_POST['Company']); // if(!empty($_POST['Company']['postAddressIsEqual'])) // $company->setPostAddressFromVisitAddress(); $contact->addressbook_id = 1; //just for validating if ($user->validate() && $contact->validate()) { \GO::setIgnoreAclPermissions(); //allow guest to create user if ($user->save()) { $contact = $user->createContact(); // $company->addressbook_id=$contact->addressbook_id; // $company->save(); //$contact->company_id=$company->id; $contact->setAttributes($_POST['Contact']); $contact->save(); // Automatically log the newly created user in. if (\GO::session()->login($user->username, $_POST['User']['password'])) { $this->redirect($this->getReturnUrl()); } else { throw new \Exception('Login after registreation failed.'); } } } else { // var_dump($user->getValidationErrors()); // var_dump($contact->getValidationErrors()); // var_dump($company->getValidationErrors()); } } else { $user->password = ""; $user->passwordConfirm = ""; } echo $this->render('register', array('user' => $user, 'contact' => $contact)); }
protected function actionContact() { //GOS::site()->config->contact_addressbook_id; if (\GO\Base\Util\Http::isPostRequest()) { if (isset($_POST['Addressbook']['name'])) { $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findSingleByAttribute('name', $_POST['Addressbook']['name']); } else { $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findByPk($_POST['Addressbook']['id']); } if (!$addressbookModel) { throw new \Exception(sprintf(\GO::t('addressbookNotFound', 'defaultsite'), $_POST['Addressbook']['name'])); } $contactModel = \GO\Addressbook\Model\Contact::model()->findSingleByAttributes(array('email' => $_POST['Contact']['email'], 'addressbook_id' => $addressbookModel->id)); if (!$contactModel) { $contactModel = new \GO\Addressbook\Model\Contact(); $contactModel->addressbook_id = $addressbookModel->id; } $contactModel->setValidationRule('first_name', 'required', true); $contactModel->setValidationRule('last_name', 'required', true); $contactModel->setValidationRule('email', 'required', true); $companyModel = \GO\Addressbook\Model\Company::model()->findSingleByAttributes(array('name' => $_POST['Company']['name'], 'addressbook_id' => $addressbookModel->id)); if (!$companyModel) { $companyModel = new \GO\Addressbook\Model\Company(); $companyModel->addressbook_id = $addressbookModel->id; } $companyModel->setValidationRule('name', 'required', true); $companyModel->setAttributes($_POST['Company']); if ($companyModel->validate()) { $companyModel->save(); $contactModel->company_id = $companyModel->id; } $contactModel->setAttributes($_POST['Contact']); if ($contactModel->validate()) { $saveSuccess = $contactModel->save(); if ($saveSuccess) { // Add to mailings. $addresslists = !empty($_POST['Addresslist']) ? $_POST['Addresslist'] : array(); foreach ($addresslists as $addresslistName => $checked) { if (!empty($checked)) { $addresslistModel = \GO\Addressbook\Model\Addresslist::model()->findSingleByAttribute('name', $addresslistName); if ($addresslistModel) { $addresslistContactModel = \GO\Addressbook\Model\AddresslistContact::model()->findSingleByAttributes(array('contact_id' => $contactModel->id, 'addresslist_id' => $addresslistModel->id)); if (!$addresslistContactModel) { $addresslistContactModel = new \GO\Addressbook\Model\AddresslistContact(); $addresslistContactModel->contact_id = $contactModel->id; $addresslistContactModel->addresslist_id = $addresslistModel->id; $addresslistContactModel->save(); } } } } echo $this->render('contactform_done'); } else { echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel)); } } else { $validationErrors = $contactModel->getValidationErrors(); foreach ($validationErrors as $valError) { echo $valError; } echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel)); } } else { $addressbookModel = new \GO\Addressbook\Model\Addressbook(); $contactModel = new \GO\Addressbook\Model\Contact(); $companyModel = new \GO\Addressbook\Model\Company(); echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel)); } }