Devise: Authentication after Registration without Confirmable - ruby-on-rails

Use case: User fills out a form to add a product and register at once. When the user has submitted the combined form, the app authenticates the user and is logged in (assume validations passed) without the need to confirm or login.
I've removed the confirmable feature out, but when the user fill out the form, it succeeds, but the user doesn't get logged in unless they go to a login form. This isn't such a great experience, so is there a way to Register a user and immediately log them in?

What I actually wanted was sign_in(#user) from my controller

If you want to login without confirmation then Remove :confirmable option from devise options in User model.

Related

progressive engagement with devise in rails 4

I'm trying to implement a functionality that would allow guests to submit booking forms and then be redirected to sign-in or subscribe in order to save it. Superprof.co.uk has the same functionality so here's what I mean:
As a guest (a user who isn't signed in) can click on "book a course" in what would be the "course#show" page in rails
He is then redirected to fill the booking form (even if he isn't signed in)
When he submits the form he is asked to subscribe or sign-in.
Is there a way to do something similar with devise? How can I keep the booking information and save it only after the user signs in ? Thanks in advance for your answers
A simple approach would be to save booking information to session[:booking]. Then overwrite devise controller and after sign up or sign in check if session[:booking] is set and if so create booking records in DB.
A more correct but also a more complicated approach would be to use guest user. You can check guest user record railscast for more information about that.

Confirm (as an admin) a User created with Devise

I am using Devise and since my app is in Beta, I want to control which users who have signed up can sign in.
So, even if the confirmation email is sent, how can I make it so that just when an admin has confirmed the account they will be able to sign in? Is there any module in Devise that would let me do so?
All you need to do is add an "approved" attribute to your user table, use admin to change its status and before sign in you can check whether user is approved or not. You can find detailed information here: link

devise how to prevent a user from login in if account has not been activated

I have a simple rails application that uses devise authentication and I want to prevent a user from login in or requesting for password request or any thing that can grant access to a registered user.
In my user model I have a boolean field that helps me easily determine if the account has been activated or not, the boolean field is called active.
What call back methods can I use to go around this and to check if the user has been activated of not with devise. Thanks
If you mean how you can set your active boolean after a confirmation email, you can override the confirm! method devise gives.
If you need a method to prevent a non active user to login etc., override the new method in the SessionsController.

devise remember_me value

I am using devise in my application. When a user goes to my website, if i know that the user had previously visited my website and checked 'Remember Me' while logging in, I want to show ihm a special message. How I do get this remember me value from devise in my view? Thanks.
If you have a saved user and wants to know whereas he clicked on the remember_me use the field:
#user.remember_created_at
If you have a instantiated user in your controller after the form submission, you can access the value using:
#user.remember_me
remember_me is a attr_accessor in Devise gem, see here. Which means it will not be persisted when saving you user's instance.

Rails: Make all users change their passwords within Devise?

Is there a way to ask all users to change their passwords upon
logging into a Rails application using Devise authentication? In other words, I'd like a way to "expire" a password, so that the next time a user signs in, they have to change it.
I don't think that Devise can do that out of the box, but i guess it's pretty to do it yourself. What i would do :
Upon user sign in, i would nil out the encrypted_password field of the database.
I would have overriden devise's session controller (responsible for the logins), in order to check whether encrypted_password of a user that tries to log in is nil.
If that was nil, i would redirect them to login, also flashing an error like "Your password has expired. Please create a new one."

Resources