开发者

rails 3 + devise: on after_inactive_sign_up_path_for() how show the not-yet-confirmed user's email address?

开发者 https://www.devze.com 2023-03-09 14:25 出处:网络
In order to have a post-registration page, I added a RegistrationsController and method to provide a custom page to tell the user to check their email for the account confirmation link.

In order to have a post-registration page, I added a RegistrationsController and method to provide a custom page to tell the user to check their email for the account confirmation link.

  def after_inactive_sign_up_path_for(resource)
    "/awaiting_confirmation"
  end

Is there any way on that page (which is seen by a user who has created an account, but not confirmed it, and not signed in yet) to show the email address they used to create the account.

I'd like the page to say "we just sent a confirmation link to you at useremail@userdomain.com"

But the view for that page cannot display current_user.email because current_user 开发者_如何学Gois nil because they have not signed in.

Is there some other devise variable, or session variable, that would contain the registration info that was just created?


here's how we solved it ... it was easy.

modified the one-line controller method in my custom registration controller (shown in my question) to:

"/awaiting_confirmation?email=#{resource.email}"

then in the receiving method for the route /awaiting_confirmation I simply do

@email = params[:email]

and display the @email variable in my view.


You can do this two ways, the first is to display a flash message to the user after the email is successfully sent. You still have access to the users email in a variable there so something like:

:notice => "Email was sent to #{userobject.email}"

Or you could pass this object into the page that you are sending the user to after a signup and using it there.

Another way you could tackle this would be to authenticate the user with a token and then the user would be effectively signed in and you could then use current_user. For that you would want to look into single use token authentication and devise.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号