diff options
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 23 | ||||
| -rw-r--r-- | app/controllers/sessions_controller.rb | 17 | ||||
| -rw-r--r-- | config/initializers/omniauth.rb | 3 | ||||
| -rw-r--r-- | config/routes.rb | 3 |
5 files changed, 47 insertions, 0 deletions
@@ -21,6 +21,7 @@ end gem 'jquery-rails' gem 'bootswatch-rails' +gem 'omniauth-github' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index c773920..0053919 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,19 +42,41 @@ GEM erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) + faraday (0.8.4) + multipart-post (~> 1.1) + hashie (1.2.0) hike (1.2.1) + httpauth (0.1) i18n (0.6.0) journey (1.0.4) jquery-rails (2.1.1) railties (>= 3.1.0, < 5.0) thor (~> 0.14) json (1.7.5) + jwt (0.1.5) + multi_json (>= 1.0) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) multi_json (1.3.6) + multipart-post (1.1.5) + oauth2 (0.8.0) + faraday (~> 0.8) + httpauth (~> 0.1) + jwt (~> 0.1.4) + multi_json (~> 1.0) + rack (~> 1.2) + omniauth (1.1.1) + hashie (~> 1.2) + rack + omniauth-github (1.0.2) + omniauth (~> 1.0) + omniauth-oauth2 (~> 1.1) + omniauth-oauth2 (1.1.0) + oauth2 (~> 0.8.0) + omniauth (~> 1.0) polyglot (0.3.3) rack (1.4.1) rack-cache (1.2) @@ -108,6 +130,7 @@ DEPENDENCIES bootswatch-rails coffee-rails (~> 3.2.1) jquery-rails + omniauth-github rails (= 3.2.8) sass-rails (~> 3.2.3) sqlite3 diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..8d64438 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,17 @@ +class SessionsController < ApplicationController + def create + auth = request.env["omniauth.auth"] + Rails.logger.info auth + user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth) + session[:user_id] = user.id + redirect_to root_url, :notice => "Signed in!" + end + + def destroy + session[:user_id] = nil + redirect_to root_url, :notice => "Signed out!" + end + + def failure + end +end diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000..e8af172 --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'] +end diff --git a/config/routes.rb b/config/routes.rb index 95993bd..bdc5ca9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Techtalk::Application.routes.draw do + match "/auth/:provider/callback" => "sessions#create" + match "/auth/failure" => "sessions#failure" + match "signout" => "sessions#destroy", :as => :signout # The priority is based upon order of creation: # first created -> highest priority. |
