登录功能,自动登录实现
This commit is contained in:
commit
bb8dfca7a1
5 files changed
+49
-51
No files matched your search
@@ -280,7 +280,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
|
||||
string Sql = @"
|
||||
INSERT INTO Users (User,UserId ,UserName ,UserPassword ,Enterprise ,Department ,ServerID ,Groups ,ProxyID ,LogNo ,LocalAreaNetworkMode ,DarkMode ,MessageNotificationMode ,GUID
|
||||
)VALUES('SUNLIGHT','SUNLIGHT','SUNLIGHT','SUNLIGHT','SUNLIGHT','ENGINEER','TEST','ENGINEER','',0,0,0,0,'"+ Models.AppModels.GetAppUniqueId() + "');";
|
||||
)VALUES('SUNLIGHT','SUNLIGHT','SUNLIGHT','SUNLIGHT','SUNLIGHT','ENGINEER','127.0.0.1:7789','ENGINEER','',0,0,0,0,'"+ Models.AppModels.GetAppUniqueId() + "');";
|
||||
|
||||
// 复用现有的 ExecuteNonQuery 方法
|
||||
SQLitedata.ExecuteNonQuery(Sql, null);
|
||||
|
||||
+1
-3
@@ -47,9 +47,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
ServerPassword = Password;
|
||||
ServerTerminal = Terminal;
|
||||
|
||||
|
||||
_ = TcpClient(tcpClient, ServerIP);
|
||||
|
||||
}
|
||||
public static async void TcpTransmit(string Dat)
|
||||
{
|
||||
@@ -167,7 +165,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("错误", "不合法的访问地址", "是");
|
||||
await Application.Current!.Windows[0].Page!.DisplayAlertAsync("错误", ex.ToString(), "是");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-20
@@ -17,29 +17,31 @@ namespace SunlightAggregationTerminal.Models
|
||||
if(sqliteHelper != null)
|
||||
{//获取配置信息
|
||||
sqliteHelper.Open();
|
||||
DataSet? userdata = sqliteHelper.ExecuteDataSet("select * from Users ", null);
|
||||
DataSet? userdata = sqliteHelper.ExecuteDataSet("select * from Users where LogNo = 1", null);
|
||||
sqliteHelper.Close();
|
||||
if (userdata != null)
|
||||
{
|
||||
DataRow dat = userdata.Tables[0].Rows[0];
|
||||
if (dat != null)
|
||||
{
|
||||
App.GlobalData.UserName = dat.Field<string>("UserName") ?? "";
|
||||
App.GlobalData.UserId = dat.Field<string>("UserID") ?? "";
|
||||
App.GlobalData.User = dat.Field<string>("User") ?? "";
|
||||
App.GlobalData.UserPassword = dat.Field<string>("UserPassword") ?? "";
|
||||
App.GlobalData.Enterprise = dat.Field<string>("Enterprise") ?? "";
|
||||
App.GlobalData.Department = dat.Field<string>("Department") ?? "";
|
||||
App.GlobalData.Groups = dat.Field<string>("Groups") ?? "";
|
||||
App.GlobalData.ServerID = dat.Field<string>("ServerID") ?? "";
|
||||
App.GlobalData.ProxyID = dat.Field<string>("ProxyID") ?? "";
|
||||
App.GlobalData.LogNo = Convert.ToBoolean(dat.Field<object>("LogNo"));
|
||||
App.GlobalData.LocalAreaNetworkMode = Convert.ToBoolean(dat.Field<object>("LocalAreaNetworkMode"));
|
||||
App.GlobalData.DarkMode = Convert.ToBoolean(dat.Field<object>("DarkMode"));
|
||||
App.GlobalData.MessageNotificationMode = Convert.ToBoolean(dat.Field<object>("MessageNotificationMode"));
|
||||
|
||||
TcpServer.Configuration(App.GlobalData.ServerID, App.GlobalData.User, App.GlobalData.UserPassword, dat.Field<string>("GUID") ?? "Not");
|
||||
{
|
||||
if (userdata.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
DataRow dat = userdata.Tables[0].Rows[0];
|
||||
if (dat != null)
|
||||
{
|
||||
App.GlobalData.UserName = dat.Field<string>("UserName") ?? "";
|
||||
App.GlobalData.UserId = dat.Field<string>("UserID") ?? "";
|
||||
App.GlobalData.User = dat.Field<string>("User") ?? "";
|
||||
App.GlobalData.UserPassword = dat.Field<string>("UserPassword") ?? "";
|
||||
App.GlobalData.Enterprise = dat.Field<string>("Enterprise") ?? "";
|
||||
App.GlobalData.Department = dat.Field<string>("Department") ?? "";
|
||||
App.GlobalData.Groups = dat.Field<string>("Groups") ?? "";
|
||||
App.GlobalData.ServerID = dat.Field<string>("ServerID") ?? "";
|
||||
App.GlobalData.ProxyID = dat.Field<string>("ProxyID") ?? "";
|
||||
App.GlobalData.LogNo = Convert.ToBoolean(dat.Field<object>("LogNo"));
|
||||
App.GlobalData.LocalAreaNetworkMode = Convert.ToBoolean(dat.Field<object>("LocalAreaNetworkMode"));
|
||||
App.GlobalData.DarkMode = Convert.ToBoolean(dat.Field<object>("DarkMode"));
|
||||
App.GlobalData.MessageNotificationMode = Convert.ToBoolean(dat.Field<object>("MessageNotificationMode"));
|
||||
|
||||
TcpServer.Configuration(App.GlobalData.ServerID, App.GlobalData.User, App.GlobalData.UserPassword, dat.Field<string>("GUID") ?? "Not");
|
||||
}
|
||||
//启动tcp
|
||||
// TcpServer.CreateCustomService();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using SunlightAggregationTerminal.Class;
|
||||
using SunlightAggregationTerminal.Models;
|
||||
using SunlightAggregationTerminal.View;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -15,10 +16,13 @@ public partial class ProfilePage : ContentPage
|
||||
|
||||
private async void Out_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
//退出
|
||||
bool shouldExit = await DisplayAlertAsync("退出确认", "确定要退出吗?", "是", "否");
|
||||
if (shouldExit)
|
||||
{
|
||||
App.GlobalData.LogNo = false;
|
||||
await TcpServer.tcpClient.CloseAsync("");
|
||||
|
||||
var logpage = new View.LogPage();
|
||||
await Navigation.PushModalAsync(logpage);
|
||||
}
|
||||
|
||||
+21
-27
@@ -9,13 +9,13 @@ namespace SunlightAggregationTerminal.View;
|
||||
|
||||
public class ItemOption
|
||||
{
|
||||
public required string? SERVER { get; set; }
|
||||
public required string? SERVERIP { get; set; }
|
||||
public required string SERVER { get; set; }
|
||||
public required string SERVERIP { get; set; }
|
||||
}
|
||||
|
||||
public partial class LogPage : ContentPage
|
||||
{
|
||||
public ObservableCollection<ItemOption>? Items { get; }
|
||||
public ObservableCollection<ItemOption>? Items { get; set; }
|
||||
|
||||
public LogPage()
|
||||
{
|
||||
@@ -31,22 +31,25 @@ public partial class LogPage : ContentPage
|
||||
var userdata = AppModels.sqliteHelper.ExecuteDataSet("select * from Server", null);
|
||||
AppModels.sqliteHelper.Close();
|
||||
|
||||
Items = new ObservableCollection<ItemOption>();
|
||||
|
||||
if (userdata != null)
|
||||
{
|
||||
foreach (DataRow dataRow in userdata.Tables[0].Rows)
|
||||
{
|
||||
if (dataRow != null)
|
||||
{
|
||||
Items?.Add(new ItemOption {
|
||||
SERVER = dataRow.Field<string>("UserName") ?? "",
|
||||
SERVERIP = dataRow.Field<string>("UserName") ?? ""
|
||||
});
|
||||
var dat = new ItemOption
|
||||
{
|
||||
SERVER = dataRow.Field<string>("Server") ?? "",
|
||||
SERVERIP = dataRow.Field<string>("ServerID") ?? ""
|
||||
};
|
||||
Items.Add(dat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:设置默认选中项
|
||||
if (Items != null)
|
||||
// 设置默认选中项
|
||||
if (Items.Count>0)
|
||||
{
|
||||
SERVER.ItemsSource = Items;
|
||||
SERVER.SelectedItem = Items[0];
|
||||
@@ -74,19 +77,17 @@ public partial class LogPage : ContentPage
|
||||
TcpServer.Configuration(SERVERIP.Text, UsernameEntry.Text, PasswordEntry.Text,
|
||||
Models.AppModels.GetAppUniqueId());
|
||||
|
||||
|
||||
LoadingIndicator.IsVisible = true;
|
||||
|
||||
//TcpServer.TcpTransmit("Log");
|
||||
|
||||
|
||||
if (await AppModels.LogIn())
|
||||
{
|
||||
var temp_name = AppModels.Select("SELECT * FROM Users WHERE User='" + UsernameEntry.Text + "' LIMIT 1;")!.Tables[0];
|
||||
if (temp_name != null)
|
||||
App.GlobalData.ServerID = SERVERIP.Text;
|
||||
|
||||
int temp_name = AppModels.Select("SELECT * FROM Users WHERE User='" + UsernameEntry.Text + "' LIMIT 1;")!.Tables[0].Rows.Count;
|
||||
if (temp_name >0)
|
||||
{
|
||||
//存在更新账号状态
|
||||
string sql = @"UPDATE Users SET ServerID = '" + SERVERIP.Text
|
||||
string sql = "UPDATE Users SET ServerID = '" + SERVERIP.Text
|
||||
+ "', UserPassword = '" + PasswordEntry.Text +
|
||||
"', LogNo = 1 WHERE User='" + UsernameEntry.Text + "';";
|
||||
AppModels.Updata(sql);
|
||||
@@ -104,8 +105,8 @@ public partial class LogPage : ContentPage
|
||||
AppModels.INSERT(sql);
|
||||
}
|
||||
|
||||
var temp_server = AppModels.Select("SELECT * FROM Server WHERE ServerID='" + SERVERIP.Text + "' LIMIT 1;")!.Tables[0];
|
||||
if (temp_server == null)
|
||||
int temp_server = AppModels.Select("SELECT * FROM Server WHERE ServerID='" + SERVERIP.Text + "' LIMIT 1;")!.Tables[0].Rows.Count;
|
||||
if (temp_server == 0)
|
||||
{
|
||||
string sql = @"INSERT INTO Server ( Server, ServerID)VALUES('" + App.GlobalData.Enterprise + "','" +
|
||||
App.GlobalData.ServerID + "');";
|
||||
@@ -119,12 +120,5 @@ public partial class LogPage : ContentPage
|
||||
await DisplayAlertAsync("未登录", "服务器不存在或拒绝访问", "是");
|
||||
}
|
||||
LoadingIndicator.IsVisible = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//await Navigation.PopModalAsync();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user