设计skip_confirmation!未能避免发送确认指令 [英] Devise skip_confirmation! fails to avoid to send the confirmation instructions
本文介绍了设计skip_confirmation!未能避免发送确认指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用已设置为如果用户使用 Oauth 或 Openid 登录,则无需确认其电子邮件地址.但是,Devise 仍在发送电子邮件确认.当我调用 User.skip_confirmation 时!我收到未定义的方法错误.我的模型:
class User 错误的def self.find_for_facebook_oauth(access_token,signed_in_resource=nil)数据 = access_token.extra.raw_infoif user = User.where(:email => data.email).first用户别的#User.skip_confirmation!User.create!(:username => data.name, :email => data.email, :password => Devise.friendly_token[0,20])结尾结尾def跳过_确认!self.confirmed_at = Time.now结尾结尾
我的控制器:
class Users::OmniauthCallbacksController <设计::OmniauthCallbacksController定义脸书@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)@user.skip_confirmation!如果@user.persisted?登录@user@fname = @user.usernameredirect_to root_path, :flash =>{:成功=>欢迎#{@fname}!"}别的session["devise.facebook_data"] = request.env["omniauth.auth"]redirect_to new_user_registration_url结尾结尾结尾
感谢您的帮助.
解决方案
在创建 User 对象并将其持久化到数据库之前,您需要跳过确认.所以你的方法的用户创建部分看起来像
<前>user = User.new(:username => data.name, :email => data.email, :password => Devise.friendly_token[0,20])user.skip_confirmation!用户保存My app is set up so that if a user signs in with Oauth or Openid, they don't have to confirm their email address. However, Devise is still sending email confirmations. When I call User.skip_confirmation! I get an undefined method error. My model:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable,
:trackable, :validatable, :confirmable, :lockable, :token_authenticatable, :omniauthable
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
validates_presence_of :username
validates_uniqueness_of :username, :case_sensitive => false
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token.extra.raw_info
if user = User.where(:email => data.email).first
user
else
#User.skip_confirmation!
User.create!(:username => data.name, :email => data.email, :password => Devise.friendly_token[0,20])
end
end
def skip_confirmation!
self.confirmed_at = Time.now
end
end
My Controller:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
@user.skip_confirmation!
if @user.persisted?
sign_in @user
@fname = @user.username
redirect_to root_path, :flash => { :success => "Welcome #{@fname}!" }
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
thanks for any help.
解决方案
You need to skip confirmation before you create the User objects and its persisted to the database. So the user creation part of your method would look like
user = User.new(:username => data.name, :email => data.email, :password => Devise.friendly_token[0,20]) user.skip_confirmation! user.save
这篇关于设计skip_confirmation!未能避免发送确认指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文