/
SignIn.cs
162 lines (128 loc) · 5.15 KB
/
SignIn.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
using DevExpress.XtraBars.Docking2010.Views.WindowsUI;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SEnPA
{
public partial class SignIn : Form
{
string username, password;
string signInSuccessful = "failed";
public SignIn()
{
InitializeComponent();
}
private void SignIn_Load(object sender, EventArgs e)
{
}
private void btnSignIn_Click_1(object sender, EventArgs e)
{
}
private void btnClose_Click(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void cmdSignIn_Click(object sender, EventArgs e)
{
pbarSigningIn.Visible = true;
cmdSignIn.Visible = false;
username = txtUsername.Text;
password = txtPassword.Text;
backgroundWorker1.RunWorkerAsync();
}
public void ShowError()
{
FlyoutAction action = new FlyoutAction() { Caption = "Login Failed!", Description = "Username or password are incorrect. Please check the details and try again." };
FlyoutCommand command1 = new FlyoutCommand() { Text = "OK", Result = System.Windows.Forms.DialogResult.Yes };
action.Commands.Add(command1);
FlyoutProperties properties = new FlyoutProperties();
properties.ButtonSize = new Size(100, 40);
properties.Style = FlyoutStyle.MessageBox;
properties.Appearance.BackColor = Color.Red;
properties.Appearance.ForeColor = Color.White;
DevExpress.XtraBars.Docking2010.Customization.FlyoutDialog.Show(this, action, properties);
}
public void ShowConnectionError()
{
FlyoutAction action = new FlyoutAction() { Caption = "Connection Error!", Description = "The connection to the server failed. Please ensure you are connected to the network and try again." };
FlyoutCommand command1 = new FlyoutCommand() { Text = "OK", Result = System.Windows.Forms.DialogResult.Yes };
action.Commands.Add(command1);
FlyoutProperties properties = new FlyoutProperties();
properties.ButtonSize = new Size(100, 40);
properties.Style = FlyoutStyle.MessageBox;
properties.Appearance.BackColor = Color.Red;
properties.Appearance.ForeColor = Color.White;
DevExpress.XtraBars.Docking2010.Customization.FlyoutDialog.Show(this, action, properties);
}
private void picClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (signInSuccessful.Equals("failed"))
{
pbarSigningIn.Visible = false;
cmdSignIn.Visible = true;
ShowError();
}
else if (signInSuccessful.Equals("successful"))
{
SEnPAMain openMain = new SEnPAMain();
openMain.Show();
pbarSigningIn.Visible = false;
cmdSignIn.Visible = true;
this.Hide();
}
else
{
pbarSigningIn.Visible = false;
cmdSignIn.Visible = true;
ShowConnectionError();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string loginResponse = SenpaApi.SignIn(username, password);
signInSuccessful = loginResponse;
if (loginResponse.Equals("successful"))
{
SenpaApi agent = new SenpaApi();
using (new OperationContextScope(agent.context))
{
//get user group roles
senpa.ApplicationRoleGroups[] accessGroupRoles = agent.operation.GetApplicationGroupRoles(Globals.userLogged);
foreach (senpa.ApplicationRoleGroups roleName in accessGroupRoles)
{
Globals.userGroupRoles.Add(roleName.Name);
}
//get user roles
senpa.ApplicationRoles[] accessRoles = agent.operation.GetApplicationRoles(Globals.userLogged);
foreach (senpa.ApplicationRoles roleName in accessRoles)
{
Globals.userRoles.Add(roleName.Name);
}
}
signInSuccessful = loginResponse;
}
}
}
}