public function loginAjax($aData) { $oResp = new xajaxResponse(); // walidacja danych $oValidator = new Module_Validator(); $oValidator->field('type_id', $iTypeId)->rules('required|toint|not[0]'); $oValidator->field('type_name', $sValue)->rules('required|hsc'); if ($oValidator->validate()) { } else { } $oUser = Model_User::tryCreate($aData['login']); $sPassHash = md5($aData['password'] . 'fibonacci98765434567'); if ($oUser !== null && $this->oAuth->login($oUser, $sPassHash)) { $oResp->redirect($this->getPageUrl('/')); } else { $oResp->assign('error_msg', 'innerHTML', 'Incorrect name or password'); } return $oResp; }
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 summaryUsers() { $this->mTemplate->sSectionTitle = $this->getLang('summary_meals'); $sCurrentDate = date('Y-m-d'); if (isset($_POST['submit'])) { $sFrom = $this->post('from'); $sTo = $this->post('to'); $oValidator = new Module_Validator(); $oValidator->field('summary_from', $sFrom, $this->getLang('summary_from'))->rules('required|date'); $oValidator->field('summary_to', $sTo, $this->getLang('summary_to'))->rules('required|date'); if ($oValidator->validate()) { $oOrder = new Model_Order(); // pobieramy wartosc jaka zwraca firma $iEmployeePercent = $this->oCurrentUser->get('account_id')->employee_percent; $aSummary = $oOrder->getSummaryForUsers((int) $this->oCurrentUser->account_id, $sFrom, $sTo); $aData['aSummary'] = $this->generateSummaryDataForUsers($aSummary, $iEmployeePercent); } else { $aErrors = $oValidator->getError(); foreach ($aErrors as $sField => $aError) { $sMsg .= '<br />' . $this->getLang($aError['msg'], $aError['field_name']); } $aData['error'] = $this->getLang('input_validation_failed') . $sMsg; } // sprawdzamy czy podpiac widok dla excela czy normalny if ($_POST['submit'] == $this->getLang('summary_generate_excel')) { $this->mTemplate = View::factory('account/summary_users_excel', $aData); return; } } else { $sFrom = date('Y-m-') . '01'; $sTo = date('Y-m-') . date('d', mktime(0, 0, 0, date('n') + 1, 0, date('Y'))); } $aData['aForm'] = array('sPeriod' => $this->getLang('summary_period'), 'sFrom' => $this->getLang('summary_from'), 'sTo' => $this->getLang('summary_to'), 'sDateFrom' => $sFrom, 'sDateTo' => $sTo, 'sSubmit' => $this->getLang('summary_generate'), 'sSubmitExcel' => $this->getLang('summary_generate_excel')); $this->mTemplate->content = View::factory('account/summary_users', $aData)->render(); }