feat: 增加了登录选项

This commit is contained in:
2025-07-11 16:36:28 +08:00
parent d88c710606
commit b4bb563782
8 changed files with 790 additions and 129 deletions

View File

@@ -122,14 +122,30 @@ public class AppDataConnection : DataConnection
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
static readonly string DATABASE_FILEPATH = $"{Environment.CurrentDirectory}/Database.sqlite";
static readonly LinqToDB.DataOptions options =
new LinqToDB.DataOptions()
.UseSQLite($"Data Source={Environment.CurrentDirectory}/Database.sqlite");
new LinqToDB.DataOptions().UseSQLite($"Data Source={DATABASE_FILEPATH}");
/// <summary>
/// 初始化应用程序数据连接
/// </summary>
public AppDataConnection() : base(options) { }
public AppDataConnection() : base(options)
{
if (!Path.Exists(DATABASE_FILEPATH))
{
LinqToDB.DataProvider.SQLite.SQLiteTools.CreateDatabase(DATABASE_FILEPATH);
this.CreateAllTables();
var user = new User()
{
Name = "Admin",
EMail = "selfconfusion@gmail.com",
Password = "12345678",
Permission = Database.User.UserPermission.Admin,
};
this.Insert(user);
}
}
/// <summary>
@@ -173,20 +189,69 @@ public class AppDataConnection : DataConnection
/// [TODO:description]
/// </summary>
/// <param name="name">[TODO:parameter]</param>
/// <param name="password">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public Result<Optional<User>> CheckUserPassword(string name, string password)
public Result<Optional<User>> GetUserByName(string name)
{
var user = this.User.Where((user) => user.Name == name).ToArray();
if (user.Length > 1)
{
logger.Error($"TODO");
return new(new Exception($""));
return new(new Exception($"TODO"));
}
if (user[0].Password == password) return new(user[0]);
else return new(Optional.Null<User>());
if (user.Length == 0)
{
logger.Info($"TODO");
return new(Optional<User>.None);
}
return new(user[0]);
}
/// <summary>
/// [TODO:description]
/// </summary>
/// <param name="email">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public Result<Optional<User>> GetUserByEMail(string email)
{
var user = this.User.Where((user) => user.EMail == email).ToArray();
if (user.Length > 1)
{
logger.Error($"TODO");
return new(new Exception($"TODO"));
}
if (user.Length == 0)
{
logger.Info($"TODO");
return new(Optional<User>.None);
}
return new(user[0]);
}
/// <summary>
/// [TODO:description]
/// </summary>
/// <param name="name">[TODO:parameter]</param>
/// <param name="password">[TODO:parameter]</param>
/// <returns>[TODO:return]</returns>
public Result<Optional<User>> CheckUserPassword(string name, string password)
{
var ret = this.GetUserByName(name);
if (!ret.IsSuccessful)
return new(ret.Error);
if (!ret.Value.HasValue)
return new(Optional<User>.None);
var user = ret.Value.Value;
if (user.Password == password) return new(user);
else return new(Optional<User>.None);
}
/// <summary>