Class: Cheat::Controllers::Write

Inherits:
R
  • Object
show all
Defined in:
lib/cheat/site.rb

Instance Method Summary collapse

Instance Method Details

#captcha_pass?(session, answer) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/cheat/site.rb', line 149

def captcha_pass?(session, answer)
  open("http://captchator.com/captcha/check_answer/#{session}/#{answer}").read.to_i.nonzero? rescue false
end

#check_captcha!Object



145
146
147
# File 'lib/cheat/site.rb', line 145

def check_captcha!
  @error ||= !(@cookies[:passed] ||= captcha_pass?(input.chunky, input.bacon))
end

#post(title = nil) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/cheat/site.rb', line 131

def post(title = nil)
  @sheet = title ? Sheet.find_by_title(title) : Sheet.new
  @sheet = title ? Sheet.detect { |s| s.title == title } : Sheet.new

  check_captcha! unless input.from_gem

  if !@error && @sheet.update_attributes(:title => input.sheet_title, :body => input.sheet_body)
    redirect "#{URL}/s/#{@sheet.title}"
  else
    @error = true
    render title ? :edit : :add
  end
end