Skip to content

Commit 97218b9

Browse files
committed
Setup throttle control for threads
1 parent 6c80b59 commit 97218b9

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

app/Lio/Accounts/User.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Lio\Accounts;
22

3+
use Carbon\Carbon;
34
use Illuminate\Auth\Reminders\RemindableTrait;
45
use Illuminate\Auth\UserInterface;
56
use Illuminate\Auth\Reminders\RemindableInterface;
@@ -130,6 +131,17 @@ public function getLatestRepliesPaginated($max = 5)
130131
return $this->forumReplies()->with('thread')->paginate($max);
131132
}
132133

134+
public function hasCreatedAThreadRecently()
135+
{
136+
$thread = $this->forumThreads()->first();
137+
138+
if ($thread) {
139+
return $thread->created_at->gte(new Carbon('10 minutes ago'));
140+
}
141+
142+
return false;
143+
}
144+
133145
/**
134146
* Get the presenter class.
135147
*

app/controllers/Forum/ForumThreadsController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,25 @@ public function getShowThread($threadSlug)
7373
// create a thread
7474
public function getCreateThread()
7575
{
76+
$this->createSections(Input::get('tags'));
77+
78+
if (Auth::user()->hasCreatedAThreadRecently()) {
79+
return $this->view('forum.threads.throttle');
80+
}
81+
7682
$tags = $this->tags->getAllForForum();
7783
$versions = $this->threads->getNew()->getLaravelVersions();
78-
$this->createSections(Input::get('tags'));
7984

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

8489
public function postCreateThread()
8590
{
91+
if (Auth::user()->hasCreatedAThreadRecently()) {
92+
return Redirect::action('ForumThreadsController@getCreateThread');
93+
}
94+
8695
return $this->threadCreator->create($this, [
8796
'subject' => Input::get('subject'),
8897
'body' => Input::get('body'),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@extends('layouts._two_columns_left_sidebar')
2+
3+
@section('sidebar')
4+
@include('forum._sidebar')
5+
@stop
6+
7+
@section('content')
8+
<div class="header">
9+
<h1>Create Thread</h1>
10+
</div>
11+
12+
<section class="padding">
13+
<p>Woha, slow down! You can only create a thread every 10 minutes. Please try again in a few minutes.</p>
14+
<p><a href="{{ action('ForumThreadsController@getIndex') }}">Back to forums.</a></p>
15+
</section>
16+
@stop

0 commit comments

Comments
 (0)