Class: Antispam::ChallengesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Antispam::ChallengesController
- Defined in:
- app/controllers/antispam/challenges_controller.rb
Instance Method Summary collapse
-
#new ⇒ Object
GET /challenges/new.
-
#show ⇒ Object
GET /challenges/1.
-
#update ⇒ Object
PATCH/PUT /challenges/1.
Methods inherited from ApplicationController
Instance Method Details
#new ⇒ Object
GET /challenges/new
18 19 20 21 |
# File 'app/controllers/antispam/challenges_controller.rb', line 18 def new # use in the future for changing code head :ok end |
#show ⇒ Object
GET /challenges/1
8 9 10 11 12 13 14 15 |
# File 'app/controllers/antispam/challenges_controller.rb', line 8 def show respond_to do |format| format.jpeg do image = @challenge.get_image render content_type: 'image/jpeg', plain: image.jpegsave_buffer end end end |
#update ⇒ Object
PATCH/PUT /challenges/1
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/antispam/challenges_controller.rb', line 24 def update if @challenge.validate?(params[:challenge][:answer]) a = Antispam::Ip.find_or_create_by(address: request.remote_ip, provider: 'httpbl') before = a.threat a.threat = [(a.threat || 0) - 25, 0].max c = Clear.create(ip: request.remote_ip, answer: params[:challenge][:answer], result: 'Passed', threat_before: before, threat_after: a.threat) a.expires_at = 1.hour.from_now a.save redirect_to '/' else c = Clear.create(ip: request.remote_ip, answer: params[:challenge][:answer], result: 'Failed') redirect_to '/antispam/validate', notice: 'Invalid answer.' end end |