Created login and error handling to get auth token. Refreshing not handled.

This commit is contained in:
Patrick Fic
2020-01-16 18:43:50 -08:00
parent 0daf17a3f0
commit cfec5327dd
17 changed files with 625 additions and 47 deletions

View File

@@ -1,24 +1,24 @@
using System;
using System.Windows;
using System.Windows.Input;
namespace BodyshopUploader.ViewModels
{
public partial class LoginViewModel : BaseViewModel
{
private ICommand _openMainCommand;
public ICommand OpenMainCommand
private ICommand _loginCommand;
public ICommand LoginCommand
{
get
{
if (_openMainCommand == null)
if (_loginCommand == null)
{
_openMainCommand = new RelayCommand(
p => true,
p => { Views.Main m = new Views.Main(); m.Show(); });
_loginCommand = new RelayCommand(
p => !string.IsNullOrEmpty(UserName) && UserPassword?.Length > 6,
async p => { await LoginAsync(p as Window); });
}
return _openMainCommand;
return _loginCommand;
}
}
}
}

View File

@@ -1,18 +1,37 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace BodyshopUploader.ViewModels
{
{
public partial class LoginViewModel : BaseViewModel
{
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public LoginViewModel()
{
logger.Trace("We're in boys.");
logger.Trace("Login VM Created.");
}
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;
}
}
}

View File

@@ -2,25 +2,47 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
namespace BodyshopUploader.ViewModels
{
public partial class LoginViewModel: BaseViewModel
public partial class LoginViewModel : BaseViewModel
{
private ObservableCollection<string> _invoiceList;
public ObservableCollection<string> InvoiceList
private string _userName = Properties.Settings.Default.Username;
public string UserName
{
get { return _invoiceList; }
set { SetProperty(ref _invoiceList, value); }
get { return _userName; }
set { SetProperty(ref _userName, value); }
}
private int _progress = 5;
public int Progress
private SecureString _userPassword = Properties.Settings.Default.Password;
public SecureString UserPassword
{
get { return _progress; }
set { SetProperty(ref _progress, value); }
get { return _userPassword; }
set { SetProperty(ref _userPassword, value); }
}
private bool _error = false;
public bool Error
{
get { return _error; }
set { SetProperty(ref _error, value); }
}
private string _errorMsg;
public string ErrorMsg
{
get { return _errorMsg; }
set { SetProperty(ref _errorMsg, value); }
}
private bool _loading = false;
public bool Loading
{
get { return _loading; }
set { SetProperty(ref _loading, value); }
}
}
}