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

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using CommunityToolkit.Mvvm.ComponentModel;
using XFEWarframe.Player.Models;
using XFEWarframe.Player.Profiles.CrossVersionProfiles;
namespace XFEWarframe.Player.ViewModels;
public partial class AuthenticationViewModel : ObservableObject
{
 public IReadOnlyList<string> RememberedEmails { get; } = SystemProfile.RememberAccount && !string.IsNullOrWhiteSpace(SystemProfile.PlayerEmail) ? [SystemProfile.PlayerEmail] : [];
 public PlayerAccountState Account => App.Accounts.State;
 [ObservableProperty] public partial string Email { get; set; } = SystemProfile.PlayerEmail;
 [ObservableProperty] public partial string Password { get; set; } = "";
 [ObservableProperty] public partial string Confirmation { get; set; } = "";
 [ObservableProperty] public partial string DisplayName { get; set; } = "";
 [ObservableProperty] public partial string Error { get; set; } = "";
 [ObservableProperty] public partial bool RememberAccount { get; set; } = SystemProfile.RememberAccount;
 public async Task<bool> SubmitAsync(bool registration) {
  Error="";
  try {
   if(registration) {
    if(!Account.RegistrationEnabled) throw new InvalidOperationException("服务器已关闭注册。");
    if(Password.Length<8) throw new InvalidOperationException("密码至少需要 8 位。");
    if(Password!=Confirmation) throw new InvalidOperationException("两次输入的密码不一致。");
    await App.Accounts.RegisterAsync(Email,Password,DisplayName);
   } else { await App.Accounts.SetRememberAccountAsync(RememberAccount); await App.Accounts.LoginAsync(Email,Password); }
   return true;
  } catch(Exception ex) { Error=ex.Message; return false; }
  finally { ClearPasswords(); }
 }
 public void ClearPasswords() { Password=Confirmation=""; }
}