public function startup() { adminlog::init(ADMINLOG_DIR); if (!Environment::getUser()->isAuthenticated()) { $this->redirect('Login:default'); $this->terminate(); return; } fulltext::init(FULLTEXT_DIR); }
public function onLoginFormSubmit(Form $form) { $user = Environment::getUser(); $user->setAuthenticationHandler(new SimpleAuthenticator(array(ADMIN_USERNAME => ADMIN_PASSWORD))); $values = $form->getValues(); try { $user->authenticate($values['username'], $values['password']); adminlog::log(__('Successfully logged in as "%s"'), Environment::getUser()->getIdentity()->getName()); $this->redirect('Dashboard:default'); $this->terminate(); } catch (AuthenticationException $e) { adminlog::log(__('Unsuccessful log in (username: "******", password: "******")'), $values['username'], $values['password']); $this->template->error = $e; } }
public function onTitlePageFormSubmit(Form $form) { if (!$form->isValid()) { return; } $content = "<?php\nreturn "; $content .= var_export($form['content']->getValue(), TRUE); $content .= ";"; if (!@file_put_contents('safe://' . Environment::expand('%titlePageFile%'), $content)) { $form->addError(__('Cannot write to file.')); return; } adminlog::log(__('Updated title page'), $form['content']->getValue()); $this->redirect('this'); $this->terminate(); }
public function onSendMailFormSubmit(Form $form) { if (!$form->isValid()) { return; } $active = FALSE; try { dibi::begin(); $active = TRUE; mapper::order_emails()->insertOne(array('order_id' => $form['order_id']->getValue(), 'subject' => $form['subject']->getValue(), 'body' => $form['body']->getValue())); $mail = new Mail(); $mail->setFrom(Environment::expand('%shopName% <%shopEmail%>'))->addTo($form['to']->getValue())->setSubject($form['subject']->getValue())->setBody($form['body']->getValue())->send(); adminlog::log(__('Sent e-mail to "%s" with subject "%s"'), $form['to']->getValue(), $form['subject']->getValue()); $this->redirect('this'); $this->terminate(); } catch (RedirectingException $e) { dibi::commit(); throw $e; } catch (Exception $e) { if ($active) { dibi::rollback(); } $form->addError(__('Cannot send e-mail.')); } }
public function onChangeLoginFormSubmit(Form $form) { if (!$form->isValid()) { return; } if ($form['old_password']->getValue() !== Environment::expand('%adminPassword%')) { $form->addError(__('Bad old password.')); return; } $content = "<?php\nreturn " . var_export(array('username' => $form['username']->getValue(), 'password' => $form['new_password']->getValue()), TRUE) . ";\n"; if (!@file_put_contents(Environment::expand('%adminLoginFile%'), $content)) { $form->addError(__('Cannot write new login settings.')); return; } Environment::getUser()->signOut(TRUE); adminlog::log(__('Changed login credentials, logging out')); $this->redirect('this'); $this->terminate(); }
public function onImportManufacturersFormSubmit(Form $form) { if (!$form->isValid()) { return; } // read imported manufacturers if (!($handle = @fopen('safe://' . $form['file']->getValue()->getTemporaryFile(), 'r'))) { $form->addError(__('Cannot read file.')); return; } $import = array(); while (($_ = fgetcsv($handle)) !== FALSE) { $manufacturer = array(); list(, $manufacturer['name'], $manufacturer['nice_name']) = $_; $import[] = $manufacturer; } fclose($handle); adminlog::log(__('About to import manufacturers')); $manufacturers_added = 0; // import them foreach ($import as $manufacturer) { if (($_ = mapper::manufacturers()->findByNiceName($manufacturer['nice_name'])) === NULL) { mapper::manufacturers()->insertOne($manufacturer); $manufacturers_added++; } } adminlog::log(__('Added %d new manufacturers'), $manufacturers_added); }