레일 3.0.9
고안 1.5.3없이.
Google에서 로그인을 확인하면 응용 프로그램에 제어권이 반환됩니다.레일 3 + 고안 + 구글 Omniuth + 내가 고안 구글에서 OAuth2 인증을 사용하고 있습니다위한 확</p> <p>와 확인서
제 문제는 다음과 같습니다. Devise가 확인 지침이 포함 된 편지를 보냅니다. 하지만 Devise는 사용자가 내 신청서를 통해 등록한 경우에만 Google 계정에 이러한 편지를 보내지 않습니다.
사용자 모델은 다음과 같습니다
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable
validates_presence_of :user_name, :address, :tel
# Setup accessible (or protected) attributes for your model
attr_accessible :user_name, :address, :tel, :attorney_number, :email, :password, :password_confirmation, :remember_me
has_many :eclaims
has_many :createdtemplates
before_create do |user|
user.with_agreement = 1
end
def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
data = access_token.info
user = User.where(:email => data["email"]).first
unless user
user = User.create(
user_name: 'no defined',
address: 'no defined',
tel: 'no defined',
attorney_number: nil,
email: data["email"],
encrypted_password: Devise.friendly_token[0,20],
)
end
user
end
end
사용자 : OmniauthCallbacksController
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
routes.rb :
EFiling2::Application.routes.draw do
root :to => "home#index"
devise_for :users,
:path_names => { :sign_up => "register", :sign_in => "login", :sign_out => "logout" },
:controllers => {
:sessions => "sessions",
:registrations => "registrations",
:confirmations => "confirmations",
:passwords => "passwords",
:omniauth_callbacks => "users/omniauth_callbacks"
}
end
답장을 보내 주셔서 감사합니다. –