0

In my current application I have a special case, where I want to redirect the user to the resend-confirmation page, when he/she tries to log in with an unconfirmed account.

By default devise flashes a notification.

I haven't found any instructions on how to do this. If there is a way to achieve this? I would love to hear about it.

heroxav
  • 1,387
  • 1
  • 22
  • 65

1 Answers1

1

you can take a look on this post ... maybe it can help to get some idea https://stackoverflow.com/a/19433891/3276347

Community
  • 1
  • 1
Mahabub Islam Prio
  • 1,075
  • 11
  • 25
  • Thank you, that helped me out tremendously! – heroxav Jan 22 '17 at 10:05
  • One question: How can I find the User when he can login with username or email? So you get `:login` as parameter, which can be the users email or username. – heroxav Jan 22 '17 at 10:34
  • Maybe I did not understand your question. But Devise has a method for it . Maybe its `current_user` for a user who is currently signed in . And there is `user_signed_in?` which returns boolean value for a user if he/she is signed in or not. You may take a look here https://github.com/plataformatec/devise#controller-filters-and-helpers – Mahabub Islam Prio Jan 22 '17 at 10:38
  • In the answer you linked the user gets accessed via `user = User.find_by_email(params[:email])`. That doesn't work for me because I allow users to login via username or email -> https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address Because of that everytime someone tries to log in he gets redirected to the `new_confirmation_path` – heroxav Jan 22 '17 at 10:45
  • Okay , Lets walkthrough the process , You create a field in `User` with `string :username` and when they register you still do have these data in session ( while you are redirected to the confirmation page ) . This means you can access the session of devise and username data. then you can still get email confirmed . Which can trigger a boolean value in table like ':status' field. So, you got some idea ... right ?? Did I understand you properly ?? – Mahabub Islam Prio Jan 22 '17 at 10:53
  • This is what I currently do: `user = User.find_by(email: params[:login]) || User.find_by(username: params[:login]) redirect_to new_user_confirmation_path(q: "unconfirmed") unless user && user.confirmed?` – heroxav Jan 22 '17 at 10:55
  • I dont know man, But I would have thought in this way `user = User.find(by_some_param) if user_signed_in? and user already confirmed redirect to user_profile else somewhere else end` :) – Mahabub Islam Prio Jan 22 '17 at 11:01
  • I ended up using a different approach, thank you for your help. – heroxav Jan 22 '17 at 21:40