Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use message hash as identifier

  • Loading branch information...
commit eead1b587f7dd3823c35e3b3a26c49e349801665 1 parent dbb9a55
@juzna authored
View
1  app/bootstrap.php
@@ -31,6 +31,7 @@
// Setup router
$container->router[] = new Route('index.php', 'Homepage:default', Route::ONE_WAY);
+$container->router[] = new Route('record/<hash [a-f0-9]+>', 'Record:default');
$container->router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');
View
11 app/model/RecordService.php
@@ -22,17 +22,18 @@ public function __construct(Nette\Database\Connection $database, $ip = null)
public function add($message, $content)
{
return $this->database->table('records')->insert(array(
+ 'hash' => sha1($message . $content . time()),
'message' => $message,
'content' => $content,
- 'added' => new DateTime,
- 'ip' => $this->ip,
+ 'added' => new DateTime,
+ 'ip' => $this->ip,
));
}
- public function fetch($id)
+ public function fetch($hash)
{
- return $this->database->table('records')->get($id);
+ return $this->database->table('records')->where('hash', $hash)->fetch();
}
-}
+}
View
4 app/presenters/RecordPresenter.php
@@ -10,9 +10,9 @@ class RecordPresenter extends BasePresenter
- public function renderDefault($id)
+ public function renderDefault($hash)
{
- $this->template->record = $record = $this->context->recordService->fetch($id);
+ $this->template->record = $record = $this->context->recordService->fetch($hash);
}
View
6 db.sql
@@ -8,12 +8,12 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `records`;
CREATE TABLE `records` (
`id` int(11) NOT NULL AUTO_INCREMENT,
+ `hash` varchar(255) NOT NULL,
`message` varchar(255) NOT NULL,
`content` longtext NOT NULL,
`added` datetime NOT NULL,
`ip` varchar(15) DEFAULT NULL,
- PRIMARY KEY (`id`)
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `hash` (`hash`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-
--- 2012-08-02 22:27:47
Please sign in to comment.
Something went wrong with that request. Please try again.