Skip to content
Browse files

Make it work, make it work, make it wooork!!!

  • Loading branch information...
1 parent 858f3c8 commit b2c642af417fa73774b5b9967e3e9bee9ca02324 @ConradIrwin ConradIrwin committed Aug 26, 2012
Showing with 61 additions and 13 deletions.
  1. +5 −0 Gemfile
  2. +16 −1 Gemfile.lock
  3. +6 −0 app/controllers/application_controller.rb
  4. +29 −11 app/controllers/users_controller.rb
  5. +5 −1 config/initializers/octokey.rb
View
5 Gemfile
@@ -43,3 +43,8 @@ gem 'coderay' # syntax highlighting
# To use debugger
# gem 'debugger'
+
+group :development do
+ gem 'pry-rescue'
+ gem 'pry-stack_explorer'
+end
View
17 Gemfile.lock
@@ -29,6 +29,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
+ binding_of_caller (0.6.7)
builder (3.0.0)
coderay (1.0.6)
coffee-rails (3.2.2)
@@ -47,6 +48,7 @@ GEM
high_voltage (1.1.1)
hike (1.2.1)
i18n (0.6.0)
+ interception (0.1)
journey (1.0.4)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
@@ -63,11 +65,21 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ method_source (0.8)
mime-types (1.19)
multi_json (1.3.6)
- octokey (0.1.pre.2)
+ octokey (0.1.pre.4)
pg (0.14.0)
polyglot (0.3.3)
+ pry (0.9.10)
+ coderay (~> 1.0.5)
+ method_source (~> 0.8)
+ slop (~> 3.3.1)
+ pry-rescue (0.5)
+ interception
+ pry
+ pry-stack_explorer (0.4.5)
+ binding_of_caller (~> 0.6.2)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -98,6 +110,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ slop (3.3.2)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
@@ -134,6 +147,8 @@ DEPENDENCIES
kramdown
octokey (>= 0.1.pre)
pg
+ pry-rescue
+ pry-stack_explorer
rails (= 3.2.6)
sass-rails (~> 3.2.3)
thin
View
6 app/controllers/application_controller.rb
@@ -1,6 +1,12 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ around_filter :pry_rescue if Rails.env == 'development'
+
+ def pry_rescue
+ Pry::rescue{ yield }
+ end
+
private
def octokey_username
View
40 app/controllers/users_controller.rb
@@ -1,7 +1,5 @@
class UsersController < ApplicationController
- layout 'website'
-
def index
redirect_to :new_user
end
@@ -10,22 +8,42 @@ def new
end
def create
- email, public_key = octokey_signup
- user = User.create!(
- :email => email,
- :public_keys => public_key,
- :name => params[:name]
- )
-
- redirect_to user_url(user)
+ signup = Octokey.new(params['auth_request'],
+ :username => params['username'],
+ :client_ip => client_ip)
+
+ if signup.can_sign_up?
+ user = User.create!(
+ :email => signup.username,
+ :public_keys => signup.public_key,
+ :name => params[:name]
+ )
+
+ redirect_to user_url(user)
+ elsif signup.should_retry?
+ redirect_to new_user_url
+ else
+ puts signup.errors
+ raise "go away"
+ end
end
def show
@user = User.find(params[:id])
end
def update
- @user = User.find(params[:id])
+ login = Octokey.new(params['auth_request'],
+ :username => params['username'],
+ :client_ip => client_ip)
+ if login.can_log_in?
+ @user = User.find(params[:id])
+ elsif login.should_retry?
+ redirect_to user_url(params[:id])
+ else
+ puts login.errors
+ raise "go away"
+ end
end
def challenge
View
6 config/initializers/octokey.rb
@@ -1 +1,5 @@
-Octokey.hmac_secret = ENV["OCTOKEY_HMAC_SECRET"] or raise "no OCTOKEY_HMAC_SECRET set"
+Octokey::Config.hmac_secret = ENV["OCTOKEY_HMAC_SECRET"] or raise "no OCTOKEY_HMAC_SECRET set"
+Octokey::Config.valid_hostnames = ["thinkpad.jelzo.com"]
+Octokey::Config.public_keys{ |username, opts|
+ User.where(:email => username).map(&:public_keys)
+}

0 comments on commit b2c642a

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