-
Notifications
You must be signed in to change notification settings - Fork 0
/
bar.cs
203 lines (161 loc) · 6.6 KB
/
bar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using GitMasterGui;
using GitMasterGui.Configuration;
using GitMasterGui.License;
using GitMasterGui.LoginWindow;
using GitMaster.UI;
using GitMaster.UI.Web;
using WpfUI;
using GitMasterGui.Api;
namespace GitMaster.LoginWindow
{
internal class LoginPanel : DockPanel
{
internal LoginPanel(
IGitMasterRestApi restApi,
ILoginWindow loginWindow,
Login.ILoginNotifier loginSuccessNotifier)
{
mRestApi = restApi;
mLoginWindow = loginWindow;
mLoginSuccessNotifier = loginSuccessNotifier;
BuildComponents();
mUserTextBox.Focus();
}
internal void Dispose()
{
mSignUpLinkLabel.HyperLink.Click -= SignUpLinkLabel_Click;
mLoginButton.Click -= LoginButton_Click;
mPasswordTextBox.Dispose();
}
internal string GetTeamInvitationCode()
{
return mTeamInvitationCodeTextBox.Text;
}
internal void NotifyError(string message)
{
mMascotImage.Source = GitMasterImages.GetImage(
GitMasterImages.ImageName.IllustrationSignupError);
mWebErrorPanel.ShowError(message);
}
void SignUpLinkLabel_Click(object sender, RoutedEventArgs e)
{
mLoginWindow.ShowSignUpPanel();
}
void LoginButton_Click(object sender, RoutedEventArgs e)
{
ClearErrors();
LoginConfiguration.Data data = LoginConfiguration.Data.Build(
mUserTextBox.Text,
mPasswordTextBox.Text);
Login.ValidationResult result = Login.Validate(data);
if (!result.IsOk())
{
ShowErrors(result);
return;
}
Login.Run(mRestApi, data, mProgressControls, mLoginSuccessNotifier);
}
void ShowErrors(Login.ValidationResult result)
{
if (!string.IsNullOrEmpty(result.EncryptedPasswordError))
{
mPasswordTextBox.HasValidationError = true;
mPasswordTextBox.Focus();
mPasswordErrorLabel.Text = result.EncryptedPasswordError;
mPasswordErrorLabel.Visibility = Visibility.Visible;
}
if (!string.IsNullOrEmpty(result.UserError))
{
mUserTextBox.HasValidationError = true;
mUserTextBox.Focus();
mUserErrorLabel.Text = result.UserError;
mUserErrorLabel.Visibility = Visibility.Visible;
}
}
void ClearErrors()
{
mUserTextBox.HasValidationError = false;
mUserErrorLabel.Text = string.Empty;
mUserErrorLabel.Visibility = Visibility.Collapsed;
mPasswordTextBox.HasValidationError = false;
mPasswordErrorLabel.Text = string.Empty;
mPasswordErrorLabel.Visibility = Visibility.Collapsed;
}
void BuildComponents()
{
mMascotImage = ControlBuilder.CreateImage(
GitMasterImages.GetImage(
GitMasterImages.ImageName.IllustrationLoginSkater));
mMascotImage.Width = 330;
mMascotImage.Margin = new Thickness(10, 55, 30, 50);
WebEntriesPacker.AddMascotContentComponents(
this, mMascotImage, CreateContentPanel());
}
Panel CreateContentPanel()
{
StackPanel result = new StackPanel();
ValidationProgressPanel validationPanel = new ValidationProgressPanel();
Panel headerPanel = CreateHeaderPanel();
mWebErrorPanel = new WebErrorPanel();
mUserTextBox = WebControlBuilder.CreateTextBox(
GitMasterLocalization.GetString(
GitMasterLocalization.Name.LoginPanelUserWatermark));
mUserErrorLabel = WebControlBuilder.CreateErrorLabel();
mPasswordTextBox = WebControlBuilder.CreatePasswordTextBox(
GitMasterLocalization.GetString(
GitMasterLocalization.Name.LoginPanelPasswordWatermark));
mPasswordErrorLabel = WebControlBuilder.CreateErrorLabel();
mTeamInvitationCodeTextBox = WebControlBuilder.CreateTextBox(
GitMasterLocalization.GetString(
GitMasterLocalization.Name.LoginPanelTeamInvitationCodeWatermark));
mLoginButton = WebControlBuilder.CreateMainActionButton(
GitMasterLocalization.GetString(
GitMasterLocalization.Name.LoginButtonUppercase));
mLoginButton.Click += LoginButton_Click;
WebEntriesPacker.AddRelatedComponents(
result,
headerPanel,
mWebErrorPanel,
mUserTextBox,
mUserErrorLabel,
mPasswordTextBox,
mPasswordErrorLabel,
mTeamInvitationCodeTextBox,
validationPanel,
mLoginButton);
mProgressControls = new ProgressControlsForDialogs(
validationPanel, new UIElement[] { mLoginButton });
mLoginButton.IsDefault = true;
return result;
}
Panel CreateHeaderPanel()
{
TextBlock titleTextBlock = WebControlBuilder.CreateTitle(
GitMasterLocalization.GetString(
GitMasterLocalization.Name.LoginPanelTitle));
mSignUpLinkLabel = WebControlBuilder.CreateLinkLabel(
GitMasterLocalization.GetString(
GitMasterLocalization.Name.SignUpLinkLabel));
mSignUpLinkLabel.HyperLink.Click += SignUpLinkLabel_Click;
return WebEntriesPacker.CreateHeaderPanel(
titleTextBlock, mSignUpLinkLabel);
}
IProgressControlsForDialogs mProgressControls;
LinkLabel mSignUpLinkLabel;
Image mMascotImage;
WebErrorPanel mWebErrorPanel;
WebTextBox mUserTextBox;
SelectableLabel mUserErrorLabel;
PasswordWebTextBox mPasswordTextBox;
SelectableLabel mPasswordErrorLabel;
WebTextBox mTeamInvitationCodeTextBox;
Button mLoginButton;
Login.ILoginNotifier mLoginSuccessNotifier;
ILoginWindow mLoginWindow;
IGitMasterRestApi mRestApi;
}
}