-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logout button & Password edit control in settings
- Loading branch information
Showing
15 changed files
with
594 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Source/Fasetto.Word.Core/ViewModel/Input/Design/PasswordEntryDesignModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Fasetto.Word.Core | ||
{ | ||
/// <summary> | ||
/// The design-time data for a <see cref="PasswordEntryViewModel"/> | ||
/// </summary> | ||
public class PasswordEntryDesignModel : PasswordEntryViewModel | ||
{ | ||
#region Singleton | ||
|
||
/// <summary> | ||
/// A single instance of the design model | ||
/// </summary> | ||
public static PasswordEntryDesignModel Instance => new PasswordEntryDesignModel(); | ||
|
||
#endregion | ||
|
||
#region Constructor | ||
|
||
/// <summary> | ||
/// Default Constructor | ||
/// </summary> | ||
public PasswordEntryDesignModel() | ||
{ | ||
Label = "Name"; | ||
FakePassword = "********"; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
184 changes: 184 additions & 0 deletions
184
Source/Fasetto.Word.Core/ViewModel/Input/PasswordEntryViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
using System.Security; | ||
using System.Windows.Input; | ||
|
||
namespace Fasetto.Word.Core | ||
{ | ||
/// <summary> | ||
/// The view model for a password entry to edit a password | ||
/// <summary> | ||
public class PasswordEntryViewModel : BaseViewModel | ||
{ | ||
#region Public Properties | ||
|
||
/// <summary> | ||
/// The label to identify what this value is for | ||
/// </summary> | ||
public string Label { get; set; } | ||
|
||
/// <summary> | ||
/// The fake password display string | ||
/// </summary> | ||
public string FakePassword { get; set; } | ||
|
||
/// <summary> | ||
/// The current password hint text | ||
/// </summary> | ||
public string CurrentPasswordHintText { get; set; } | ||
|
||
/// <summary> | ||
/// The new password hint text | ||
/// </summary> | ||
public string NewPasswordHintText { get; set; } | ||
|
||
/// <summary> | ||
/// The confirm password hint text | ||
/// </summary> | ||
public string ConfirmPasswordHintText { get; set; } | ||
|
||
/// <summary> | ||
/// The current saved password | ||
/// </summary> | ||
public SecureString CurrentPassword { get; set; } | ||
|
||
/// <summary> | ||
/// The current non-commit edited password | ||
/// </summary> | ||
public SecureString NewPassword { get; set; } | ||
|
||
/// <summary> | ||
/// The current non-commit edited confirmed password | ||
/// </summary> | ||
public SecureString ConfirmPassword { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the current text is in edit mode | ||
/// </summary> | ||
public bool Editing { get; set; } | ||
|
||
#endregion | ||
|
||
#region Public Commands | ||
|
||
/// <summary> | ||
/// Puts the control into edit mode | ||
/// </summary> | ||
public ICommand EditCommand { get; set; } | ||
|
||
/// <summary> | ||
/// Cancels out of edit mode | ||
/// </summary> | ||
public ICommand CancelCommand { get; set; } | ||
|
||
/// <summary> | ||
/// Commits the edits and saves the value | ||
/// as well as goes back to non-edit mode | ||
/// </summary> | ||
public ICommand SaveCommand { get; set; } | ||
|
||
#endregion | ||
|
||
#region Constructor | ||
|
||
/// <summary> | ||
/// Default constructor | ||
/// </summary> | ||
public PasswordEntryViewModel() | ||
{ | ||
// Create commands | ||
EditCommand = new RelayCommand(Edit); | ||
CancelCommand = new RelayCommand(Cancel); | ||
SaveCommand = new RelayCommand(Save); | ||
|
||
// Set default hints | ||
// TODO: Replace with localization text | ||
CurrentPasswordHintText = "Current Password"; | ||
NewPasswordHintText = "New Password"; | ||
ConfirmPasswordHintText = "Confirm Password"; | ||
} | ||
|
||
#endregion | ||
|
||
#region Command Methods | ||
|
||
/// <summary> | ||
/// Puts the control into edit mode | ||
/// </summary> | ||
public void Edit() | ||
{ | ||
// Clear all password | ||
NewPassword = new SecureString(); | ||
ConfirmPassword = new SecureString(); | ||
|
||
// Go into edit mode | ||
Editing = true; | ||
} | ||
|
||
/// <summary> | ||
/// Cancels out of edit mode | ||
/// </summary> | ||
public void Cancel() | ||
{ | ||
Editing = false; | ||
} | ||
|
||
/// <summary> | ||
/// Commits the content and exits out of edit mode | ||
/// </summary> | ||
public void Save() | ||
{ | ||
// Make sure current password is correct | ||
// TODO: This will come from the real back-end store of this users password | ||
// or via asking the web server to confirm it | ||
var storedPassword = "Testing"; | ||
|
||
// Confirm current password is a match | ||
// NOTE: Typically this isn't done here, it's done on the server | ||
if (storedPassword != CurrentPassword.Unsecure()) | ||
{ | ||
// Let user know | ||
IoC.UI.ShowMessage(new MessageBoxDialogViewModel | ||
{ | ||
Title = "Wrong password", | ||
Message = "The current password is invalid" | ||
}); | ||
|
||
return; | ||
} | ||
|
||
// Now check that the new and confirm password match | ||
if (NewPassword.Unsecure() != ConfirmPassword.Unsecure()) | ||
{ | ||
// Let user know | ||
IoC.UI.ShowMessage(new MessageBoxDialogViewModel | ||
{ | ||
Title = "Password mismatch", | ||
Message = "The new and confirm password do not match" | ||
}); | ||
|
||
return; | ||
} | ||
|
||
// Check we actually have a password | ||
if (NewPassword.Unsecure().Length == 0) | ||
{ | ||
// Let user know | ||
IoC.UI.ShowMessage(new MessageBoxDialogViewModel | ||
{ | ||
Title = "Password too short", | ||
Message = "You must enter a password!" | ||
}); | ||
|
||
return; | ||
} | ||
|
||
// Set the edited password to the current value | ||
CurrentPassword = new SecureString(); | ||
foreach (var c in NewPassword.Unsecure().ToCharArray()) | ||
CurrentPassword.AppendChar(c); | ||
|
||
Editing = false; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.