hrev47902 adds 2 changesets to branch 'master' old head: 84e6fa8e2a9d84a2fe7bc6c7657093c6df71ebb1 new head: 12f29d444100195f19d79613cae76cdea1c2aacb overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=12f29d4+%5E84e6fa8 ---------------------------------------------------------------------------- 89ec84a: HaikuDepot: Some usage of the BKeyStore API ... completely untested and premature. The idea is that after a successful login with the web-app, the password used is stored in the keyring. Then HaikuDepot will restore just last the used username on next launch and retrieve the password from the keyring. One could also register multiple accounts in HaikuDepot and switch between them. 12f29d4: HaikuDepot: Force preferred language to be supported At the moment, the web-app has a defined, limited set of supported languages for translations. JSON requests fail when asking for an unsupported language code. For the time being, force the language code to be in the supported set. [ Stephan Aßmus <superstippi@xxxxxx> ] ---------------------------------------------------------------------------- 3 files changed, 39 insertions(+), 4 deletions(-) src/apps/haikudepot/Model.cpp | 34 ++++++++++++++++++++++++++++- src/apps/haikudepot/Model.h | 5 ++++- src/apps/haikudepot/UserLoginWindow.cpp | 4 ++-- ############################################################################ Commit: 89ec84a4cb5f8fea4214c6feaf6eafe2685295b5 URL: http://cgit.haiku-os.org/haiku/commit/?id=89ec84a Author: Stephan Aßmus <superstippi@xxxxxx> Date: Wed Sep 24 19:16:27 2014 UTC HaikuDepot: Some usage of the BKeyStore API ... completely untested and premature. The idea is that after a successful login with the web-app, the password used is stored in the keyring. Then HaikuDepot will restore just last the used username on next launch and retrieve the password from the keyring. One could also register multiple accounts in HaikuDepot and switch between them. ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/Model.cpp b/src/apps/haikudepot/Model.cpp index d832456..0347359 100644 --- a/src/apps/haikudepot/Model.cpp +++ b/src/apps/haikudepot/Model.cpp @@ -17,6 +17,7 @@ #include <Entry.h> #include <FindDirectory.h> #include <File.h> +#include <KeyStore.h> #include <LocaleRoster.h> #include <Message.h> #include <Path.h> @@ -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 c968c1c..487049c 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 0a525ca..bb47b53 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); ############################################################################ Revision: hrev47902 Commit: 12f29d444100195f19d79613cae76cdea1c2aacb URL: http://cgit.haiku-os.org/haiku/commit/?id=12f29d4 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Wed Sep 24 19:24:41 2014 UTC HaikuDepot: Force preferred language to be supported At the moment, the web-app has a defined, limited set of supported languages for translations. JSON requests fail when asking for an unsupported language code. For the time being, force the language code to be in the supported set. ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/Model.cpp b/src/apps/haikudepot/Model.cpp index 0347359..ce00590 100644 --- a/src/apps/haikudepot/Model.cpp +++ b/src/apps/haikudepot/Model.cpp @@ -340,6 +340,14 @@ Model::Model() language.CopyInto(fPreferredLanguage, 0, 2); } } + if (fPreferredLanguage != "en" && fPreferredLanguage != "de" + && fPreferredLanguage != "fr" && fPreferredLanguage != "ja" + && fPreferredLanguage != "es" && fPreferredLanguage != "zh" + && fPreferredLanguage != "pt" && fPreferredLanguage != "ru") { + // Force the preferred language to one of the currently supported + // ones, until the web application supports all ISO language codes. + fPreferredLanguage = "en"; + } fWebAppInterface.SetPreferredLanguage(fPreferredLanguage); }