简体   繁体   中英

Rails Devise and skip_confirmation!, how to avoid autologin

When I use a link from confirmation email to confirm my account, I'm redirected to login path, which is fine. But for some users I want to skip confirmation, so I've applied a code like below in before validation collback:

if foo?
  self.skip_confirmation!
end

Problem is that when I register as that user I'm auto logged, is it any way to prevent it ? I want to skip confirmation but not autologin.

You could try overriding devise's RegistrationsController and only override the sign_up method. The comment for that method in the devise source says "Signs in a user on sign up. You can overwrite this method in your own RegistrationsController" . You could then override it like so:

def sign_up(resource_name, resource)
  if !foo?    # or you could use "if !resource.confirmed?" instead.
    super  # The current implementation just calls sign_in(resource_name, resource)
  end
end

I haven't actually done this myself, but hopefully this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM