module Sorcery::Model::Submodules::MagicLogin
This submodule adds the ability to login via email without password. When the user requests an email is sent to him with a url. The url includes a token, which is also saved with the user's record in the db. The token has configurable expiration. When the user clicks the url in the email, providing the token has not yet expired, he will be able to login.
When using this submodule, supplying a mailer is mandatory.
Public Class Methods
included(base)
click to toggle source
# File lib/sorcery/model/submodules/magic_login.rb, line 13 def self.included(base) base.sorcery_config.class_eval do attr_accessor :magic_login_token_attribute_name, # magic login code attribute name. :magic_login_token_expires_at_attribute_name, # expires at attribute name. :magic_login_email_sent_at_attribute_name, # when was email sent, used for hammering # protection. :magic_login_mailer_class, # mailer class. Needed. :magic_login_mailer_disabled, # when true sorcery will not automatically # email magic login details and allow you to # manually handle how and when email is sent :magic_login_email_method_name, # magic login email method on your # mailer class. :magic_login_expiration_period, # how many seconds before the request # expires. nil for never expires. :magic_login_time_between_emails # hammering protection, how long to wait # before allowing another email to be sent. end base.sorcery_config.instance_eval do @defaults.merge!(:@magic_login_token_attribute_name => :magic_login_token, :@magic_login_token_expires_at_attribute_name => :magic_login_token_expires_at, :@magic_login_email_sent_at_attribute_name => :magic_login_email_sent_at, :@magic_login_mailer_class => nil, :@magic_login_mailer_disabled => true, :@magic_login_email_method_name => :magic_login_email, :@magic_login_expiration_period => 15 * 60, :@magic_login_time_between_emails => 5 * 60) reset! end base.extend(ClassMethods) base.sorcery_config.after_config << :validate_mailer_defined base.sorcery_config.after_config << :define_magic_login_fields base.send(:include, InstanceMethods) end