Permalink
Browse files

typos

  • Loading branch information...
dg committed Sep 6, 2012
1 parent af85f09 commit 05fd13598d4544c22e20e4d000992891358f9e65
Showing with 42 additions and 33 deletions.
  1. +5 −7 app/config/config.neon
  2. +17 −8 app/model/Authenticator.php
  3. +2 −3 app/presenters/ErrorPresenter.php
  4. +18 −15 app/presenters/SignPresenter.php
View
@@ -11,20 +11,18 @@ common:
date.timezone: Europe/Prague
# zlib.output_compression: yes
-
nette:
application:
errorPresenter: Error
+ database:
+ dsn: 'mysql:host=localhost;dbname=test'
+ user:
+ password:
+
session:
expiration: 14 days
- database:
- default:
- dsn: 'mysql:host=localhost;dbname=test'
- user:
- password:
-
services:
authenticator: Authenticator
@@ -1,12 +1,23 @@
<?php
-use Nette\Security as NS;
+use Nette\Security,
+ Nette\Utils\Strings;
+/*
+CREATE TABLE users (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ username varchar(50) NOT NULL,
+ password char(60) NOT NULL,
+ role varchar(20) NOT NULL,
+ PRIMARY KEY (id)
+);
+*/
+
/**
* Users authenticator.
*/
-class Authenticator extends Nette\Object implements NS\IAuthenticator
+class Authenticator extends Nette\Object implements Security\IAuthenticator
{
/** @var Nette\Database\Connection */
private $database;
@@ -21,8 +32,7 @@ public function __construct(Nette\Database\Connection $database)
/**
- * Performs an authentication
- * @param array
+ * Performs an authentication.
* @return Nette\Security\Identity
* @throws Nette\Security\AuthenticationException
*/
@@ -32,22 +42,21 @@ public function authenticate(array $credentials)
$row = $this->database->table('users')->where('username', $username)->fetch();
if (!$row) {
- throw new NS\AuthenticationException("User '$username' not found.", self::IDENTITY_NOT_FOUND);
+ throw new Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
}
if ($row->password !== $this->calculateHash($password)) {
- throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
+ throw new Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
}
unset($row->password);
- return new NS\Identity($row->id, $row->role, $row->toArray());
+ return new Security\Identity($row->id, $row->role, $row->toArray());
}
/**
* Computes salted password hash.
- * @param string
* @return string
*/
public function calculateHash($password)
@@ -1,7 +1,6 @@
<?php
-use Nette\Diagnostics\Debugger,
- Nette\Application as NA;
+use Nette\Diagnostics\Debugger;
@@ -21,7 +20,7 @@ public function renderDefault($exception)
$this->payload->error = TRUE;
$this->terminate();
- } elseif ($exception instanceof NA\BadRequestException) {
+ } elseif ($exception instanceof Nette\Application\BadRequestException) {
$code = $exception->getCode();
// load template 403.latte or 404.latte or ... 4xx.latte
$this->setView(in_array($code, array(403, 404, 405, 410, 500)) ? $code : '4xx');
@@ -1,7 +1,6 @@
<?php
-use Nette\Application\UI,
- Nette\Security as NS;
+use Nette\Application\UI;
/**
@@ -12,22 +11,23 @@ class SignPresenter extends BasePresenter
/**
- * Sign in form component factory.
+ * Sign-in form factory.
* @return Nette\Application\UI\Form
*/
protected function createComponentSignInForm()
{
$form = new UI\Form;
$form->addText('username', 'Username:')
- ->setRequired('Please provide a username.');
+ ->setRequired('Please enter your username.');
$form->addPassword('password', 'Password:')
- ->setRequired('Please provide a password.');
+ ->setRequired('Please enter your password.');
- $form->addCheckbox('remember', 'Remember me on this computer');
+ $form->addCheckbox('remember', 'Keep me signed in');
$form->addSubmit('send', 'Sign in');
+ // call method signInFormSubmitted() on success
$form->onSuccess[] = $this->signInFormSubmitted;
return $form;
}
@@ -36,19 +36,22 @@ protected function createComponentSignInForm()
public function signInFormSubmitted($form)
{
+ $values = $form->getValues();
+
+ if ($values->remember) {
+ $this->getUser()->setExpiration('+ 14 days', FALSE);
+ } else {
+ $this->getUser()->setExpiration('+ 20 minutes', TRUE);
+ }
+
try {
- $values = $form->getValues();
- if ($values->remember) {
- $this->getUser()->setExpiration('+ 14 days', FALSE);
- } else {
- $this->getUser()->setExpiration('+ 20 minutes', TRUE);
- }
$this->getUser()->login($values->username, $values->password);
- $this->redirect('Homepage:');
-
- } catch (NS\AuthenticationException $e) {
+ } catch (Nette\Security\AuthenticationException $e) {
$form->addError($e->getMessage());
+ return;
}
+
+ $this->redirect('Homepage:');
}

0 comments on commit 05fd135

Please sign in to comment.