Login : how to set "Remember me" checked by default ?
Added by Hyeoni Hwasoo over 11 years ago
In the login page, is it possible to put by default the checkbox 'Remember me' in the checked state instead of the unchecked state?
I didn't found the appropriate method in the Wt::Auth::AuthWidget class or another.
Is it possible to do that with the auth_bootstrap_theme.xml file?
Replies (6)
RE: Login : how to set "Remember me" checked by default ? - Added by Koen Deforche over 11 years ago
Hey,
You should set a true value in the AuthModel that is used by the AuthWidget:
model->setValue(AuthModel::RememberMeField, true);
Regards,
koen
RE: Login : how to set "Remember me" checked by default ? - Added by Hyeoni Hwasoo over 11 years ago
Thank you very much for your answer but actually, even if it compiles unfortunately it does not work. No error in the console log.
Here is the code I wrote from the example and your code :
Wt::Auth::AuthWidget *authWidget = new Wt::Auth::AuthWidget(Session::auth(), session.users(), session.login());
root()->addWidget(authWidget);
authWidget->model()->addPasswordAuth(&Session::passwordAuth());
authWidget->model()->setValue(Wt::Auth::AuthModel::RememberMeField, true);
authWidget->setRegistrationEnabled(false);
authWidget->processEnvironment();
Regards,
Hyeon
RE: Login : how to set "Remember me" checked by default ? - Added by Hyeoni Hwasoo over 11 years ago
Maybe I did a mistake ?
Regards,
Hyeon
RE: Login : how to set "Remember me" checked by default ? - Added by Koen Deforche over 11 years ago
Hey,
My mistake, I'm afraid. You'll need to specialize the AuthModel and specialize its reset() function to (in addition to the base function) set the value to true.
To be honest, that really should be easier to do.
Regards,
koen
[Solved] RE: Login : how to set "Remember me" checked by default ? - Added by Hyeoni Hwasoo over 11 years ago
Sorry for the delay
Thanks a lot, this solution works perfectly (even if I don't know if some arguments are redundant or if it is the optimal code) :
class SpecializedAuthModel : public Wt::Auth::AuthModel
{
public:
SpecializedAuthModel (const Wt::Auth::AuthService &baseAuth, Wt::Auth::AbstractUserDatabase &users, Wt::WObject* parent=0)
: Wt::Auth::AuthModel(baseAuth, users, parent)
{
}
virtual void reset()
{
Wt::Auth::AuthModel::reset();
this->setValue(AuthModel::RememberMeField, true);
}
};
SpecializedAuthModel *authModel = new SpecializedAuthModel(Session::auth(), session.users(), root());
Wt::Auth::AuthWidget *authWidget = new Wt::Auth::AuthWidget(Session::auth(), session.users(), session.login());
authWidget->setModel(authModel);
RE: Login : how to set "Remember me" checked by default ? - Added by Koen Deforche over 11 years ago
Hey,
That's exactly what I had in mind!
Regards,
koen