From 87a11914f8383a1153e317c3b8579281d1fa1e71 Mon Sep 17 00:00:00 2001 From: luocai Date: Fri, 8 Nov 2024 20:25:31 +0800 Subject: [PATCH] add code. --- WebApplication/model/BlogUserDatabase.cpp | 19 ++++++++++--------- WebApplication/model/BlogUserDatabase.h | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/WebApplication/model/BlogUserDatabase.cpp b/WebApplication/model/BlogUserDatabase.cpp index 73d4f8d..91e2cf0 100644 --- a/WebApplication/model/BlogUserDatabase.cpp +++ b/WebApplication/model/BlogUserDatabase.cpp @@ -61,11 +61,7 @@ Wt::Auth::User BlogUserDatabase::findWithIdentity(const std::string &provider, c if (provider == Wt::Auth::Identity::LoginName) { if (!m_user || m_user->name != identity) m_user = m_session.find().where("name = ?").bind(identity); } else - m_user = m_session.find() - .where("oauth_id = ?") - .bind(identity.toUTF8()) - .where("oauth_provider = ?") - .bind(provider); + m_user = m_session.find().where("oauth_id = ?").bind(identity.toUTF8()).where("oauth_provider = ?").bind(provider); t.commit(); if (m_user) @@ -74,8 +70,7 @@ Wt::Auth::User BlogUserDatabase::findWithIdentity(const std::string &provider, c return Wt::Auth::User(); } -void BlogUserDatabase::addIdentity(const Wt::Auth::User &user, const std::string &provider, - const Wt::WString &identity) { +void BlogUserDatabase::addIdentity(const Wt::Auth::User &user, const std::string &provider, const Wt::WString &identity) { WithUser find(*this, user); if (provider == Wt::Auth::Identity::LoginName) @@ -119,8 +114,14 @@ Wt::Auth::PasswordHash BlogUserDatabase::password(const Wt::Auth::User &user) co return Wt::Auth::PasswordHash(m_user->passwordMethod, m_user->passwordSalt, m_user->password); } -BlogUserDatabase::WithUser::WithUser(const BlogUserDatabase &self, const Wt::Auth::User &user) - : transaction(self.m_session) { +void BlogUserDatabase::setPassword(const Wt::Auth::User &user, const Wt::Auth::PasswordHash &password) { + WithUser find(*this, user); + m_user.modify()->password = password.value(); + m_user.modify()->passwordMethod = password.function(); + m_user.modify()->passwordSalt = password.salt(); +} + +BlogUserDatabase::WithUser::WithUser(const BlogUserDatabase &self, const Wt::Auth::User &user) : transaction(self.m_session) { self.getUser(user.id()); if (!self.m_user) throw InvalidUser(user.id()); diff --git a/WebApplication/model/BlogUserDatabase.h b/WebApplication/model/BlogUserDatabase.h index 5ce3b1c..46c4c47 100644 --- a/WebApplication/model/BlogUserDatabase.h +++ b/WebApplication/model/BlogUserDatabase.h @@ -22,6 +22,7 @@ public: Wt::WString identity(const Wt::Auth::User &user, const std::string &provider) const final; void setLastLoginAttempt(const Wt::Auth::User &user, const Wt::WDateTime &t) final; Wt::Auth::PasswordHash password(const Wt::Auth::User &user) const final; + void setPassword(const Wt::Auth::User &user, const Wt::Auth::PasswordHash &password) final; protected: struct WithUser {