Skip to content

Instantly share code, notes, and snippets.

@jsmitka
Created April 11, 2010 15:14
Show Gist options
  • Save jsmitka/362804 to your computer and use it in GitHub Desktop.
Save jsmitka/362804 to your computer and use it in GitHub Desktop.
{block content}
{if $showEditForm}
{widget editForm}
{else}
{widget loginForm}
{/if}
<?php
class SomePresenter extends BasePresenter
{
/** @var DibiRow */
private $item;
/** @var SessionNamespace */
private $session;
public function actionEdit($id)
{
$model = new ServiceModel();
$this->item = $model->fetch($id);
$this->session = Environment::getSession('SomePresenter-edit');
}
public function renderEdit($id)
{
$this->template->showEditForm = (isset($this->session->key) && $this->session->key == $this->item->password);
}
protected function createComponentLoginForm()
{
$form = new AppForm();
$form->addPassword('password', 'Heslo:')
->addRule(Form::FILLED, 'Zadejte heslo.');
$form->addSubmit('login', 'Přihlásit');
$form->addProtection('Please submit this form again (security token has expired).');
$form->onSubmit[] = callback($this, 'loginFormSubmitted');
return $form;
}
protected function createComponentEditForm()
{
$form = new AppForm();
// ... definice formuláře...
$form->onSubmit[] = callback($this, 'editFormSubmitted');
return $form;
}
public function loginFormSubmitted(Form $form)
{
$values = $form->getValues();
if (sha1($values['password']) == $this->item->password) {
$this->session->key = $this->item->password;
$this->redirect('this');
} else
$form->addError('Chybné heslo.');
}
public function editFormSubmitted(Form $form)
{
if ($this->session->key != $this->item->password) {
$this->redirect('this');
// po redirectu se zobrazí přihlašovací formulář
} else {
// zpracování
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment