Skip to content
Browse files

Signup within the app. Closes #81.

Sweeet. This is in conjunction with website commit 9569f59.
  • Loading branch information...
1 parent 28bad62 commit b47d87a3aa177794b3266e6d1abe98044860df3b @steveklabnik steveklabnik committed Jan 17, 2011
Showing with 71 additions and 23 deletions.
  1. +63 −22 app/ui/tabs/prefs.rb
  2. +8 −1 lib/web/hacker.rb
View
85 app/ui/tabs/prefs.rb
@@ -33,43 +33,84 @@ def clover_whoosh
def content
user = HH::PREFS['username']
- clover_whoosh
stack :margin => [10, 20, 0, 20], :width => 1.0, :height => 1.0 do
subtitle "Your Preferences", :font => "Lacuna Regular", :margin => 0, :size => 22,
:stroke => "#377"
if user
para "Hello, #{user}! ",
else
- para "Let's set up Hackety Hack to use on the Internet okay? ",
- "Be sure you have an account from ",
- link("hackety-hack.com", :click => "http://hackety-hack.com"), "."
+ @question_stack = stack do
+ para "You can connect with your account on ",
+ link("hackety-hack.com", :click => "http://hackety-hack.com"),
+ " to do all kinds of fun stuff. Do you have one?"
+ button "Yes" do
+ @question_stack.toggle
+ @prefpane.toggle
+ end
+
+ button "No" do
+ @question_stack.toggle
+ @signup_stack.toggle
+ end
+ end
+ end
+
+ @prefpane = stack :margin => 20, :width => 400 do
+ para "Website credentials", :size => :large
+ para "Your username", :size => 10, :margin => 2, :stroke => "#352"
+ @user = edit_line user, :width => 1.0
+
+ para "Your password", :size => 10, :margin => 2, :stroke => "#352"
+ @pass = edit_line HH::PREFS['password'], :width => 1.0, :secret => true
+
+ button "Save", :margin_top => 10 do
+ 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
+ @prefpane.toggle
- @prefpane =
- stack do
- stack :margin => 20, :width => 400 do
- para "Your username", :size => 10, :margin => 2, :stroke => "#352"
- @user = edit_line user, :width => 1.0
+ @signup_stack = stack do
+ para "Website Account Signup", :size => :large
+ para "Let's get you set up with one! All fields are required."
+ para "Username:", :size => 10, :margin => 2, :stroke => "#352"
+ @user = edit_line "", :width => 1.0
- para "Your password", :size => 10, :margin => 2, :stroke => "#352"
- @pass = edit_line HH::PREFS['password'], :width => 1.0, :secret => true
+ para "Email:", :size => 10, :margin => 2, :stroke => "#352"
+ @email = edit_line "", :width => 1.0
- button "Save", :margin_top => 10 do
- 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
+ para "Password", :size => 10, :margin => 2, :stroke => "#352"
+ @pass = edit_line "", :width => 1.0, :secret => true
- 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
+ button "Sign up", :margin_top => 10 do
+ hacker = Hacker.new :username => @user.text, :email => @email.text, :password => @pass.text
+ hacker.sign_up! do |response|
+ if response.status == 200
+ alert("Great! We've got you signed up.")
+ HH::PREFS['username'] = @user.text
+ HH::PREFS['password'] = @pass.text
+ HH::PREFS['email'] = @email.text
+ HH.save_prefs
+ @signup_stack.toggle
+ @prefpane.toggle
+ else
+ alert("Uhhh... there was a problem. I couldn't sign you up. Make sure nobody has your username!")
end
end
end
+
end
+ @signup_stack.toggle
end
end
View
9 lib/web/hacker.rb
@@ -11,10 +11,12 @@ class Hacker
attr :name
attr :password
+ attr :email
def initialize(who)
@name = who[:username]
@password = who[:password]
+ @email = who[:email]
end
def inspect
@@ -33,7 +35,12 @@ def auth_check &blk
http('POST', "/check_credentials", {:username => @name, :password => @password}) do |result|
blk[result.response]
end
- ret
+ end
+
+ def sign_up! &blk
+ http('POST', "/signup_via_api", {:username => @name, :email => @email, :password => @password}) do |result|
+ blk[result.response]
+ end
end
def save_program_to_the_cloud name, code, &blk

0 comments on commit b47d87a

Please sign in to comment.
Something went wrong with that request. Please try again.