104c9d578SStephan Aßmus /* 204c9d578SStephan Aßmus * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3*bf866d5eSAndrew Lindesay * Copyright 2019-2024, Andrew Lindesay <apl@lindesay.co.nz>. 404c9d578SStephan Aßmus * All rights reserved. Distributed under the terms of the MIT License. 504c9d578SStephan Aßmus */ 604c9d578SStephan Aßmus #ifndef USER_LOGIN_WINDOW_H 704c9d578SStephan Aßmus #define USER_LOGIN_WINDOW_H 804c9d578SStephan Aßmus 904c9d578SStephan Aßmus #include <Locker.h> 101bbda92dSStephan Aßmus #include <Messenger.h> 1104c9d578SStephan Aßmus #include <Window.h> 1204c9d578SStephan Aßmus 13835e7239SAndrew Lindesay #include "CreateUserDetail.h" 1404c9d578SStephan Aßmus #include "PackageInfo.h" 15b6356b91SAndrew Lindesay #include "PasswordRequirements.h" 16835e7239SAndrew Lindesay #include "UserCredentials.h" 17835e7239SAndrew Lindesay #include "ValidationFailure.h" 1804c9d578SStephan Aßmus 1904c9d578SStephan Aßmus 2004c9d578SStephan Aßmus class BButton; 210c82f64bSAndrew Lindesay class BCheckBox; 223e3d0effSStephan Aßmus class BMenuField; 2304c9d578SStephan Aßmus class BTabView; 2404c9d578SStephan Aßmus class BTextControl; 2504c9d578SStephan Aßmus class BitmapView; 26835e7239SAndrew Lindesay class Captcha; 270c82f64bSAndrew Lindesay class LinkView; 2804c9d578SStephan Aßmus class Model; 290c82f64bSAndrew Lindesay class UserUsageConditions; 3004c9d578SStephan Aßmus 3104c9d578SStephan Aßmus 3204c9d578SStephan Aßmus class UserLoginWindow : public BWindow { 3304c9d578SStephan Aßmus public: 3404c9d578SStephan Aßmus UserLoginWindow(BWindow* parent, BRect frame, 3504c9d578SStephan Aßmus Model& model); 3604c9d578SStephan Aßmus virtual ~UserLoginWindow(); 3704c9d578SStephan Aßmus 38835e7239SAndrew Lindesay virtual bool QuitRequested(); 3904c9d578SStephan Aßmus virtual void MessageReceived(BMessage* message); 4004c9d578SStephan Aßmus 411bbda92dSStephan Aßmus void SetOnSuccessMessage( 421bbda92dSStephan Aßmus const BMessenger& messenger, 431bbda92dSStephan Aßmus const BMessage& message); 441bbda92dSStephan Aßmus 4504c9d578SStephan Aßmus private: 460c82f64bSAndrew Lindesay 4704c9d578SStephan Aßmus enum Mode { 4804c9d578SStephan Aßmus NONE = 0, 4904c9d578SStephan Aßmus LOGIN, 5004c9d578SStephan Aßmus CREATE_ACCOUNT 5104c9d578SStephan Aßmus }; 5204c9d578SStephan Aßmus 5304c9d578SStephan Aßmus void _SetMode(Mode mode); 54835e7239SAndrew Lindesay void _SetWorkerThread(thread_id thread); 55835e7239SAndrew Lindesay void _SetWorkerThreadLocked(thread_id thread); 56835e7239SAndrew Lindesay 57835e7239SAndrew Lindesay void _Authenticate(); 58835e7239SAndrew Lindesay void _Authenticate( 59835e7239SAndrew Lindesay const UserCredentials& credentials); 60835e7239SAndrew Lindesay static int32 _AuthenticateThreadEntry(void* data); 61835e7239SAndrew Lindesay void _AuthenticateThread( 62835e7239SAndrew Lindesay UserCredentials& credentials); 63835e7239SAndrew Lindesay void _UnpackAuthenticationToken( 64835e7239SAndrew Lindesay BMessage& responsePayload, BString& token); 65835e7239SAndrew Lindesay void _HandleAuthenticationFailed(); 66835e7239SAndrew Lindesay void _HandleAuthenticationSuccess( 67835e7239SAndrew Lindesay const UserCredentials & credentials); 68835e7239SAndrew Lindesay void _HandleAuthenticationError(); 69835e7239SAndrew Lindesay 7004c9d578SStephan Aßmus void _CreateAccount(); 71835e7239SAndrew Lindesay void _AssembleCreateUserDetail( 72835e7239SAndrew Lindesay CreateUserDetail& detail); 73835e7239SAndrew Lindesay void _ValidateCreateUserDetail( 74835e7239SAndrew Lindesay CreateUserDetail& detail, 75835e7239SAndrew Lindesay ValidationFailures& failures); 76835e7239SAndrew Lindesay void _AlertCreateUserValidationFailure( 77835e7239SAndrew Lindesay const ValidationFailures& failures); 78835e7239SAndrew Lindesay static BString _CreateAlertTextFromValidationFailure( 79835e7239SAndrew Lindesay const BString& property, 80835e7239SAndrew Lindesay const BString& message); 81835e7239SAndrew Lindesay void _MarkCreateUserInvalidFields(); 82835e7239SAndrew Lindesay void _MarkCreateUserInvalidFields( 83835e7239SAndrew Lindesay const ValidationFailures& failures); 84835e7239SAndrew Lindesay static int32 _CreateAccountThreadEntry(void* data); 85835e7239SAndrew Lindesay void _CreateAccountThread(CreateUserDetail* detail); 86835e7239SAndrew Lindesay void _HandleCreateAccountSuccess( 87835e7239SAndrew Lindesay const UserCredentials& credentials); 88835e7239SAndrew Lindesay void _HandleCreateAccountFailure( 89835e7239SAndrew Lindesay const ValidationFailures& failures); 90835e7239SAndrew Lindesay void _HandleCreateAccountError(); 91835e7239SAndrew Lindesay 920c82f64bSAndrew Lindesay void _CreateAccountSetup(uint32 mask); 930c82f64bSAndrew Lindesay void _CreateAccountSetupIfNecessary(); 940c82f64bSAndrew Lindesay static int32 _CreateAccountSetupThreadEntry(void* data); 95835e7239SAndrew Lindesay status_t _CreateAccountCaptchaSetupThread( 96835e7239SAndrew Lindesay Captcha& captcha); 97835e7239SAndrew Lindesay status_t _CreateAccountUserUsageConditionsSetupThread( 98835e7239SAndrew Lindesay UserUsageConditions& userUsageConditions); 99b6356b91SAndrew Lindesay status_t _CreateAccountPasswordRequirementsSetupThread( 100b6356b91SAndrew Lindesay PasswordRequirements& passwordRequirements); 101835e7239SAndrew Lindesay status_t _UnpackCaptcha(BMessage& responsePayload, 102835e7239SAndrew Lindesay Captcha& captcha); 103835e7239SAndrew Lindesay void _HandleCreateAccountSetupSuccess( 104835e7239SAndrew Lindesay BMessage* message); 1050c82f64bSAndrew Lindesay 106835e7239SAndrew Lindesay void _SetCaptcha(Captcha* captcha); 1070c82f64bSAndrew Lindesay void _SetUserUsageConditions( 1080c82f64bSAndrew Lindesay UserUsageConditions* userUsageConditions); 109b6356b91SAndrew Lindesay void _SetPasswordRequirements( 110b6356b91SAndrew Lindesay PasswordRequirements* passwordRequirements); 11104c9d578SStephan Aßmus 11204c9d578SStephan Aßmus void _CollectValidationFailures( 11304c9d578SStephan Aßmus const BMessage& result, 11404c9d578SStephan Aßmus BString& error) const; 11504c9d578SStephan Aßmus 1160c82f64bSAndrew Lindesay void _ViewUserUsageConditions(); 117b6356b91SAndrew Lindesay void _ViewPasswordRequirements(); 1180c82f64bSAndrew Lindesay 119835e7239SAndrew Lindesay void _TakeUpCredentialsAndQuit( 120835e7239SAndrew Lindesay const UserCredentials& credentials); 121835e7239SAndrew Lindesay 122835e7239SAndrew Lindesay void _EnableMutableControls(bool enabled); 123835e7239SAndrew Lindesay 124835e7239SAndrew Lindesay static void _ValidationFailuresToString( 125835e7239SAndrew Lindesay const ValidationFailures& failures, 126835e7239SAndrew Lindesay BString& output); 127835e7239SAndrew Lindesay 12804c9d578SStephan Aßmus private: 1291bbda92dSStephan Aßmus BMessenger fOnSuccessTarget; 1301bbda92dSStephan Aßmus BMessage fOnSuccessMessage; 1311bbda92dSStephan Aßmus 13204c9d578SStephan Aßmus BTabView* fTabView; 13304c9d578SStephan Aßmus 134835e7239SAndrew Lindesay BTextControl* fNicknameField; 13504c9d578SStephan Aßmus BTextControl* fPasswordField; 13604c9d578SStephan Aßmus 137835e7239SAndrew Lindesay BTextControl* fNewNicknameField; 13804c9d578SStephan Aßmus BTextControl* fNewPasswordField; 13904c9d578SStephan Aßmus BTextControl* fRepeatPasswordField; 140b6356b91SAndrew Lindesay LinkView* fPasswordRequirementsLink; 14104c9d578SStephan Aßmus BTextControl* fEmailField; 142*bf866d5eSAndrew Lindesay BMenuField* fLanguageIdField; 14304c9d578SStephan Aßmus BitmapView* fCaptchaView; 14404c9d578SStephan Aßmus BTextControl* fCaptchaResultField; 1450c82f64bSAndrew Lindesay BCheckBox* fConfirmMinimumAgeCheckBox; 1460c82f64bSAndrew Lindesay BCheckBox* fConfirmUserUsageConditionsCheckBox; 1470c82f64bSAndrew Lindesay LinkView* fUserUsageConditionsLink; 14804c9d578SStephan Aßmus 14904c9d578SStephan Aßmus BButton* fSendButton; 15004c9d578SStephan Aßmus BButton* fCancelButton; 15104c9d578SStephan Aßmus 152b6356b91SAndrew Lindesay PasswordRequirements* 153b6356b91SAndrew Lindesay fPasswordRequirements; 154835e7239SAndrew Lindesay UserUsageConditions* 155835e7239SAndrew Lindesay fUserUsageConditions; 156835e7239SAndrew Lindesay Captcha* fCaptcha; 157*bf866d5eSAndrew Lindesay BString fPreferredLanguageId; 15804c9d578SStephan Aßmus 15904c9d578SStephan Aßmus Model& fModel; 16004c9d578SStephan Aßmus 16104c9d578SStephan Aßmus Mode fMode; 16204c9d578SStephan Aßmus 16304c9d578SStephan Aßmus BLocker fLock; 16404c9d578SStephan Aßmus thread_id fWorkerThread; 165835e7239SAndrew Lindesay bool fQuitRequestedDuringWorkerThread; 16604c9d578SStephan Aßmus }; 16704c9d578SStephan Aßmus 16804c9d578SStephan Aßmus 16904c9d578SStephan Aßmus #endif // USER_LOGIN_WINDOW_H 170