Module: Sorcery::Model::Submodules::UserActivation
- Defined in:
- lib/sorcery/model/submodules/user_activation.rb
Overview
This submodule adds the ability to make the user activate his account via email or any other way in which he can recieve an activation code. with the activation code the user may activate his account. When using this submodule, supplying a mailer is mandatory.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sorcery/model/submodules/user_activation.rb', line 9 def self.included(base) base.sorcery_config.class_eval do attr_accessor :activation_state_attribute_name, # the attribute name to hold activation state # (active/pending). :activation_token_attribute_name, # the attribute name to hold activation code # (sent by email). :activation_token_expires_at_attribute_name, # the attribute name to hold activation code # expiration date. :activation_token_expiration_period, # how many seconds before the activation code # expires. nil for never expires. :user_activation_mailer, # your mailer class. Required when # activation_mailer_disabled == false. :activation_mailer_disabled, # when true sorcery will not automatically # email activation details and allow you to # manually handle how and when email is sent :activation_needed_email_method_name, # activation needed email method on your # mailer class. :activation_success_email_method_name, # activation success email method on your # mailer class. :prevent_non_active_users_to_login # do you want to prevent or allow users that # did not activate by email to login? end base.sorcery_config.instance_eval do @defaults.merge!(:@activation_state_attribute_name => :activation_state, :@activation_token_attribute_name => :activation_token, :@activation_token_expires_at_attribute_name => :activation_token_expires_at, :@activation_token_expiration_period => nil, :@user_activation_mailer => nil, :@activation_mailer_disabled => false, :@activation_needed_email_method_name => :activation_needed_email, :@activation_success_email_method_name => :activation_success_email, :@prevent_non_active_users_to_login => true) reset! end base.class_eval do # don't setup activation if no password supplied - this user is created automatically sorcery_adapter.define_callback :before, :create, :setup_activation, :if => Proc.new { |user| user.send(sorcery_config.password_attribute_name).present? } # don't send activation needed email if no crypted password created - this user is external (OAuth etc.) sorcery_adapter.define_callback :after, :create, :send_activation_needed_email!, :if => :send_activation_needed_email? end base.sorcery_config.after_config << :validate_mailer_defined base.sorcery_config.after_config << :define_user_activation_fields base.sorcery_config.before_authenticate << :prevent_non_active_login base.extend(ClassMethods) base.send(:include, InstanceMethods) end |