Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add method to confirmable to improve flexibility on changing emails #2187

Closed
wants to merge 2 commits into from

2 participants

@sopwithpup

I use an overridden confirmations_controller to get users to pay via cc or paypal when they sign up. If they then try to change their email or password they are asked to pay again.

I added confirm_changed_by_token to confirmable.rb to allow devise:confirmable to respond differently to already confirmed accounts.

Could be useful more generally if for example users have to fill in some info when confirming, you don't want that to happen if they just change their email.

sopwithpup added some commits
@sopwithpup sopwithpup Update lib/devise/models/confirmable.rb
 I added this as I am overriding confirmable to allow subscribed users to subscribe 
via paypal or cc. If they then change their email, the default confirmable expects them to 
pay again!
654e60e
@sopwithpup sopwithpup Update lib/devise/models/confirmable.rb 9267739
@josevalim
Owner

Thank you for the pull request. Maybe this method should be called find_for_confirmation and then the other method in that module should just rely on it? We also need tests.

@sopwithpup
@josevalim
Owner

Please let us know if there is still an interest into merging this in. CLosing for now, thanks!

@josevalim josevalim closed this
@sopwithpup

Will do, just a bit busy with work! Will post when done

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2012
  1. @sopwithpup

    Update lib/devise/models/confirmable.rb

    sopwithpup authored
     I added this as I am overriding confirmable to allow subscribed users to subscribe 
    via paypal or cc. If they then change their email, the default confirmable expects them to 
    pay again!
  2. @sopwithpup
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/devise/models/confirmable.rb
View
13 lib/devise/models/confirmable.rb
@@ -249,6 +249,19 @@ def confirm_by_token(confirmation_token)
confirmable.confirm! if confirmable.persisted?
confirmable
end
+
+ # find an already confirmed used by token
+ # return the user
+ # useful if you are using confirmable to take payment or otherwise process
+ # the user account on the initial confirmation only and want to enable
+ # changing email with confirmations
+
+ def confirm_changed_by_token(confirmation_token)
+ confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
+ if confirmable.persisted?
+ confirmable
+ end
+ end
# Generate a token checking if one does not already exist in the database.
def confirmation_token
Something went wrong with that request. Please try again.