I'm currently implementing Devise Confirmable so that a user is sent to the confirmations page "We've sent a validation email to , check it and click on the link".
I'm being asked to implement a feature that allows a user to edit that email in case they made a mistake, and for to update and send the verification to the new email. This would only be for brand-new accounts, and not existing ones with any data in them.
The user is not logged in before they verify, and I'm sending params[:uuid] to the page, which is getting wiped whenever it reloads - not a great way to do this. I could use localstorage, I suppose...
has anyone done this before?
I would store unconfirmed account ID in the session on the server: session[:unconfirmed_account] = 999
. And then, when a user is not authenticated and there is session[:unconfirmed_account]
present, show a notification on the page with the account unconfirmed email and a link or a button to change it.
I think the best way to set :unconfirmed_account
variable in the session is by overriding Devise's Devise::RegistrationsController#create
method. This is where a new unconfirmed account is created.
class RegistrationsController < Devise::RegistrationsController
def create
super do |resource|
if resource.persisted?
session[:unconfirmed_account] = resource.id
end
end
end
end
The information about how to customize Devise
controllers can be found here https://www.rubydoc.info/github/plataformatec/devise#Configuring_controllers
Once the user has confirmed the email and is authenticated, the session variable should be deleted.
class ConfirmationsController < Devise::ConfirmationsController
def show
super do |resource|
if resource.errors.empty?
session.delete(:unconfirmed_account)
end
end
end
end
When the user updates the unconfirmed email, the account should be updated and a new confirmation message should be sent to the new email address. This is for you to implement )
What you could do is,
For example,
if the user is sent a confirmation mail with a link, and he clicks on the link, at this point you could have a status column which would change the status to pending
.
Now, you could allow the users to change their email until the status of their account remain pending
. At this point, if the user wants to go back and change his email, he will and receive a confirmation mail with a link.
Let's assume we have a approved
status, this will change from pending
to approved
only after he signs into the application.
Did this help ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.