Permalink
Browse files

Adding necessary controllers etc. for devise/github login

  • Loading branch information...
1 parent 0812d09 commit f6b2db926b226cff84b18e89a7435d65d51d468f Jason Lewis committed Jun 8, 2012
@@ -1,3 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ rescue_from Embargo::RequirementsError do |exception|
+ redirect_to root_url, :alert => exception.message
+ end
end
@@ -0,0 +1,6 @@
+class FrontpageController < ApplicationController
+
+ def index
+
+ end
+end
@@ -0,0 +1,23 @@
+class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
+ include Devise::Controllers::Rememberable
+
+ def github
+ @user = User.find_for_github_oauth(request.env["omniauth.auth"], current_user)
+
+ if @user.persisted?
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Github"
+ sign_in_and_redirect @user, :event => :authentication
+ remember_me(@user)
+ else
+ session["devise.github_data"] = request.env["omniauth.auth"]
+ redirect_to new_user_registration_url
+ end
+ end
+
+ def passthru
+ render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
+ # Or alternatively,
+ # raise ActionController::RoutingError.new('Not Found')
+ end
+
+end
No changes.
@@ -0,0 +1 @@
+require 'exceptions'
View
@@ -1,5 +1,14 @@
Embargo::Application.routes.draw do
- devise_for :users
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks"}
+
+ devise_scope :user do
+ get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
+ delete "/users/sign_out" => "devise/sessions#destroy"
+ end
+
+ #match 'home' => 'home#index'
+
+ root :to => 'frontpage#index'
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -2,6 +2,7 @@ class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
+ t.string :username, :null => false, :default => ""
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
@@ -31,7 +32,7 @@ def change
# t.datetime :locked_at
## Token authenticatable
- # t.string :authentication_token
+ t.string :authentication_token
t.timestamps
@@ -41,6 +42,6 @@ def change
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
- # add_index :users, :authentication_token, :unique => true
+ add_index :users, :authentication_token, :unique => true
end
end
View
@@ -0,0 +1,8 @@
+module Embargo
+
+ class RequirementsError < StandardError
+
+
+ end
+
+end

0 comments on commit f6b2db9

Please sign in to comment.