Commit ceaa8050d0dab79ae5cad59196af5957ea0c112c
1 parent
1e0cc2a4
Exists in
article_hit_count
Restrict hit count with cookies
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> Signed-off-by: Simiao Carvalho <simiaosimis@gmail.com>
Showing
1 changed file
with
15 additions
and
1 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -8,6 +8,7 @@ class ContentViewerController < ApplicationController | @@ -8,6 +8,7 @@ class ContentViewerController < ApplicationController | ||
8 | helper TagsHelper | 8 | helper TagsHelper |
9 | 9 | ||
10 | def view_page | 10 | def view_page |
11 | + | ||
11 | path = get_path(params[:page], params[:format]) | 12 | path = get_path(params[:page], params[:format]) |
12 | 13 | ||
13 | @version = params[:version].to_i | 14 | @version = params[:version].to_i |
@@ -38,7 +39,7 @@ class ContentViewerController < ApplicationController | @@ -38,7 +39,7 @@ class ContentViewerController < ApplicationController | ||
38 | end | 39 | end |
39 | 40 | ||
40 | # At this point the page will be showed | 41 | # At this point the page will be showed |
41 | - @page.hit unless user_is_a_bot? | 42 | + @page.hit unless user_is_a_bot? || already_visited? |
42 | 43 | ||
43 | @page = FilePresenter.for @page | 44 | @page = FilePresenter.for @page |
44 | 45 | ||
@@ -272,4 +273,17 @@ class ContentViewerController < ApplicationController | @@ -272,4 +273,17 @@ class ContentViewerController < ApplicationController | ||
272 | @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | 273 | @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] |
273 | end | 274 | end |
274 | 275 | ||
276 | + private | ||
277 | + | ||
278 | + def already_visited? | ||
279 | + return true if current_user.nil? | ||
280 | + | ||
281 | + if cookies[:visited].to_i == current_user.id | ||
282 | + return true | ||
283 | + else | ||
284 | + cookies[:visited] = { value: current_user.id, expires: 7.days.from_now } | ||
285 | + return false; | ||
286 | + end | ||
287 | + end | ||
288 | + | ||
275 | end | 289 | end |