Util - Add regex serverUrl check.
This commit is contained in:
parent
ab9216cbc2
commit
8e537fba1b
38
AIParkingApplication/LoginForm.Designer.cs
generated
38
AIParkingApplication/LoginForm.Designer.cs
generated
|
@ -34,8 +34,8 @@
|
||||||
this.lblUsername = new System.Windows.Forms.Label();
|
this.lblUsername = new System.Windows.Forms.Label();
|
||||||
this.txtPassword = new System.Windows.Forms.TextBox();
|
this.txtPassword = new System.Windows.Forms.TextBox();
|
||||||
this.lblPassword = new System.Windows.Forms.Label();
|
this.lblPassword = new System.Windows.Forms.Label();
|
||||||
this.lblServerAddress = new System.Windows.Forms.TextBox();
|
this.txtServerAddress = new System.Windows.Forms.TextBox();
|
||||||
this.lblServerIP = new System.Windows.Forms.Label();
|
this.lblServerAddress = new System.Windows.Forms.Label();
|
||||||
this.btnLogin = new System.Windows.Forms.Button();
|
this.btnLogin = new System.Windows.Forms.Button();
|
||||||
this.btnExit = new System.Windows.Forms.Button();
|
this.btnExit = new System.Windows.Forms.Button();
|
||||||
this.lblLoginStatus = new System.Windows.Forms.Label();
|
this.lblLoginStatus = new System.Windows.Forms.Label();
|
||||||
|
@ -87,22 +87,22 @@
|
||||||
this.lblPassword.TabIndex = 2;
|
this.lblPassword.TabIndex = 2;
|
||||||
this.lblPassword.Text = "Mật khẩu";
|
this.lblPassword.Text = "Mật khẩu";
|
||||||
//
|
//
|
||||||
|
// txtServerAddress
|
||||||
|
//
|
||||||
|
this.txtServerAddress.Location = new System.Drawing.Point(294, 90);
|
||||||
|
this.txtServerAddress.Name = "txtServerAddress";
|
||||||
|
this.txtServerAddress.Size = new System.Drawing.Size(227, 20);
|
||||||
|
this.txtServerAddress.TabIndex = 1;
|
||||||
|
this.txtServerAddress.Text = "http://localhost:80/";
|
||||||
|
//
|
||||||
// lblServerAddress
|
// lblServerAddress
|
||||||
//
|
//
|
||||||
this.lblServerAddress.Location = new System.Drawing.Point(294, 90);
|
this.lblServerAddress.AutoSize = true;
|
||||||
|
this.lblServerAddress.Location = new System.Drawing.Point(214, 93);
|
||||||
this.lblServerAddress.Name = "lblServerAddress";
|
this.lblServerAddress.Name = "lblServerAddress";
|
||||||
this.lblServerAddress.Size = new System.Drawing.Size(227, 20);
|
this.lblServerAddress.Size = new System.Drawing.Size(48, 13);
|
||||||
this.lblServerAddress.TabIndex = 1;
|
this.lblServerAddress.TabIndex = 2;
|
||||||
this.lblServerAddress.Text = "localhost";
|
this.lblServerAddress.Text = "Máy chủ";
|
||||||
//
|
|
||||||
// lblServerIP
|
|
||||||
//
|
|
||||||
this.lblServerIP.AutoSize = true;
|
|
||||||
this.lblServerIP.Location = new System.Drawing.Point(214, 93);
|
|
||||||
this.lblServerIP.Name = "lblServerIP";
|
|
||||||
this.lblServerIP.Size = new System.Drawing.Size(48, 13);
|
|
||||||
this.lblServerIP.TabIndex = 2;
|
|
||||||
this.lblServerIP.Text = "Máy chủ";
|
|
||||||
//
|
//
|
||||||
// btnLogin
|
// btnLogin
|
||||||
//
|
//
|
||||||
|
@ -141,10 +141,10 @@
|
||||||
this.Controls.Add(this.lblLoginStatus);
|
this.Controls.Add(this.lblLoginStatus);
|
||||||
this.Controls.Add(this.btnExit);
|
this.Controls.Add(this.btnExit);
|
||||||
this.Controls.Add(this.btnLogin);
|
this.Controls.Add(this.btnLogin);
|
||||||
this.Controls.Add(this.lblServerIP);
|
this.Controls.Add(this.lblServerAddress);
|
||||||
this.Controls.Add(this.lblPassword);
|
this.Controls.Add(this.lblPassword);
|
||||||
this.Controls.Add(this.lblUsername);
|
this.Controls.Add(this.lblUsername);
|
||||||
this.Controls.Add(this.lblServerAddress);
|
this.Controls.Add(this.txtServerAddress);
|
||||||
this.Controls.Add(this.txtPassword);
|
this.Controls.Add(this.txtPassword);
|
||||||
this.Controls.Add(this.txtUsername);
|
this.Controls.Add(this.txtUsername);
|
||||||
this.Controls.Add(this.pictureBoxImageLogo);
|
this.Controls.Add(this.pictureBoxImageLogo);
|
||||||
|
@ -168,8 +168,8 @@
|
||||||
private System.Windows.Forms.Label lblUsername;
|
private System.Windows.Forms.Label lblUsername;
|
||||||
private System.Windows.Forms.TextBox txtPassword;
|
private System.Windows.Forms.TextBox txtPassword;
|
||||||
private System.Windows.Forms.Label lblPassword;
|
private System.Windows.Forms.Label lblPassword;
|
||||||
private System.Windows.Forms.TextBox lblServerAddress;
|
private System.Windows.Forms.TextBox txtServerAddress;
|
||||||
private System.Windows.Forms.Label lblServerIP;
|
private System.Windows.Forms.Label lblServerAddress;
|
||||||
private System.Windows.Forms.Button btnLogin;
|
private System.Windows.Forms.Button btnLogin;
|
||||||
private System.Windows.Forms.Button btnExit;
|
private System.Windows.Forms.Button btnExit;
|
||||||
private System.Windows.Forms.Label lblLoginStatus;
|
private System.Windows.Forms.Label lblLoginStatus;
|
||||||
|
|
|
@ -13,13 +13,25 @@ namespace AIParkingApplication
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
pictureBoxImageLogo.Image = new Bitmap(@".\Images\ApplicationLogo.ico");
|
pictureBoxImageLogo.Image = new Bitmap(@".\Images\ApplicationLogo.ico");
|
||||||
lblLoginStatus.Text = string.Empty;
|
lblLoginStatus.Text = string.Empty;
|
||||||
|
|
||||||
apiController = new ApiController(serverBaseAddress);
|
|
||||||
this.AcceptButton = btnLogin;
|
this.AcceptButton = btnLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Login()
|
private async void Login()
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(txtServerAddress.Text))
|
||||||
|
{
|
||||||
|
lblLoginStatus.Text = "Địa chỉ server không được để trống!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Util.IsUrlValid(txtServerAddress.Text))
|
||||||
|
{
|
||||||
|
lblLoginStatus.Text = "Địa chỉ server không đúng định dạng: \r\n http://localhost:80 hoặc http://192.168.1.2:80";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
apiController = new ApiController(txtServerAddress.Text);
|
||||||
|
|
||||||
lblLoginStatus.Text = string.Empty;
|
lblLoginStatus.Text = string.Empty;
|
||||||
string username = txtUsername.Text;
|
string username = txtUsername.Text;
|
||||||
string password = txtPassword.Text;
|
string password = txtPassword.Text;
|
||||||
|
@ -28,6 +40,7 @@ namespace AIParkingApplication
|
||||||
lblLoginStatus.Text = "Tên tài khoản hoặc mật khẩu không được để trống!";
|
lblLoginStatus.Text = "Tên tài khoản hoặc mật khẩu không được để trống!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var loginResult = await apiController.Login(new LoginModel { Username = username, Password = password });
|
var loginResult = await apiController.Login(new LoginModel { Username = username, Password = password });
|
||||||
if (loginResult.IsLoginSuccess)
|
if (loginResult.IsLoginSuccess)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
@ -168,6 +169,14 @@ namespace AIParkingApplication
|
||||||
//process.Close();
|
//process.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsUrlValid(string url)
|
||||||
|
{
|
||||||
|
|
||||||
|
string pattern = @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
|
||||||
|
Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
return reg.IsMatch(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlateRequestEngineModel
|
public class PlateRequestEngineModel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user