Wt::Auth::Dbo::UserDatabase link with custom user table
Added by Thomas Saquet 9 months ago
Hello,
I spent a lot of time understanding the link between the table "auth_info" and the custom user table needed for an application. Maybe I missed something important and in that case I would be pleased to understand, otherwise I came up with the conclusion that Wt/Auth/Dbo/UserDatabase could be improved to provide the link by adding a second class to the template, something like
template <class DboType, class CustomUser>
class UserDatabase : public Wt::Auth::AbstractUserDatabase
{
[...]
}
and a small change in the registerNew method :
virtual User registerNew()
{
DboType *user = new DboType();
CustomUser *customUser = new CustomUser(); // creating the custom user
user->setUser(session_.add(customUser)); // adding it to the session to get its pointer and pass it to the setUser method
setUser(session_.add(user));
user_.flush();
return User(boost::lexical_cast<std::string > (user_.id()), *this);
}
It allows someone to directly use your implementation within his registration widget, using the registerUserDetails method which seems made in that purpose, with something like that :
void RegistrationWidget::registerUserDetails(User& user)
{
dynamic_cast<UserDatabase*>(user.database())->find(user).get()->user().modify()->customField = valueYouAddedToTheModel;
}
Does that make sense ?
Thank you !
Thomas
Replies (1)
RE: Wt::Auth::Dbo::UserDatabase link with custom user table - Added by Kevin Robertson 9 months ago
That makes since to me, Thomas. I'll try it out in the application I'm developing. Thanks!
(1-1/1)