67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
|
|
namespace ProManagerPartner.ViewModels
|
|
{
|
|
public partial class LoginViewModel : BaseViewModel
|
|
{
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
public LoginViewModel()
|
|
{
|
|
logger.Trace("Login VM Created.");
|
|
|
|
AutoLogin();
|
|
|
|
|
|
}
|
|
|
|
private async Task AutoLogin()
|
|
{
|
|
Loading = true;
|
|
string AuthToken = Properties.Settings.Default.AuthToken;
|
|
string RefreshToken = Properties.Settings.Default.RefreshToken;
|
|
|
|
|
|
if (!String.IsNullOrEmpty(AuthToken) && !String.IsNullOrEmpty(RefreshToken))
|
|
{
|
|
//Attempt auto login.
|
|
logger.Debug("Good to attempt auto login.");
|
|
(Error, ErrorMsg) = await Utils.Auth.AutoLogin(AuthToken, RefreshToken);
|
|
if (ErrorMsg == null)
|
|
{
|
|
App.Current.MainWindow.Hide();
|
|
Views.Main m = new Views.Main();
|
|
m.Show();
|
|
|
|
}
|
|
|
|
}
|
|
Loading = false;
|
|
}
|
|
|
|
private async Task LoginAsync(Window W)
|
|
{
|
|
Loading = true;
|
|
|
|
Utils.LoginHelpers.SaveLoginSettings(UserName, UserPassword);
|
|
|
|
logger.Trace("Attempting to login as user: {0}", UserName);
|
|
(Error, ErrorMsg) = await Utils.Auth.LoginAsync(UserName, Utils.LoginHelpers.DecodePassword(UserPassword));
|
|
if (ErrorMsg == null)
|
|
{
|
|
Views.Main m = new Views.Main();
|
|
m.Show();
|
|
W.Hide();
|
|
}
|
|
Loading = false;
|
|
}
|
|
}
|
|
}
|