public function registerAction() { if ($this->oAuth->isLoggedIn()) { $this->redirect('/'); return; } $this->mTemplate->title = $this->getLang('title_registration'); $this->mTemplate->sSectionTitle = $this->getLang('title_registration'); $sUser = $this->post('user_name'); $sPass = $this->post('user_pass'); $sEmail = $this->post('user_email'); $sAccount_name = $this->post('account_name'); $oValidator = new Module_Validator(); $oValidator->field('nick', $sUser, $this->getLang('user.nick'))->rules('required'); $oValidator->field('password', $sPass, $this->getLang('user.password'))->rules('required|md5'); $oValidator->field('email', $sEmail, $this->getLang('user.email'))->rules('required|email'); $oValidator->field('account_name', $sAccount_name, $this->getLang('user.account_name'))->rules('required'); if (isset($_POST['submit'])) { if ($oValidator->validate()) { // sprawdzamy czy nie ma juz takiego konta lub usera $oUser = new Model_User(); $aRes = $oUser->where('email', $sEmail)->getRow(); if (empty($aRes)) { $oUser->reset(); $oAccount = new Model_Account(); $oAccount->name = $sAccount_name; if ($iAccountId = $oAccount->save()) { $oUser->name = $sUser; $oUser->email = $sEmail; $oUser->password = $sPass; $oUser->role_id = 1; $oUser->account_id = $iAccountId; if ($oUser->save()) { $this->redirect('/user/login/'); } else { $error = $this->getLang('failed_creating_user'); } } else { $error = $this->getLang('failed_creating_account'); } } else { $error = $this->getLang('user_already_exists'); } } else { $error = 'Blad danych wejsciowych.'; $aErrors = $oValidator->getError(); foreach ($aErrors as $sField => $aError) { $error .= '<br />' . $this->getLang($aError['msg'], $aError['field_name']); } } } // generate form $aData = array('label_user' => $this->getLang('user.nick'), 'label_pass' => $this->getLang('user.password'), 'label_email' => $this->getLang('user.email'), 'label_accountname' => $this->getLang('user.account_name'), 'user_name' => $sUser, 'user_pass' => '', 'user_email' => $sEmail, 'account_name' => $sAccount_name, 'submit' => $this->getLang('user.register'), 'error' => isset($error) ? $error : null); $this->mTemplate->content = View::factory('user/registration_form', $aData)->render(); }
protected function saveAccount() { $this->mTemplate->sSectionTitle = $this->getLang('section_title_settings_saving'); $sName = $this->post('name'); $sTime = $this->post('day_end'); $fMaxPrice = $this->post('max_price'); $iEmployeePercent = $this->post('employee_percent'); $sCss = $this->post('css'); $oValidator = new Module_Validator(); $oValidator->field('company_name', $sName)->rules('required|hsc'); $oValidator->field('order_end_time', $sTime)->rules('required'); $oValidator->field('max_price_of_meal', $fMaxPrice)->rules('required|tofloat'); $oValidator->field('employee_cost', $iEmployeePercent)->rules('required|toint'); if ($oValidator->validate()) { // zapisujemy ustawienia $oAccaount = new Model_Account($this->oCurrentUser->account_id); $oAccaount->getRow(); $oAccaount->name = $sName; $oAccaount->day_end = $sTime; $oAccaount->max_price = $fMaxPrice; $oAccaount->employee_percent = $iEmployeePercent; $oAccaount->css = $sCss; if ($oAccaount->save()) { $aMeta = $this->mTemplate->aMeta; $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor() . '" />'; $this->mTemplate->aMeta = $aMeta; $this->mTemplate->content = $this->getLang('save_settings_successfull'); return true; } else { return $this->getLang('save_settings_failed'); } } else { $aErrors = $oValidator->getError(); foreach ($aErrors as $sField => $aError) { $sMsg .= '<br />' . $this->getLang($aError['msg'], $this->getLang($sField)); } return $sMsg; } }