Module: Sorcery::Model::Submodules::MagicLogin::InstanceMethods
- Defined in:
- lib/sorcery/model/submodules/magic_login.rb
Instance Method Summary collapse
-
#clear_magic_login_token! ⇒ Object
Clears the token.
-
#deliver_magic_login_instructions! ⇒ Object
generates a magic login code with expiration and sends an email to the user.
-
#generate_magic_login_token! ⇒ Object
generates a reset code with expiration.
Instance Method Details
#clear_magic_login_token! ⇒ Object
Clears the token.
113 114 115 116 117 118 119 |
# File 'lib/sorcery/model/submodules/magic_login.rb', line 113 def clear_magic_login_token! config = sorcery_config sorcery_adapter.update_attributes( config.magic_login_token_attribute_name => nil, config.magic_login_token_expires_at_attribute_name => nil ) end |
#deliver_magic_login_instructions! ⇒ Object
generates a magic login code with expiration and sends an email to the user.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/sorcery/model/submodules/magic_login.rb', line 94 def deliver_magic_login_instructions! mail = false config = sorcery_config # hammering protection return false if !config.magic_login_time_between_emails.nil? && send(config.magic_login_email_sent_at_attribute_name) && send(config.magic_login_email_sent_at_attribute_name) > config.magic_login_time_between_emails.seconds.ago self.class.sorcery_adapter.transaction do generate_magic_login_token! unless config.magic_login_mailer_disabled send_magic_login_email! mail = true end end mail end |
#generate_magic_login_token! ⇒ Object
generates a reset code with expiration
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sorcery/model/submodules/magic_login.rb', line 82 def generate_magic_login_token! config = sorcery_config attributes = { config.magic_login_token_attribute_name => TemporaryToken.generate_random_token, config.magic_login_email_sent_at_attribute_name => Time.now.in_time_zone } attributes[config.magic_login_token_expires_at_attribute_name] = Time.now.in_time_zone + config.magic_login_expiration_period if config.magic_login_expiration_period sorcery_adapter.update_attributes(attributes) end |