Created
April 11, 2010 15:14
-
-
Save jsmitka/362804 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{block content} | |
{if $showEditForm} | |
{widget editForm} | |
{else} | |
{widget loginForm} | |
{/if} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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