I came across this google group message that was asking if it was possible to turn the remember me functionality on by default, so you won't have to check a checkbox.
That was exactly what I was looking for so I was wondering if you are still open for a patch that makes this configurable? And if so, do you have any notes before I start working on it? :-)
No, we don't have this feature yet and yes, a patch sounds fine. :)
There's always a ProTip:
f.input :remember_me, :as => :hidden, :value => true
:D
Very true, but as the google group posting says ;)
but then it wouldn't work with other auth methods
True, I was mostly making a funny :P This is very desirable so I can remove the above in my project(s) ;)
I've only had time to take a quick glance at the code and here is what I came up with.
The remember_me method in Authenticatable could be extended to also check for a remember always setting.
This function only gets checked if rememberable is included so it should be a small addition.
Would this be the right way to go? And would this cover every case, like logging in from a token?
Hrm, the problem is this code is triggered only when signing in through strategies. For example, when using omniauth, you can sign_in manually and that code isn't executed. Maybe we could achieve something better in the hook:
https://github.com/plataformatec/devise/blob/master/lib/devise/hooks/rememberable.rb
Look it already checks model.remember_me. So a very easy way to have always remember_me is to just set def remember_me; true; end in your model. However, there are some specific cases we explicitly do not allow remember_me, like token authentication. What is your case? Do you also want automatic remember me for token authentication as well?
My specific case is very simple, and would be solved with setting model.remember_me. I want it to be enabled at all times for a simple login form.
So I guess this is case closed? :D
Haha, yes, for me it could be considered closed and might be even better than making yet another configuration option. I'm not sure if there are use cases where people would still want it though.
There is a better solution:
def remember_me
(super == nil) ? '1' : super
end
this case you'll get remember_me enabled by default, otherwise, you'll get a user choise
+1 to asiniy's solution. After testing many alternatives and none of them working this one works like a charm.
@asiniy , where you would put that function?
@hunainkapadia you put that function in your resource (usually 'User') model.
Most helpful comment
There is a better solution:
this case you'll get remember_me enabled by default, otherwise, you'll get a user choise