Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Joona Romppanen
/
Moya Info Tools
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit beb97f27
authored
Jun 09, 2017
by
Joona Romppanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lingering password field and remove useless timer from UserLoginControl
1 parent
6ec28ff3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
109 deletions
MoyaSignup/UserLoginControl.Designer.cs
MoyaSignup/UserLoginControl.cs
MoyaSignup/UserLoginControl.resx
MoyaSignup/UserLoginControl.Designer.cs
View file @
beb97f2
...
@@ -28,10 +28,8 @@
...
@@ -28,10 +28,8 @@
/// </summary>
/// </summary>
private
void
InitializeComponent
()
private
void
InitializeComponent
()
{
{
this
.
components
=
new
System
.
ComponentModel
.
Container
();
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
txtEmail
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
txtEmail
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
timer1
=
new
System
.
Windows
.
Forms
.
Timer
(
this
.
components
);
this
.
infoLabel
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
infoLabel
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
passwordTextBox
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
passwordTextBox
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
loginButton
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
loginButton
=
new
System
.
Windows
.
Forms
.
Button
();
...
@@ -61,12 +59,6 @@
...
@@ -61,12 +59,6 @@
this
.
txtEmail
.
Size
=
new
System
.
Drawing
.
Size
(
395
,
26
);
this
.
txtEmail
.
Size
=
new
System
.
Drawing
.
Size
(
395
,
26
);
this
.
txtEmail
.
TabIndex
=
67
;
this
.
txtEmail
.
TabIndex
=
67
;
this
.
txtEmail
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
TxtEmail_TextChanged
);
this
.
txtEmail
.
TextChanged
+=
new
System
.
EventHandler
(
this
.
TxtEmail_TextChanged
);
this
.
txtEmail
.
KeyUp
+=
new
System
.
Windows
.
Forms
.
KeyEventHandler
(
this
.
TxtEmail_KeyUp
);
//
// timer1
//
this
.
timer1
.
Interval
=
500
;
this
.
timer1
.
Tick
+=
new
System
.
EventHandler
(
this
.
Timer1_Tick
);
//
//
// infoLabel
// infoLabel
//
//
...
@@ -137,7 +129,6 @@
...
@@ -137,7 +129,6 @@
this
.
Name
=
"UserLoginControl"
;
this
.
Name
=
"UserLoginControl"
;
this
.
Size
=
new
System
.
Drawing
.
Size
(
420
,
126
);
this
.
Size
=
new
System
.
Drawing
.
Size
(
420
,
126
);
this
.
Load
+=
new
System
.
EventHandler
(
this
.
UserLoginControl_Load
);
this
.
Load
+=
new
System
.
EventHandler
(
this
.
UserLoginControl_Load
);
this
.
KeyUp
+=
new
System
.
Windows
.
Forms
.
KeyEventHandler
(
this
.
UserLoginControl_KeyUp
);
this
.
ResumeLayout
(
false
);
this
.
ResumeLayout
(
false
);
this
.
PerformLayout
();
this
.
PerformLayout
();
...
@@ -147,7 +138,6 @@
...
@@ -147,7 +138,6 @@
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
TextBox
txtEmail
;
private
System
.
Windows
.
Forms
.
TextBox
txtEmail
;
private
System
.
Windows
.
Forms
.
Timer
timer1
;
private
System
.
Windows
.
Forms
.
Label
infoLabel
;
private
System
.
Windows
.
Forms
.
Label
infoLabel
;
private
System
.
Windows
.
Forms
.
TextBox
passwordTextBox
;
private
System
.
Windows
.
Forms
.
TextBox
passwordTextBox
;
private
System
.
Windows
.
Forms
.
Button
loginButton
;
private
System
.
Windows
.
Forms
.
Button
loginButton
;
...
...
MoyaSignup/UserLoginControl.cs
View file @
beb97f2
using
System
;
using
System
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing
;
using
System.Windows.Forms
;
using
System.Windows.Forms
;
using
MoyaAdminLib
;
using
MoyaAdminLib
;
...
@@ -35,11 +34,59 @@ namespace MoyaSignup
...
@@ -35,11 +34,59 @@ namespace MoyaSignup
var
txt
=
txtEmail
.
Text
;
var
txt
=
txtEmail
.
Text
;
if
(
IsValidEmail
(
txt
))
if
(
IsValidEmail
(
txt
))
{
{
timer1
.
Stop
();
var
client
=
new
RestClient
();
timer1
.
Start
();
try
{
var
json
=
client
.
MakeRequest
(
"user"
,
"email="
+
txtEmail
.
Text
);
var
ser
=
new
JavaScriptSerializer
();
var
euser
=
ser
.
Deserialize
<
Eventuser
>(
json
);
if
(
euser
!=
null
)
{
btnNewProfile
.
Visible
=
false
;
CurrentUser
=
new
User
(
euser
);
infoLabel
.
Text
=
"Hei! "
+
CurrentUser
+
" Kirjoita salasanasi ja kirjaudu"
;
ShowLogin
(
true
);
}
}
catch
(
WebException
ex
)
{
var
apiException
=
ex
as
MoyaApiException
;
if
(
apiException
!=
null
&&
apiException
.
StatusCode
==
HttpStatusCode
.
NotFound
)
{
CurrentUser
=
null
;
infoLabel
.
Text
=
"Uusi kävijä?"
;
btnNewProfile
.
Visible
=
true
;
ShowLogin
(
false
);
}
else
{
ShowLogin
(
false
);
Logger
.
Error
(
"Connection to MoyaApi failed"
,
ex
);
MessageBox
.
Show
(
"Yhteys taustajärjestelmään epäonnistui. Ota yhteys infoon."
,
"Järjestelmävirhe"
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
}
}
catch
(
Exception
ex
)
{
Logger
.
Error
(
"Unexpected exception"
,
ex
);
MessageBox
.
Show
(
"Odottamaton virhe. Ota yhteys infoon."
,
"Järjestelmävirhe"
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
}
}
}
else
else
{
{
ShowLogin
(
false
);
if
(
txtEmail
.
Text
==
"thermo2"
)
if
(
txtEmail
.
Text
==
"thermo2"
)
{
{
SetPrinter
?.
Invoke
(
ThermoPrinter
.
Models
.
IDP3210
);
SetPrinter
?.
Invoke
(
ThermoPrinter
.
Models
.
IDP3210
);
...
@@ -50,8 +97,7 @@ namespace MoyaSignup
...
@@ -50,8 +97,7 @@ namespace MoyaSignup
SetPrinter
?.
Invoke
(
ThermoPrinter
.
Models
.
TMT188II
);
SetPrinter
?.
Invoke
(
ThermoPrinter
.
Models
.
TMT188II
);
txtEmail
.
Text
=
"OK"
;
txtEmail
.
Text
=
"OK"
;
}
}
timer1
.
Stop
();
CurrentUser
=
null
;
CurrentUser
=
null
;
btnNewProfile
.
Visible
=
false
;
btnNewProfile
.
Visible
=
false
;
infoLabel
.
Text
=
"Hei! Kirjoita sähköpostiosoitteesi"
;
infoLabel
.
Text
=
"Hei! Kirjoita sähköpostiosoitteesi"
;
...
@@ -91,75 +137,33 @@ namespace MoyaSignup
...
@@ -91,75 +137,33 @@ namespace MoyaSignup
}
}
}
}
private
void
Timer1_Tick
(
object
sender
,
EventArgs
e
)
private
void
ShowLogin
(
bool
show
)
{
{
var
client
=
new
RestClient
();
if
(
show
)
try
{
{
var
json
=
client
.
MakeRequest
(
"user"
,
"email="
+
txtEmail
.
Text
);
passwordTextBox
.
Visible
=
true
;
var
ser
=
new
JavaScriptSerializer
();
loginButton
.
Visible
=
true
;
var
euser
=
ser
.
Deserialize
<
Eventuser
>(
json
);
if
(
euser
!=
null
)
{
btnNewProfile
.
Visible
=
false
;
CurrentUser
=
new
User
(
euser
);
infoLabel
.
Text
=
"Hei! "
+
CurrentUser
+
" Kirjoita salasanasi ja kirjaudu"
;
ShowLogin
(
true
);
}
}
}
catch
(
WebException
ex
)
else
{
timer1
.
Stop
();
var
apiException
=
ex
as
MoyaApiException
;
if
(
apiException
!=
null
&&
apiException
.
StatusCode
==
HttpStatusCode
.
NotFound
)
{
CurrentUser
=
null
;
infoLabel
.
Text
=
"Uusi kävijä?"
;
btnNewProfile
.
Visible
=
true
;
ShowLogin
(
false
);
}
else
{
Logger
.
Error
(
"Connection to MoyaApi failed"
,
ex
);
MessageBox
.
Show
(
"Yhteys taustajärjestelmään epäonnistui. Ota yhteys infoon."
,
"Järjestelmävirhe"
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
}
}
catch
(
Exception
ex
)
{
{
timer1
.
Stop
();
passwordTextBox
.
Visible
=
false
;
Logger
.
Error
(
"Unexpected exception"
,
ex
);
loginButton
.
Visible
=
false
;
passwordTextBox
.
Clear
();
MessageBox
.
Show
(
"Odottamaton virhe. Ota yhteys infoon."
,
"Järjestelmävirhe"
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
}
}
}
}
private
void
ShowLogin
(
bool
show
)
private
void
DoLogin
(
)
{
{
passwordTextBox
.
Visible
=
show
;
var
client
=
new
RestClient
(
RestClient
.
ApiURL
,
HttpVerb
.
POST
)
loginButton
.
Visible
=
show
;
{
}
PostData
=
"password="
+
passwordTextBox
.
Text
,
ContentType
=
"application/x-www-form-urlencoded"
};
private
void
Login
()
{
var
client
=
new
RestClient
(
RestClient
.
ApiURL
,
HttpVerb
.
POST
);
//client.PostData = "password=" + WebUtility.UrlEncode(passwordTextBox.Text);
client
.
PostData
=
"password="
+
passwordTextBox
.
Text
;
client
.
ContentType
=
"application/x-www-form-urlencoded"
;
try
try
{
{
var
json
=
client
.
MakeRequest
(
"v2/user/"
+
CurrentUser
.
UserId
+
"/check-password"
);
var
json
=
client
.
MakeRequest
(
"v2/user/"
+
CurrentUser
.
UserId
+
"/check-password"
);
// string json2 = client.MakeRequest("user/"+ CurrentUser.UserId +"/check-password");
// MoyaWeb/rest/user/eventusers
// MoyaWeb/rest/user/eventusers
var
ser
=
new
JavaScriptSerializer
();
var
ser
=
new
JavaScriptSerializer
();
var
euser
=
ser
.
Deserialize
<
Eventuser
>(
json
);
var
euser
=
ser
.
Deserialize
<
Eventuser
>(
json
);
...
@@ -185,7 +189,7 @@ namespace MoyaSignup
...
@@ -185,7 +189,7 @@ namespace MoyaSignup
private
void
LoginButton_Click
(
object
sender
,
EventArgs
e
)
private
void
LoginButton_Click
(
object
sender
,
EventArgs
e
)
{
{
Login
();
Do
Login
();
}
}
private
void
WrongPass
()
private
void
WrongPass
()
...
@@ -196,7 +200,7 @@ namespace MoyaSignup
...
@@ -196,7 +200,7 @@ namespace MoyaSignup
private
void
PasswordTextBox_KeyDown
(
object
sender
,
KeyEventArgs
e
)
private
void
PasswordTextBox_KeyDown
(
object
sender
,
KeyEventArgs
e
)
{
{
if
(
e
.
KeyData
==
Keys
.
Enter
)
if
(
e
.
KeyData
==
Keys
.
Enter
)
Login
();
Do
Login
();
}
}
private
void
BtnNewProfile_Click
(
object
sender
,
EventArgs
e
)
private
void
BtnNewProfile_Click
(
object
sender
,
EventArgs
e
)
...
@@ -205,6 +209,7 @@ namespace MoyaSignup
...
@@ -205,6 +209,7 @@ namespace MoyaSignup
{
{
Email
=
txtEmail
.
Text
Email
=
txtEmail
.
Text
};
};
//Send info to parent control
//Send info to parent control
LoginOk
?.
Invoke
(
this
,
null
);
LoginOk
?.
Invoke
(
this
,
null
);
}
}
...
@@ -221,35 +226,5 @@ namespace MoyaSignup
...
@@ -221,35 +226,5 @@ namespace MoyaSignup
infoLabel
.
Text
=
"Hei! Kirjoita sähköpostiosoitteesi"
;
infoLabel
.
Text
=
"Hei! Kirjoita sähköpostiosoitteesi"
;
loginButton
.
Visible
=
false
;
loginButton
.
Visible
=
false
;
}
}
private
void
UserLoginControl_KeyUp
(
object
sender
,
KeyEventArgs
e
)
{
/*if (e.Alt && e.Control && e.KeyCode == Keys.S)
{
Application.Exit();
return;
}
if (e.Alt && e.KeyCode == Keys.F5)
{
//userDetailsEditor1.SetPrinter(ThermoPrinterLibrary.ThermoPrinter.Models.IDP3210);
//MessageBox.Show("Printteri: IDP3210");
}*/
}
private
void
TxtEmail_KeyUp
(
object
sender
,
KeyEventArgs
e
)
{
/*if (e.Alt && e.Control && e.KeyCode == Keys.S)
{
Program.form1.AllowShutdown = true;
Application.Exit();
return;
}
if (e.Alt && e.KeyCode == Keys.F5)
{
//userDetailsEditor1.SetPrinter(ThermoPrinterLibrary.ThermoPrinter.Models.IDP3210);
//MessageBox.Show("Printteri: IDP3210");
}*/
}
}
}
}
}
\ No newline at end of file
MoyaSignup/UserLoginControl.resx
View file @
beb97f2
...
@@ -117,7 +117,4 @@
...
@@ -117,7 +117,4 @@
<resheader name="writer">
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
</root>
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment