Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Use json to store login data
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhiyuan36 authored Jul 25, 2024
1 parent a465eb8 commit 9dfd2db
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions LoCyanFrpDesktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -31,6 +31,7 @@
using HandyControl.Tools.Extension;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using HandyControl.Controls;
using static System.Windows.Forms.AxHost;

namespace LoCyanFrpDesktop
{
Expand Down Expand Up @@ -144,20 +145,18 @@ private async void InitializeAutoLogin()

private async Task<bool> CheckLogined()
{
string path = ".//session.token";
string path = "./UserConfig/Information.json";
if (!File.Exists(path))
{
return false;
}
else
{
string[] token_split;
try
{
char[] delimiters = { '|' };
token_split = File.ReadAllText(path).Split(delimiters);
username_auto = token_split[0];
token_auto = token_split[1];
var PathObject = JsonConvert.DeserializeObject<PathObject>(File.ReadAllText(path));
username_auto = PathObject.Username;
token_auto = PathObject.Token;
}
catch
{
Expand Down Expand Up @@ -235,8 +234,9 @@ public async Task Login(string username, string password)
Properties.Settings.Default.LoginToken = responseObject.Token;
Properties.Settings.Default.username = responseObject.UserData.Username;
Properties.Settings.Default.FrpToken = responseObject.UserData.FrpToken;
string path = ".//session.token";
string text = $"{responseObject.UserData.Username}|{responseObject.Token}";
string path = "./UserConfig/Information.json";
string text = $"{{\n \"Username\": \"{responseObject.UserData.Username}\",\n \"Token\": \"{responseObject.Token}\"\n}}";
Directory.CreateDirectory("./UserConfig");
File.WriteAllText(path, text);
islogin = true;
DashBoard = new DashBoard();
Expand Down Expand Up @@ -438,4 +438,10 @@ public class UserData
public string? Avatar { get; set; }
}

}
public class PathObject
{
public string Username { get; set; }

Check warning on line 443 in LoCyanFrpDesktop/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Non-nullable property 'Username' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string Token { get; set; }

Check warning on line 444 in LoCyanFrpDesktop/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows

Non-nullable property 'Token' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}

}

0 comments on commit 9dfd2db

Please sign in to comment.