Permalink
Browse files

added oauth2 stuff

  • Loading branch information...
1 parent 99993e4 commit 290cb1100f6fd7d76f85744c1a7cde47f004f18b @stellard committed Dec 16, 2010
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm --create ree-1.8.7-2010.02@oauth
View
@@ -9,6 +9,7 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
gem "authlogic"
gem "oauth2"
+gem 'ruby-debug'
# Use unicorn as the web server
# gem 'unicorn'
View
@@ -34,13 +34,15 @@ GEM
authlogic (2.1.6)
activesupport
builder (2.1.2)
+ columnize (0.3.2)
erubis (2.6.6)
abstract (>= 1.0.0)
faraday (0.5.3)
addressable (~> 2.2.2)
multipart-post (~> 1.0.1)
rack (>= 1.1.0, < 2)
i18n (0.4.2)
+ linecache (0.43)
mail (2.2.12)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -72,6 +74,11 @@ GEM
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
sqlite3-ruby (1.3.2)
thor (0.14.6)
treetop (1.4.9)
@@ -85,4 +92,5 @@ DEPENDENCIES
authlogic
oauth2
rails (= 3.0.1)
+ ruby-debug
sqlite3-ruby
@@ -1,8 +1,7 @@
class ApplicationController < ActionController::Base
helper :all
helper_method :current_user_session, :current_user
- filter_parameter_logging :password, :password_confirmation
- protect_from_forgery
+
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@@ -8,11 +8,14 @@ def new
def create
@user_session = UserSession.new(params[:user_session])
- if @user_session.save
- flash[:notice] = "Login successful!"
- redirect_back_or_default account_url
- else
- render :action => :new
+
+ @user_session.save do |result|
+ if result
+ flash[:notice] = "Login successful!"
+ redirect_back_or_default account_url
+ else
+ render :action => :new
+ end
end
end
@@ -43,12 +43,14 @@ def create
@user = User.new(params[:user])
respond_to do |format|
- if @user.save
- format.html { redirect_to(@user, :notice => 'User was successfully created.') }
- format.xml { render :xml => @user, :status => :created, :location => @user }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ @user.save do |result|
+ if result
+ format.html { redirect_to(@user, :notice => 'User was successfully created.') }
+ format.xml { render :xml => @user, :status => :created, :location => @user }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
end
end
end
@@ -1,3 +1,6 @@
class UserSession < Authlogic::Session::Base
- # configuration here, see documentation for sub modules of Authlogic::Session
+ oauth2_client_id "17cc28a00decebdcb091"
+ oauth2_client_secret "332407dff6644680409e071737e21dd49396db5c"
+ oauth2_site "https://github.com/login"
+ oauth2_scope "repo,user"
end
@@ -1,13 +1,4 @@
-<h1>Login</h1>
-
<% form_for @user_session, :as => :user_session, :url => { :action => "create" } do |f| %>
- <%= f.label :login %><br />
- <%= f.text_field :login %><br />
- <br />
- <%= f.label :password %><br />
- <%= f.password_field :password %><br />
- <br />
- <%= f.check_box :remember_me %><%= f.label :remember_me %><br />
- <br />
- <%= f.submit "Login" %>
+ # All your other form stuff goes here, if you need it.
+ <%= raw oauth2_login_button :value => "Login using Github" %>
<% end %>
@@ -1,7 +1,4 @@
-<h1>Register</h1>
-
<% form_for @user, :url => account_path do |f| %>
- <%= f.error_messages %>
- <%= render :partial => "form", :object => f %>
- <%= f.submit "Register" %>
+ # All your other form stuff goes here, if you need it.
+ <%= raw oauth2_register_button :value => "Register using Github" %>
<% end %>
@@ -0,0 +1,10 @@
+class AddOauth2 < ActiveRecord::Migration
+ def self.up
+ add_column :users, :oauth2_token, :string
+ add_index :users, :oauth2_token
+ end
+
+ def self.down
+ remove_column :users, :oauth2_token
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20101216001351) do
+ActiveRecord::Schema.define(:version => 20101216004605) do
create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
@@ -39,6 +39,9 @@
t.string "last_login_ip"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "oauth2_token"
end
+ add_index "users", ["oauth2_token"], :name => "index_users_on_oauth2_token"
+
end

0 comments on commit 290cb11

Please sign in to comment.