Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Persist unlock token before triggering mailer #1908

Merged
merged 1 commit into from

2 participants

@mhfs

Hey guys,

The fact that the lockable module triggers the email before the token is persisted is annoying me in some specs when associated with devise-async.

Also, even tough very unlikely, the current code would allow a worker to have a tiny time frame in which it would be able to render the email before the token is persisted (devise-async loads the record from db).

This change just ensures the token is persisted before triggering the mailer.

Let me know if you need any change.

Cheers!

@josevalim josevalim merged commit c26ed53 into plataformatec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 11, 2012
  1. @mhfs
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/devise/models/lockable.rb
View
10 lib/devise/models/lockable.rb
@@ -38,11 +38,11 @@ def lock_access!
self.locked_at = Time.now.utc
if unlock_strategy_enabled?(:email)
- generate_unlock_token
+ generate_unlock_token!
send_unlock_instructions
+ else
+ save(:validate => false)
end
-
- save(:validate => false)
end
# Unlock a user by cleaning locked_at and failed_attempts.
@@ -123,6 +123,10 @@ def generate_unlock_token
self.unlock_token = self.class.unlock_token
end
+ def generate_unlock_token!
+ generate_unlock_token && save(:validate => false)
+ end
+
# Tells if the lock is expired if :time unlock strategy is active
def lock_expired?
if unlock_strategy_enabled?(:time)
Something went wrong with that request. Please try again.