aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs170
1 files changed, 5 insertions, 165 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
index f4645ecf2..cf34764d9 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs
@@ -22,9 +22,6 @@ using Tango.MachineStudio.UI.Messages;
using Tango.Settings;
using Tango.SharedUI;
using Tango.Web;
-using SimpleValidator.Extensions;
-using Tango.BL.Entities;
-using System.Data.Entity;
namespace Tango.MachineStudio.UI.ViewModels
{
@@ -41,7 +38,6 @@ namespace Tango.MachineStudio.UI.ViewModels
private Rfc2898Cryptographer cryptographer;
private MachineStudioSettings _settings;
private MachineStudioWebClient _machineStudioWebClient;
- private TaskCompletionSource<object> _updatePasswordCompletionSource;
private String _email;
/// <summary>
@@ -86,14 +82,6 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _isLogging = value; RaisePropertyChangedAuto(); }
}
- private bool _showLogginDetails;
- public bool ShowLoggingDetails
- {
- get { return _showLogginDetails; }
- set { _showLogginDetails = value; RaisePropertyChangedAuto(); }
- }
-
-
private bool _rememberMe;
/// <summary>
/// Gets or sets a value indicating whether to remember the last user email and password.
@@ -114,47 +102,6 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _enableSlotSelection = value; RaisePropertyChangedAuto(); }
}
- private bool _isActiveDirectory;
- public bool IsActiveDirectory
- {
- get { return _isActiveDirectory; }
- set { _isActiveDirectory = value; RaisePropertyChangedAuto(); if (value) IsStandardUser = false; }
- }
-
- private bool _isStandardUser;
- public bool IsStandardUser
- {
- get { return _isStandardUser; }
- set { _isStandardUser = value; RaisePropertyChangedAuto(); if (value) IsActiveDirectory = false; }
- }
-
- private String _progressLog;
- public String ProgressLog
- {
- get { return _progressLog; }
- set { _progressLog = value; RaisePropertyChangedAuto(); }
- }
-
- private bool _isChangingPassword;
- public bool IsChangingPassword
- {
- get { return _isChangingPassword; }
- set { _isChangingPassword = value; RaisePropertyChangedAuto(); }
- }
-
- private String _newPassword1;
- public String NewPassword1
- {
- get { return _newPassword1; }
- set { _newPassword1 = value; RaisePropertyChangedAuto(); }
- }
-
- private String _newPassword2;
- public String NewPassword2
- {
- get { return _newPassword2; }
- set { _newPassword2 = value; RaisePropertyChangedAuto(); }
- }
/// <summary>
/// Gets or sets the login command.
@@ -162,11 +109,6 @@ namespace Tango.MachineStudio.UI.ViewModels
public RelayCommand LoginCommand { get; set; }
/// <summary>
- /// Gets or sets the update password command.
- /// </summary>
- public RelayCommand UpdatePasswordCommand { get; set; }
-
- /// <summary>
/// Initializes a new instance of the <see cref="LoginViewVM"/> class.
/// </summary>
/// <param name="authenticationProvider">The authentication provider.</param>
@@ -175,7 +117,6 @@ namespace Tango.MachineStudio.UI.ViewModels
public LoginViewVM(MachineStudioWebClient machineStudioWebClient, IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger)
{
EnableSlotSelection = true;
- ShowLoggingDetails = true;
_machineStudioWebClient = machineStudioWebClient;
_settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>();
@@ -185,22 +126,12 @@ namespace Tango.MachineStudio.UI.ViewModels
_authenticationProvider = authenticationProvider;
_eventLogger = eventLogger;
LoginCommand = new RelayCommand(Login, () => !IsLogging);
- UpdatePasswordCommand = new RelayCommand(UpdatePassword, () => IsChangingPassword);
cryptographer = new Rfc2898Cryptographer();
Email = _settings.LastLoginEmail;
DeploymentSlot = _settings.DeploymentSlot;
RememberMe = _settings.RememberMe;
- if (_settings.LastLoginMethod == LoginMethod.ActiveDirectory)
- {
- IsActiveDirectory = true;
- }
- else
- {
- IsStandardUser = true;
- }
-
try
{
Password = cryptographer.Decrypt(_settings.LastLoginPassword);
@@ -221,22 +152,13 @@ namespace Tango.MachineStudio.UI.ViewModels
try
{
IsLogging = true;
- ShowLoggingDetails = false;
- NewPassword1 = String.Empty;
- NewPassword2 = String.Empty;
-
InvalidateRelayCommands();
- LoginMethod loginMethod = IsActiveDirectory ? LoginMethod.ActiveDirectory : LoginMethod.StandardUser;
-
await Task.Factory.StartNew(() =>
{
_settings.DeploymentSlot = DeploymentSlot;
- LoginResponse result = _authenticationProvider.Login(Email, Password, loginMethod, _settings.ByPassEnvironmentVersionCheck, (progress) =>
- {
- ProgressLog = progress;
- }).Response;
+ LoginResponse result = _authenticationProvider.Login(Email, Password, _settings.ByPassEnvironmentVersionCheck).Response;
if (result.VersionChangeRequired && !_settings.ByPassEnvironmentVersionCheck)
{
@@ -255,113 +177,31 @@ namespace Tango.MachineStudio.UI.ViewModels
return;
}
- if (result.PasswordChangeRequired)
- {
- StartUpdatePassword().Task.GetAwaiter().GetResult();
- Password = NewPassword1;
- Login();
- return;
- }
-
- //_eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!");
+ _eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!");
_navigationManager.NavigateTo(NavigationView.MainView);
_settings.LastLoginEmail = Email;
_settings.RememberMe = RememberMe;
- _settings.LastLoginMethod = loginMethod;
_settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null;
_settings.Save();
- EnableSlotSelection = false;
+ _eventLogger.Log("User logged in.");
- IsLogging = false;
- ShowLoggingDetails = true;
- IsChangingPassword = false;
- InvalidateRelayCommands();
+ EnableSlotSelection = false;
});
}
catch (Exception ex)
{
- IsLogging = false;
- ShowLoggingDetails = true;
- IsChangingPassword = false;
- InvalidateRelayCommands();
LogManager.Log(ex, "Login Error.");
_notificationProvider.ShowError($"An error occurred while trying to perform the log-in operation.\n{ex.FlattenMessage()}");
}
- }
- }
-
- private TaskCompletionSource<object> StartUpdatePassword()
- {
- _updatePasswordCompletionSource = new TaskCompletionSource<object>();
-
- IsChangingPassword = true;
- ShowLoggingDetails = false;
- IsLogging = false;
- InvalidateRelayCommands();
-
- return _updatePasswordCompletionSource;
- }
-
- private async void UpdatePassword()
- {
- await Task.Factory.StartNew(() =>
- {
- try
- {
- if (!Validate())
- {
- return;
- }
-
- ProgressLog = "Updating your password...";
- IsChangingPassword = false;
- IsLogging = true;
- InvalidateRelayCommands();
-
- using (var db = ObservablesContext.CreateDefault())
- {
- var user = db.Users.SingleOrDefault(x => x.Email == Email);
- user.PasswordChangeRequired = false;
- user.Password = User.GetPasswordHash(NewPassword1);
- db.SaveChanges();
- }
-
- _updatePasswordCompletionSource.SetResult(true);
- }
- catch (Exception ex)
- {
- IsLogging = false;
- IsChangingPassword = false;
- ShowLoggingDetails = true;
- InvalidateRelayCommands();
- _updatePasswordCompletionSource.SetException(ex);
- }
finally
{
+ IsLogging = false;
InvalidateRelayCommands();
}
- });
- }
-
- protected override void OnValidating()
- {
- if (IsChangingPassword)
- {
- if (!NewPassword1.IsBetweenLength(6, 8))
- {
- InsertError(nameof(NewPassword1), "Password must be 6 to 8 characters long");
- }
-
- if (NewPassword1 != NewPassword2)
- {
- InsertError(nameof(NewPassword2), "Passwords do not match");
- }
}
-
- base.OnValidating();
}
}
}