Skip to content

Commit

Permalink
Setup throttle control for threads
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Nov 2, 2014
1 parent 6c80b59 commit 97218b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/Lio/Accounts/User.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Lio\Accounts;

use Carbon\Carbon;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
Expand Down Expand Up @@ -130,6 +131,17 @@ public function getLatestRepliesPaginated($max = 5)
return $this->forumReplies()->with('thread')->paginate($max);
}

public function hasCreatedAThreadRecently()
{
$thread = $this->forumThreads()->first();

if ($thread) {
return $thread->created_at->gte(new Carbon('10 minutes ago'));
}

return false;
}

/**
* Get the presenter class.
*
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/Forum/ForumThreadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,25 @@ public function getShowThread($threadSlug)
// create a thread
public function getCreateThread()
{
$this->createSections(Input::get('tags'));

if (Auth::user()->hasCreatedAThreadRecently()) {
return $this->view('forum.threads.throttle');
}

$tags = $this->tags->getAllForForum();
$versions = $this->threads->getNew()->getLaravelVersions();
$this->createSections(Input::get('tags'));

$this->title = "Create Forum Thread";
$this->view('forum.threads.create', compact('tags', 'versions'));
}

public function postCreateThread()
{
if (Auth::user()->hasCreatedAThreadRecently()) {
return Redirect::action('ForumThreadsController@getCreateThread');
}

return $this->threadCreator->create($this, [
'subject' => Input::get('subject'),
'body' => Input::get('body'),
Expand Down
16 changes: 16 additions & 0 deletions app/views/forum/threads/throttle.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@extends('layouts._two_columns_left_sidebar')

@section('sidebar')
@include('forum._sidebar')
@stop

@section('content')
<div class="header">
<h1>Create Thread</h1>
</div>

<section class="padding">
<p>Woha, slow down! You can only create a thread every 10 minutes. Please try again in a few minutes.</p>
<p><a href="{{ action('ForumThreadsController@getIndex') }}">Back to forums.</a></p>
</section>
@stop

0 comments on commit 97218b9

Please sign in to comment.