
Connected the login form button to the Authentication endpoint (/token). Gets back bearer token or exception if failed
72 lines
1.6 KiB
C#
72 lines
1.6 KiB
C#
using Caliburn.Micro;
|
|
using RMWPFUserInterface.Helpers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RMWPFUserInterface.ViewModels
|
|
{
|
|
public class LoginViewModel : Screen
|
|
{
|
|
private string _userName;
|
|
private string _password;
|
|
private IAPIHelper _apiHelper;
|
|
|
|
public LoginViewModel(IAPIHelper apiHelper)
|
|
{
|
|
_apiHelper = apiHelper;
|
|
}
|
|
public string UserName
|
|
{
|
|
get { return _userName; }
|
|
set
|
|
{
|
|
_userName = value;
|
|
NotifyOfPropertyChange(() => UserName);
|
|
NotifyOfPropertyChange(() => CanLogIn);
|
|
}
|
|
}
|
|
|
|
public string Password
|
|
{
|
|
get { return _password; }
|
|
set
|
|
{
|
|
_password = value;
|
|
NotifyOfPropertyChange(() => Password);
|
|
NotifyOfPropertyChange(() => CanLogIn);
|
|
}
|
|
}
|
|
|
|
public bool CanLogIn
|
|
{
|
|
get{
|
|
|
|
bool output = false;
|
|
|
|
if (UserName?.Length > 0 && Password?.Length > 0)
|
|
{
|
|
output = true;
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
}
|
|
|
|
public async Task LogIn()
|
|
{
|
|
try
|
|
{
|
|
var result = await _apiHelper.Authenticate(UserName, Password);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|