Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from nicoolas25/user.rb
Created June 23, 2014 00:25
Show Gist options
  • Save kivanio/a3cbf15e3d1247a3c3ce to your computer and use it in GitHub Desktop.
Save kivanio/a3cbf15e3d1247a3c3ce to your computer and use it in GitHub Desktop.
module OneConnectionBeforeConfirm
extend ActiveSupport::Concern
included do
before_create :generate_confirmation_token
after_create :send_on_create_confirmation_instructions
end
# This actions are not properly trigerred because of the rest of our modifications.
before_create :generate_confirmation_token
after_create :send_on_create_confirmation_instructions
# Alias the original devise's confirmed? method
alias :strictly_confirmed? :confirmed?
# Override the confirmed? method, this will allow an unconfirmed user to sign in
# just after sign up.
def confirmed?
sign_in_count < 2 || strictly_confirmed?
end
protected
# Must use the strictly_confirmed? method here to avoid confirmation issues.
def pending_any_confirmation
if (!strictly_confirmed? || pending_reconfirmation?)
yield
else
self.errors.add(:email, :already_confirmed)
false
end
end
end
class User
include Mongoid::Document
devise [...], :confirmable
include OneConnectionBeforeConfirm
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment