Created
November 15, 2013 16:41
-
-
Save anonymous/7487411 to your computer and use it in GitHub Desktop.
API DATA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomeController < ApplicationController | |
def index | |
print Rails.logger.info "::HOME-DATA::#{@data}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Index file of /home | |
<%= debug @data %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def providers | |
user = User.from_omniauth(request.env["omniauth.auth"]) | |
if user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google" | |
User.data_from_omniauth(request.env["omniauth.auth"]) # This will have a api data, for testing i am just passing the auth and also using User model | |
sign_in_and_redirect user | |
else | |
session["devise.user_attributes"] = user.attributes | |
redirect_to new_user_registration_url | |
end | |
end | |
alias_method :google_oauth2, :providers | |
# def failure | |
# end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Include default devise modules. Others available are: | |
# :confirmable, :lockable, :timeoutable and :omniauthable | |
devise :database_authenticatable, :registerable, :confirmable, | |
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:google_oauth2] | |
def self.from_omniauth(auth) | |
where(auth.slice(:provider, :uid)).first_or_create do |user| | |
user.provider = auth.provider | |
user.uid = auth.uid | |
end | |
end | |
def self.new_with_session(params, session) | |
if session["devise.user_attributes"] | |
new session["devise.user_attributes"] do |user| | |
user.attributes = params | |
user.valid? | |
end | |
else | |
super | |
end | |
end | |
def self.data_from_omniauth(data) # This is the method i am passing data | |
# @data = data | |
print Rails.logger.info "::USER-DATA::#{data}" | |
end | |
def password_required? | |
super && provider.blank? | |
end | |
def update_with_password(params, *options) | |
if encrypted_password.blank? | |
update_attributes(params, *options) | |
else | |
super | |
end | |
end | |
def confirmation_required? | |
super && provider.blank? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment