devise remember_me value - ruby-on-rails

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.

Related

How to conditionally ignore that a user is not confirmed in Rails, Devise?

Basically what I have is that a user is created upon a booking (from their booking details), but they have to tick an option to actually have an account on the website. The latter type of user needs confirmation of email, but the previous - does not.
How do I ignore that a user is not confirmed dynamically based on some model attribute?
You can use skip_confirmation_notification! from the Confirmable module.
This would create the user but wouldn't send them a confirmation email. It would still require being confirmed for the user to become a devise user, but you can still retrieve the user using either the user.confirmation_token which would eq a unique token (NULL for confirmed users), or the user.confirmed_at would be NULL for non confirms, as a date is added when confirmed.

How to log in with e-mail or username on one login form?

How would one who has multiple user models with Devise log in with either username or email to one login form with Devise then redirect to a custom page?
I'm able to get the username/e-mail login to work and be redirected to their own custom page but my problem is with the unified log in.
This is probably duplicate of this.
You could add this method to your user model
def self.find_for_database_authentication(conditions={})
find_by(username: conditions[:email]) || find_by(email: conditions[:email])
end
or you could see how to allow users sign in using their username or email address from the Devise wiki

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: Authentication after Registration without Confirmable

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.

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