diff --git a/src/apps/haikudepot/Model.cpp b/src/apps/haikudepot/Model.cpp index d83245600f..03473597b0 100644 --- a/src/apps/haikudepot/Model.cpp +++ b/src/apps/haikudepot/Model.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,9 @@ #define B_TRANSLATION_CONTEXT "Model" +static const char* kHaikuDepotKeyring = "HaikuDepot"; + + // #pragma mark - PackageFilters @@ -639,8 +643,28 @@ Model::StopPopulatingAllPackages() void -Model::SetAuthorization(const BString& username, const BString& password) +Model::SetUser(const BString& username) { + BPasswordKey key; + BKeyStore keyStore; + if (keyStore.GetKey(kHaikuDepotKeyring, B_KEY_TYPE_PASSWORD, username, + key) == B_OK) { + SetAuthorization(username, key.Password(), false); + } +} + + +void +Model::SetAuthorization(const BString& username, const BString& password, + bool storePassword) +{ + if (storePassword) { + BPasswordKey key(password, B_KEY_PURPOSE_WEB, username); + BKeyStore keyStore; + keyStore.AddKeyring(kHaikuDepotKeyring); + keyStore.AddKey(kHaikuDepotKeyring, key); + } + BAutolock locker(&fLock); fWebAppInterface.SetAuthorization(username, password); } diff --git a/src/apps/haikudepot/Model.h b/src/apps/haikudepot/Model.h index c968c1c7a4..487049c9ee 100644 --- a/src/apps/haikudepot/Model.h +++ b/src/apps/haikudepot/Model.h @@ -107,8 +107,10 @@ public: const BString& PreferredLanguage() const { return fPreferredLanguage; } + void SetUser(const BString& username); void SetAuthorization(const BString& username, - const BString& password); + const BString& password, + bool storePassword); private: static int32 _PopulateAllPackagesEntry(void* cookie); @@ -172,6 +174,7 @@ private: thread_id fPopulateAllPackagesThread; volatile bool fStopPopulatingAllPackages; + BString fPreferredLanguage; WebAppInterface fWebAppInterface; diff --git a/src/apps/haikudepot/UserLoginWindow.cpp b/src/apps/haikudepot/UserLoginWindow.cpp index 0a525cabba..bb47b532fb 100644 --- a/src/apps/haikudepot/UserLoginWindow.cpp +++ b/src/apps/haikudepot/UserLoginWindow.cpp @@ -346,7 +346,7 @@ UserLoginWindow::_AuthenticateThread() // the Token Bearer. See section 5.1.2 in the haiku-depot-web // documentation. error = ""; - fModel.SetAuthorization(nickName, passwordClear); + fModel.SetAuthorization(nickName, passwordClear, true); } else { error = B_TRANSLATE("Authentication failed. The user does " "not exist or the wrong password was supplied."); @@ -508,7 +508,7 @@ UserLoginWindow::_CreateAccountThread() fCaptchaToken = ""; _RequestCaptcha(); } else { - fModel.SetAuthorization(nickName, passwordClear); + fModel.SetAuthorization(nickName, passwordClear, true); _SetWorkerThread(-1); BMessenger(this).SendMessage(B_QUIT_REQUESTED);