XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

STHApplication

【MAUI】寄当家——安卓端交易管理系统

公开
关注 0 Fork 0 Star 0
UTF-8
#if ACCOUNTING_APP
using JiDangJia.Contracts;
using Microsoft.Data.Sqlite;

namespace JiDangJia.Server;

public sealed record ClearMyDataRequest(string Password,string PasswordAgain,string ClientId);
public sealed record PasswordVerificationRequest(string Password);
public sealed partial class ServerStore
{
    private static void InitializeSafety(SqliteConnection c)
    {
        void Column(string table,string name,string definition)
        {if(!Rows(c,"PRAGMA table_info("+table+")").Any(r=>Text(r,"name")==name))Exec(c,$"ALTER TABLE {table} ADD COLUMN {name} {definition}");}
        Column("Accounts","phone","TEXT NOT NULL DEFAULT ''");Column("Accounts","phoneMethod","TEXT NOT NULL DEFAULT ''");
        Column("Cards","permanent","INTEGER NOT NULL DEFAULT 0");Column("Cards","fixedUntil","TEXT");Column("Licenses","permanent","INTEGER NOT NULL DEFAULT 0");
    }
    internal static Dictionary<string,object?> SafetyAccount(SqliteConnection c,string id)
        =>Rows(c,"SELECT * FROM Accounts WHERE id=@p0 AND active=1",id).FirstOrDefault()??throw new CommunityException(401,"账户不可用,请重新登录");
    public void VerifyOwnPassword(Account account,string password)=>Read(c=>{CheckPassword(c,account,password);return 0;});
    private static void CheckPassword(SqliteConnection c,Account account,string? password)
    {if(password is null||password.Length is <8 or >128||!VerifyPassword(password,Text(SafetyAccount(c,account.Id),"passwordHash")))throw new CommunityException(403,"登录密码不正确");}
    public object ConfirmLocalClear(Account account,ClearMyDataRequest request)=>Write(c=>
    {
        CheckPassword(c,account,request.Password);CheckPassword(c,account,request.PasswordAgain);
        if(!Guid.TryParseExact(request.ClientId,"N",out _))throw new ArgumentException("清除请求标识无效");
        Audit(c,account.Id,"OWN_DATA_CLEAR",account.Id,"确认清除此记账账户的本机数据");
        return new{ok=true,accountId=account.Id,clientId=request.ClientId};
    });
}
#endif