Permalink
Browse files

Preferences now checks auth. Closes #73.

In conjunction with website commit e747e2f, we now check the authentication of preferences. Awesome.
  • Loading branch information...
steveklabnik committed Jan 18, 2011
1 parent 205e5ba commit 28bad6257910d9d00c8aa6040ec6b3eb1b2a5052
Showing with 19 additions and 4 deletions.
  1. +12 −4 app/ui/tabs/prefs.rb
  2. +7 −0 lib/web/hacker.rb
View
@@ -55,10 +55,18 @@ def content
@pass = edit_line HH::PREFS['password'], :width => 1.0, :secret => true
button "Save", :margin_top => 10 do
- HH::PREFS['username'] = @user.text
- HH::PREFS['password'] = @pass.text
- HH.save_prefs
- alert("Saved, thanks!")
+ hacker = Hacker.new :username => @user.text, :password => @pass.text
+ hacker.auth_check do |response|
+ if response.status == 200
+ HH::PREFS['username'] = @user.text
+ HH::PREFS['password'] = @pass.text
+ HH.save_prefs
+
+ alert("Saved, thanks!")
+ else
+ alert("Sorry, I couldn't authenticate you. Did you sign up for an account at http://hackety-hack.com/ ? Please double check what you've typed.")
+ end
+ end
end
end
end
View
@@ -29,6 +29,13 @@ def program_list &blk
http('GET', "/programs/#{@name}.json", :username => @name, :password => @password, &blk)
end
+ def auth_check &blk
+ http('POST', "/check_credentials", {:username => @name, :password => @password}) do |result|
+ blk[result.response]
+ end
+ ret
+ end
+
def save_program_to_the_cloud name, code, &blk
url = "/programs/#{@name}/#{name}.json"
http('PUT', url, {:creator_username => @name, :title => name, :code => code, :username => @name, :password => @password}) do |result|

0 comments on commit 28bad62

Please sign in to comment.