Commit beb97f27 by Joona Romppanen

Fix lingering password field and remove useless timer from UserLoginControl

1 parent 6ec28ff3
......@@ -28,10 +28,8 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label4 = new System.Windows.Forms.Label();
this.txtEmail = new System.Windows.Forms.TextBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.infoLabel = new System.Windows.Forms.Label();
this.passwordTextBox = new System.Windows.Forms.TextBox();
this.loginButton = new System.Windows.Forms.Button();
......@@ -61,12 +59,6 @@
this.txtEmail.Size = new System.Drawing.Size(395, 26);
this.txtEmail.TabIndex = 67;
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
//
......@@ -137,7 +129,6 @@
this.Name = "UserLoginControl";
this.Size = new System.Drawing.Size(420, 126);
this.Load += new System.EventHandler(this.UserLoginControl_Load);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UserLoginControl_KeyUp);
this.ResumeLayout(false);
this.PerformLayout();
......@@ -147,7 +138,6 @@
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtEmail;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label infoLabel;
private System.Windows.Forms.TextBox passwordTextBox;
private System.Windows.Forms.Button loginButton;
......
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using MoyaAdminLib;
......@@ -35,11 +34,59 @@ namespace MoyaSignup
var txt = txtEmail.Text;
if (IsValidEmail(txt))
{
timer1.Stop();
timer1.Start();
var client = new RestClient();
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
{
ShowLogin(false);
if (txtEmail.Text == "thermo2")
{
SetPrinter?.Invoke(ThermoPrinter.Models.IDP3210);
......@@ -51,7 +98,6 @@ namespace MoyaSignup
txtEmail.Text = "OK";
}
timer1.Stop();
CurrentUser = null;
btnNewProfile.Visible = false;
infoLabel.Text = "Hei! Kirjoita sähköpostiosoitteesi";
......@@ -91,75 +137,33 @@ namespace MoyaSignup
}
}
private void Timer1_Tick(object sender, EventArgs e)
{
var client = new RestClient();
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)
private void ShowLogin(bool show)
{
timer1.Stop();
var apiException = ex as MoyaApiException;
if (apiException != null && apiException.StatusCode == HttpStatusCode.NotFound)
if (show)
{
CurrentUser = null;
infoLabel.Text = "Uusi kävijä?";
btnNewProfile.Visible = true;
ShowLogin(false);
passwordTextBox.Visible = true;
loginButton.Visible = true;
}
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();
Logger.Error("Unexpected exception", ex);
MessageBox.Show(
"Odottamaton virhe. Ota yhteys infoon.",
"Järjestelmävirhe",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
passwordTextBox.Visible = false;
loginButton.Visible = false;
passwordTextBox.Clear();
}
}
private void ShowLogin(bool show)
private void DoLogin()
{
passwordTextBox.Visible = show;
loginButton.Visible = show;
}
private void Login()
var client = new RestClient(RestClient.ApiURL, HttpVerb.POST)
{
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";
PostData = "password=" + passwordTextBox.Text,
ContentType = "application/x-www-form-urlencoded"
};
try
{
var json = client.MakeRequest("v2/user/" + CurrentUser.UserId + "/check-password");
// string json2 = client.MakeRequest("user/"+ CurrentUser.UserId +"/check-password");
// MoyaWeb/rest/user/eventusers
var ser = new JavaScriptSerializer();
var euser = ser.Deserialize<Eventuser>(json);
......@@ -185,7 +189,7 @@ namespace MoyaSignup
private void LoginButton_Click(object sender, EventArgs e)
{
Login();
DoLogin();
}
private void WrongPass()
......@@ -196,7 +200,7 @@ namespace MoyaSignup
private void PasswordTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
Login();
DoLogin();
}
private void BtnNewProfile_Click(object sender, EventArgs e)
......@@ -205,6 +209,7 @@ namespace MoyaSignup
{
Email = txtEmail.Text
};
//Send info to parent control
LoginOk?.Invoke(this, null);
}
......@@ -221,35 +226,5 @@ namespace MoyaSignup
infoLabel.Text = "Hei! Kirjoita sähköpostiosoitteesi";
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
......@@ -117,7 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</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>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!