Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ gem 'jquery-rails'
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
gem 'rack-attack'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
Expand All @@ -42,6 +43,8 @@ gem 'jbuilder', '~> 2.5'

group :development, :test do
gem 'rspec-rails'
gem 'brakeman'
gem 'bundler-audit'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
Expand Down
15 changes: 12 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ GEM
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
brakeman (3.7.2)
builder (3.2.3)
bundler-audit (0.6.0)
bundler (~> 1.2)
thor (~> 0.18)
byebug (9.0.6)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -89,15 +93,17 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
mini_portile2 (2.2.0)
minitest (5.10.1)
multi_json (1.12.1)
nio4r (2.0.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
orm_adapter (0.5.0)
puma (3.8.2)
rack (2.0.1)
rack-attack (5.0.1)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.2)
Expand Down Expand Up @@ -192,6 +198,8 @@ PLATFORMS

DEPENDENCIES
bootstrap-sass
brakeman
bundler-audit
byebug
coffee-rails (~> 4.2)
devise
Expand All @@ -200,6 +208,7 @@ DEPENDENCIES
jquery-rails
listen (~> 3.0.5)
puma (~> 3.0)
rack-attack
rails (~> 5.0.2)
rspec-rails
sass-rails (~> 5.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ApplicationController < ActionController::Base

# protect_from_forgery with: :exception
protect_from_forgery with: :exception

helper_method :current_cart

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def show
@comments = @event.comments

if params[:keyword]
@comments = @comments.where( "comments.content LIKE '%#{params[:keyword]}%'")
keyword = ActiveRecord::Base::connection.quote_string( params[:keyword] )
# @comments = @comments.where("comments.content LIKE ?", "%#{params[:keyword]}")
@comments = @comments.where( "comments.content LIKE '%#{keyword}%'")
end

if params[:sort]
if params[:sort] && ["id DESC", "id ASC"].include?(params[:sort])
@comments = @comments.order(params[:sort])
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def update
protected

def user_params
params.require(:user).permit(:nickname, :role)
params.require(:user).permit(:nickname)
end

end
8 changes: 5 additions & 3 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ def user_avatar_link(user)
email_md5 = Digest::MD5.hexdigest(user.email)
gravatar_url = "https://www.gravatar.com/avatar/#{email_md5}"

str = "<div class ='user-link'>" + link_to(image_tag(gravatar_url), user_path(user)) + " " + user.display_name + "</div>"

str.html_safe
# str = "<div class ='user-link'>" + link_to(image_tag(gravatar_url), user_path(user)) + " " + user.display_name + "</div>"
#
# str.html_safe
"<div class ='user-link'>".html_safe + link_to(image_tag(gravatar_url), user_path(user)) + " " + user.display_name + "</div>".html_safe

end

end
6 changes: 3 additions & 3 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
</div>

<div class="panel-body">
<%= raw comment.content %>
<%= sanitize comment.content %>
</div>

<div class="panel-footer text-right">
<%= comment.created_at.to_s %>

<% if current_user && current_user.is_admin? %>
<%= link_to "Highligh", highlight_event_comment_path(@event, comment), :class => "btn btn-default" %>
<%= link_to "Highligh", highlight_event_comment_path(@event, comment), :method => :post, :class => "btn btn-default" %>
<% end %>

<% if comment.can_deleted_by(current_user) %>
Expand All @@ -50,4 +50,4 @@
<div class="form-group">
<%= f.submit "Comment", :class => "btn btn-primary" %>
</div>
<% end %>
<% end %>
3 changes: 2 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

module RailsRecipes
class Application < Rails::Application
config.middleware.use Rack::Attack
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand All @@ -16,4 +17,4 @@ class Application < Rails::Application
end
end

Time::DATE_FORMATS.merge!(:default => '%Y/%m/%d %I:%M %p', :ymd => '%Y/%m/%d')
Time::DATE_FORMATS.merge!(:default => '%Y/%m/%d %I:%M %p', :ymd => '%Y/%m/%d')
18 changes: 18 additions & 0 deletions config/initializers/rack-attack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Rack::Attack

throttle('req/ip', :limit => 180, :period => 1.minute) do |req|
req.ip
end

throttle('logins/ip', :limit => 5, :period => 20.seconds) do |req|
if req.path == '/users/sign_in' && req.post?
req.ip
end
end

throttle('logins/email', :limit => 5, :period => 20.seconds) do |req|
if req.path == '/users/sign_in' && req.post?
req.params['email'].presence
end
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
resources :events do
resources :comments do
member do
get :highlight
post :highlight
end
end
end
Expand Down