Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
LoginDialogUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  protected const string USERNAME_WIDGET = "UserName";
5  protected const string PASSWORD_WIDGET = "Password";
6 
7  protected SCR_EditBoxComponent m_UserName;
8  protected SCR_EditBoxComponent m_Password;
9 
10  //------------------------------------------------------------------------------------------------
11  override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
12  {
13  super.OnMenuOpen(preset);
14 
15  // Load credentials
16  string name = GetGame().GetBackendApi().GetCredentialsItem(EBackendCredentials.EBCRED_NAME);
17  m_UserName = SCR_EditBoxComponent.GetEditBoxComponent(USERNAME_WIDGET, m_wRoot);
18  if (m_UserName)
19  {
20  m_UserName.SetValue(name);
21  m_UserName.m_OnChanged.Insert(CheckFilledEditBoxes);
22 
23  GetGame().GetWorkspace().SetFocusedWidget(m_UserName.GetRootWidget());
24  }
25 
26  m_Password = SCR_EditBoxComponent.GetEditBoxComponent(PASSWORD_WIDGET, m_wRoot);
27  if (m_Password)
28  m_Password.m_OnChanged.Insert(CheckFilledEditBoxes);
29 
30  CheckFilledEditBoxes();
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  override void OnConfirm()
35  {
36  if (m_bIsLoading || !m_UserName || !m_Password)
37  return;
38 
39  string user = m_UserName.GetValue().Trim();
40 
41  if (!VerifyFormatting(user))
42  {
43  ShowWarningMessage(true);
44  return;
45  }
46 
47  // Verify credentials
48  GetGame().GetBackendApi().SetCredentialsItem(EBackendCredentials.EBCRED_NAME, user);
49  GetGame().GetBackendApi().SetCredentialsItem(EBackendCredentials.EBCRED_PWD, m_Password.GetValue());
50  GetGame().GetBackendApi().VerifyCredentials(m_Callback, true);
51 
52  super.OnConfirm();
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  override void OnFailDelayed(SCR_BackendCallback callback, int code, int restCode, int apiCode)
57  {
58  if (restCode == SCR_ELoginFailReason.TWO_FACTOR_AUTHENTICATION)
59  {
60  SCR_LoginProcessDialogUI.Create2FADialog(m_UserName.GetValue().Trim(), m_Password.GetValue());
61  Close();
62  }
63  else
64  {
65  super.OnFailDelayed(callback, code, restCode, apiCode);
66  }
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  override void ShowWarningMessage(bool show)
71  {
72  super.ShowWarningMessage(show);
73 
74  if (!show)
75  return;
76 
77  if (m_UserName)
78  m_UserName.OnInvalidInput();
79 
80  if (m_Password)
81  m_Password.OnInvalidInput();
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  // Username must be [email protected] format
86  override bool VerifyFormatting(string text)
87  {
88  // check for spaces and @
89  if (text.IsEmpty() || text.Contains(" ") || !text.Contains("@") || text.LastIndexOf("@") == text.Length() - 1)
90  return false;
91 
92  array<string> substrings = {};
93  text.Split("@", substrings, true);
94 
95  // make sure there's only one @
96  if (substrings.IsEmpty() || substrings.Count() != 2)
97  return false;
98 
99  // check if the domain contains . and it's not the last symbol
100  string domain = substrings[1];
101  if (domain.IsEmpty() || !domain.Contains(".") || domain[0] == "." || domain.LastIndexOf(".") == domain.Length() - 1)
102  return false;
103 
104  // make sure there's no symbols except . in the domain string
105  for (int i = 0; i < domain.Length(); i++)
106  {
107  string char = domain[i];
108 
109  if (char == ".")
110  continue;
111 
112  int ascii = char.ToAscii();
113 
114  bool number = ascii >= 48 && ascii <= 57;
115  bool capLetter = ascii >= 65 && ascii <= 90;
116  bool letter = ascii >= 97 && ascii <= 122;
117 
118  if (!number && !capLetter && !letter)
119  return false;
120  }
121 
122  return super.VerifyFormatting(text);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  protected void CheckFilledEditBoxes()
127  {
128  m_bForceConfirmButtonDisabled = m_UserName.GetValue().IsEmpty() || m_Password.GetValue().IsEmpty();
129  if (m_ConfirmButton)
130  m_ConfirmButton.SetEnabled(!m_bForceConfirmButtonDisabled && UpdateButtons());
131  }
132 }
133 
134 //------------------------------------------------------------------------------------------------
135 class SCR_LoginDialogConsoleUI : SCR_LoginDialogUI
136 {
137  protected const string OVERLAY_MAIN = "OverlayMain";
138 
139  protected OverlayWidget m_wOverlayMain;
140 
141  //------------------------------------------------------------------------------------------------
143  {
144  super.OnMenuOpen(preset);
145 
146  m_wOverlayMain = OverlayWidget.Cast(m_wRoot.FindAnyWidget(OVERLAY_MAIN));
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  // The dialog has a unique structure so we need to attach the loading overlay to a different Widget than other dialogs
151  override OverlayWidget GetDialogBaseOverlay()
152  {
153  return m_wOverlayMain;
154  }
155 }
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_LoginDialogUI
Definition: LoginDialogUI.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Callback
protected ref CampaignCallback m_Callback
Definition: SCR_PlayerProfileManagerComponent.c:25
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
m_wOverlayMain
protected OverlayWidget m_wOverlayMain
Definition: LoginDialogUI.c:139
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_ELoginFailReason
SCR_ELoginFailReason
Definition: SCR_LoginProcessDialogUI.c:364
GetDialogBaseOverlay
override OverlayWidget GetDialogBaseOverlay()
Definition: LoginDialogUI.c:151
SCR_EditBoxComponent
Definition: SCR_EditBoxComponent.c:8
UpdateButtons
protected void UpdateButtons()
Definition: SCR_ContentBrowser_AddonsSubMenu.c:1036
callback
DownloadConfigCallback callback
OVERLAY_MAIN
SCR_LoginDialogUI OVERLAY_MAIN
SCR_LoginProcessDialogUI
Definition: SCR_LoginProcessDialogUI.c:5
OnMenuOpen
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
Definition: LoginDialogUI.c:142