mixing in some sorcery auth
This commit is contained in:
2
app/assets/javascripts/oauths.js
Normal file
2
app/assets/javascripts/oauths.js
Normal file
@ -0,0 +1,2 @@
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
3
app/assets/stylesheets/oauths.scss
Normal file
3
app/assets/stylesheets/oauths.scss
Normal file
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Oauths controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -31,7 +31,7 @@ form {
|
||||
}
|
||||
|
||||
fieldset {
|
||||
margin: 15px;
|
||||
border: 0;
|
||||
margin: 15px;
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,4 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
def current_user
|
||||
# temp
|
||||
Person.new(id: 9999)
|
||||
end
|
||||
helper_method :current_user
|
||||
end
|
||||
|
34
app/controllers/oauths_controller.rb
Normal file
34
app/controllers/oauths_controller.rb
Normal file
@ -0,0 +1,34 @@
|
||||
class OauthsController < ApplicationController
|
||||
skip_before_filter :require_login
|
||||
|
||||
def oauth
|
||||
login_at(params[:provider])
|
||||
end
|
||||
|
||||
def callback
|
||||
provider = params[:provider]
|
||||
@user = login_from(provider)
|
||||
|
||||
if @user
|
||||
redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
|
||||
else
|
||||
begin
|
||||
@user = create_from(provider)
|
||||
# NOTE: this is the place to add '@user.activate!'
|
||||
# if you are using user_activation submodule
|
||||
|
||||
reset_session # protect from session fixation attack
|
||||
auto_login(@user)
|
||||
redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
|
||||
rescue
|
||||
redirect_to root_path, alert: "Failed to login from #{provider.titleize}!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def auth_params
|
||||
params.permit(:code, :provider)
|
||||
end
|
||||
end
|
2
app/helpers/oauths_helper.rb
Normal file
2
app/helpers/oauths_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module OauthsHelper
|
||||
end
|
3
app/models/authentication.rb
Normal file
3
app/models/authentication.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class Authentication < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
end
|
@ -1,6 +1,9 @@
|
||||
class Person < ActiveRecord::Base
|
||||
authenticates_with_sorcery!
|
||||
has_many :parenthoods
|
||||
has_many :children, through: :parenthoods
|
||||
has_many :authentications, dependent: :destroy
|
||||
accepts_nested_attributes_for :authentications
|
||||
accepts_nested_attributes_for :children, reject_if: :all_blank
|
||||
|
||||
validates :first_name, presence: true
|
||||
@ -30,4 +33,10 @@ class Person < ActiveRecord::Base
|
||||
def to_i
|
||||
id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
## SorceryCore expects the model to hold a crypted_password field
|
||||
## Since we are only using external oAuth providers, faking this one out.
|
||||
def crypted_password; end
|
||||
end
|
||||
|
@ -1,2 +1,4 @@
|
||||
%h2 Something helpful later
|
||||
%p= link_to 'Login with Google', auth_at_provider_path(provider: :google)
|
||||
|
||||
%h2 Something more helpful later
|
||||
%p= raw(ap @doc)
|
||||
|
0
app/views/oauths/_sub_nav.html.haml
Normal file
0
app/views/oauths/_sub_nav.html.haml
Normal file
2
app/views/oauths/callback.html.haml
Normal file
2
app/views/oauths/callback.html.haml
Normal file
@ -0,0 +1,2 @@
|
||||
%h1 Oauths#callback
|
||||
%p Find me in app/views/oauths/callback.html.haml
|
2
app/views/oauths/oauth.html.haml
Normal file
2
app/views/oauths/oauth.html.haml
Normal file
@ -0,0 +1,2 @@
|
||||
%h1 Oauths#oauth
|
||||
%p Find me in app/views/oauths/oauth.html.haml
|
Reference in New Issue
Block a user