Handle settings at service level, avoid getting settings whenever testing auth
This commit is contained in:
parent
9f42c891de
commit
f10fab0fa9
1 changed files with 19 additions and 19 deletions
|
|
@ -10,9 +10,11 @@ namespace LANCommander.Client.Services
|
|||
public class ProfileService
|
||||
{
|
||||
private readonly SDK.Client Client;
|
||||
private Settings Settings;
|
||||
|
||||
public ProfileService(SDK.Client client) {
|
||||
Client = client;
|
||||
Settings = SettingService.GetSettings();
|
||||
}
|
||||
|
||||
public async Task Login(string serverAddress, string username, string password)
|
||||
|
|
@ -21,55 +23,53 @@ namespace LANCommander.Client.Services
|
|||
|
||||
var token = await Client.AuthenticateAsync(username, password);
|
||||
|
||||
var settings = SettingService.GetSettings();
|
||||
Settings = SettingService.GetSettings();
|
||||
|
||||
settings.Authentication.ServerAddress = serverAddress;
|
||||
settings.Authentication.AccessToken = token.AccessToken;
|
||||
settings.Authentication.RefreshToken = token.RefreshToken;
|
||||
Settings.Authentication.ServerAddress = serverAddress;
|
||||
Settings.Authentication.AccessToken = token.AccessToken;
|
||||
Settings.Authentication.RefreshToken = token.RefreshToken;
|
||||
|
||||
SettingService.SaveSettings(settings);
|
||||
SettingService.SaveSettings(Settings);
|
||||
|
||||
var remoteProfile = await Client.Profile.GetAsync();
|
||||
|
||||
settings.Profile.Id = remoteProfile.Id;
|
||||
settings.Profile.Alias = String.IsNullOrWhiteSpace(remoteProfile.Alias) ? remoteProfile.UserName : remoteProfile.Alias;
|
||||
Settings.Profile.Id = remoteProfile.Id;
|
||||
Settings.Profile.Alias = String.IsNullOrWhiteSpace(remoteProfile.Alias) ? remoteProfile.UserName : remoteProfile.Alias;
|
||||
|
||||
var tempAvatarPath = await Client.Profile.DownloadAvatar();
|
||||
|
||||
if (File.Exists(tempAvatarPath))
|
||||
settings.Profile.Avatar = Convert.ToBase64String(await File.ReadAllBytesAsync(tempAvatarPath));
|
||||
Settings.Profile.Avatar = Convert.ToBase64String(await File.ReadAllBytesAsync(tempAvatarPath));
|
||||
|
||||
SettingService.SaveSettings(settings);
|
||||
SettingService.SaveSettings(Settings);
|
||||
}
|
||||
|
||||
public async Task Logout()
|
||||
{
|
||||
await Client.LogoutAsync();
|
||||
|
||||
var settings = SettingService.GetSettings();
|
||||
Settings = SettingService.GetSettings();
|
||||
|
||||
settings.Profile = new ProfileSettings();
|
||||
settings.Authentication = new AuthenticationSettings();
|
||||
Settings.Profile = new ProfileSettings();
|
||||
Settings.Authentication = new AuthenticationSettings();
|
||||
|
||||
SettingService.SaveSettings(settings);
|
||||
SettingService.SaveSettings(Settings);
|
||||
}
|
||||
|
||||
public async Task ChangeAlias(string newName)
|
||||
{
|
||||
await Client.Profile.ChangeAliasAsync(newName);
|
||||
|
||||
var settings = SettingService.GetSettings();
|
||||
Settings = SettingService.GetSettings();
|
||||
|
||||
settings.Profile.Alias = newName;
|
||||
Settings.Profile.Alias = newName;
|
||||
|
||||
SettingService.SaveSettings(settings);
|
||||
SettingService.SaveSettings(Settings);
|
||||
}
|
||||
|
||||
public bool IsAuthenticated()
|
||||
{
|
||||
var settings = SettingService.GetSettings();
|
||||
|
||||
return !String.IsNullOrWhiteSpace(settings.Authentication.AccessToken);
|
||||
return !String.IsNullOrWhiteSpace(Settings.Authentication.AccessToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue