1/* 2 * Copyright 2014, Stephan A��mus <superstippi@gmx.de>. 3 * Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6#ifndef USER_LOGIN_WINDOW_H 7#define USER_LOGIN_WINDOW_H 8 9#include <Locker.h> 10#include <Messenger.h> 11#include <Window.h> 12 13#include "PackageInfo.h" 14 15 16class BButton; 17class BCheckBox; 18class BMenuField; 19class BTabView; 20class BTextControl; 21class BitmapView; 22class LinkView; 23class Model; 24class UserUsageConditions; 25 26 27class UserLoginWindow : public BWindow { 28public: 29 UserLoginWindow(BWindow* parent, BRect frame, 30 Model& model); 31 virtual ~UserLoginWindow(); 32 33 virtual void MessageReceived(BMessage* message); 34 35 void SetOnSuccessMessage( 36 const BMessenger& messenger, 37 const BMessage& message); 38 39private: 40 41 enum Mode { 42 NONE = 0, 43 LOGIN, 44 CREATE_ACCOUNT 45 }; 46 47 void _SetMode(Mode mode); 48 bool _ValidateCreateAccountFields( 49 bool alertProblems = false); 50 void _Login(); 51 void _CreateAccount(); 52 void _CreateAccountSetup(uint32 mask); 53 void _CreateAccountSetupIfNecessary(); 54 void _LoginSuccessful(const BString& message); 55 56 void _SetWorkerThread(thread_id thread); 57 58 static int32 _AuthenticateThreadEntry(void* data); 59 void _AuthenticateThread(); 60 61 static int32 _CreateAccountSetupThreadEntry(void* data); 62 void _CreateAccountCaptchaSetupThread(); 63 void _CreateAccountUserUsageConditionsSetupThread(); 64 65 void _SetUserUsageConditions( 66 UserUsageConditions* userUsageConditions); 67 68 static int32 _CreateAccountThreadEntry(void* data); 69 void _CreateAccountThread(); 70 71 void _CollectValidationFailures( 72 const BMessage& result, 73 BString& error) const; 74 75 void _ViewUserUsageConditions(); 76 77private: 78 BMessenger fOnSuccessTarget; 79 BMessage fOnSuccessMessage; 80 81 BTabView* fTabView; 82 83 BTextControl* fUsernameField; 84 BTextControl* fPasswordField; 85 86 BTextControl* fNewUsernameField; 87 BTextControl* fNewPasswordField; 88 BTextControl* fRepeatPasswordField; 89 BTextControl* fEmailField; 90 BMenuField* fLanguageCodeField; 91 BitmapView* fCaptchaView; 92 BTextControl* fCaptchaResultField; 93 BCheckBox* fConfirmMinimumAgeCheckBox; 94 BCheckBox* fConfirmUserUsageConditionsCheckBox; 95 LinkView* fUserUsageConditionsLink; 96 97 BButton* fSendButton; 98 BButton* fCancelButton; 99 100 BString fCaptchaToken; 101 BitmapRef fCaptchaImage; 102 BString fPreferredLanguageCode; 103 104 Model& fModel; 105 106 Mode fMode; 107 108 UserUsageConditions* 109 fUserUsageConditions; 110 111 BLocker fLock; 112 thread_id fWorkerThread; 113}; 114 115 116#endif // USER_LOGIN_WINDOW_H 117