Finally i add a counter for clean the session, after a couple of refreshes or a couple of errors it will show the normal page
user.rb
defself.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
endend#persist user in session on validation error with omniauthdefself.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection:true) do |user|
user.attributes = params
user.valid?
session["count_errors"] = session["count_errors"] + 1
session["devise.user_attributes"] = nilif session["count_errors"] == 2endelsesuperendend#validation for password on omniauthdefpassword_required?super && self.provider.blank?
end#password for update if blank on omniauthdefupdate_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
elsesuperendenddefhas_no_password?self.encrypted_password.blank?
end
omniauth_callbacks_controller.rb
classUsers::OmniauthCallbacksController < Devise::OmniauthCallbacksControllerdefall# You need to implement the method below in your model (e.g. app/models/user.rb)
user = User.from_omniauth(request.env["omniauth.auth"])
if user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => user.provider.titleize.split("").first
sign_in_and_redirect user, :event => :authenticationelse
session["count_errors"] = 0if session["devise.user_attributes"] == nil
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
endend
alias_method :twitter, :all
alias_method :google_oauth2, :allend
Hi, i'm having troubles with password_required and new_with_session
user.rb
defself.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
endend#persist user in session on validation error with omniauthdefself.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection:true) do |user|
user.attributes = params
user.valid?
endelsesuperendend#validation for password on omniauthdefpassword_required?super && self.provider.blank?
end#password for update if blank on omniauthdefupdate_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
elsesuperendenddefhas_no_password?self.encrypted_password.blank?
end
The session are always there, imagine this case, you sign up with twitter, the system asks you for a email, you regrets and want to use normal register, you can't because there isn't the password field and the provider info is still in cache, i need to know where to clear that session :/
Similar problem when you want to update the blank password with an error, it would f.object.encrypted_password.present? would return true in that case, so i add that has_no_password? method for that.
Finally i add a counter for clean the session, after a couple of refreshes or a couple of errors it will show the normal page
Hi, i'm having troubles with password_required and new_with_session
The session are always there, imagine this case, you sign up with twitter, the system asks you for a email, you regrets and want to use normal register, you can't because there isn't the password field and the provider info is still in cache, i need to know where to clear that session :/
Similar problem when you want to update the blank password with an error, it would f.object.encrypted_password.present? would return true in that case, so i add that has_no_password? method for that.
i have that problem and was going to other way for get the solution, thanks!