m
This commit is contained in:
parent
ea202d0a8e
commit
82e9a7d1ee
@ -15,12 +15,10 @@ namespace SafeMessageStorage.Pages
|
|||||||
public partial class ChangePasswordPage : ContentPage
|
public partial class ChangePasswordPage : ContentPage
|
||||||
{
|
{
|
||||||
private ChangePasswordViewModel _viewModel => this.BindingContext as ChangePasswordViewModel;
|
private ChangePasswordViewModel _viewModel => this.BindingContext as ChangePasswordViewModel;
|
||||||
private IMessageStorageService _messageStorage;
|
|
||||||
public ChangePasswordPage(IAuthorizationService authorizationService, IMessageStorageService messageStorage)
|
public ChangePasswordPage(IAuthorizationService authorizationService, IMessageStorageService messageStorage)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
BindingContext = new ChangePasswordViewModel(authorizationService);
|
BindingContext = new ChangePasswordViewModel(authorizationService,messageStorage);
|
||||||
_messageStorage = messageStorage;
|
|
||||||
|
|
||||||
_viewModel.PasswordSetFailed += _viewModel_PasswordSetFailed;
|
_viewModel.PasswordSetFailed += _viewModel_PasswordSetFailed;
|
||||||
_viewModel.PasswordSetSucceeded += _viewModel_PasswordSetSucceeded;
|
_viewModel.PasswordSetSucceeded += _viewModel_PasswordSetSucceeded;
|
||||||
@ -29,7 +27,6 @@ namespace SafeMessageStorage.Pages
|
|||||||
|
|
||||||
private async void _viewModel_PasswordSetSucceeded(object sender, EventArgs e)
|
private async void _viewModel_PasswordSetSucceeded(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await _messageStorage.DeleteAllMessagesAsync();
|
|
||||||
await Navigation.PopAsync();
|
await Navigation.PopAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ namespace SafeMessageStorage.Services.MessageStorageService
|
|||||||
|
|
||||||
public async Task<bool> DeleteAllMessagesAsync()
|
public async Task<bool> DeleteAllMessagesAsync()
|
||||||
{
|
{
|
||||||
CheckIfAuthorized();
|
//CheckIfAuthorized();
|
||||||
return Xamarin.Essentials.SecureStorage.Remove(_messagesKey);
|
return Xamarin.Essentials.SecureStorage.Remove(_messagesKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using SafeMessageStorage.Services.AuthorizationService;
|
using SafeMessageStorage.Services.AuthorizationService;
|
||||||
|
using SafeMessageStorage.Services.MessageStorageService;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace SafeMessageStorage.ViewModels
|
namespace SafeMessageStorage.ViewModels
|
||||||
@ -10,10 +11,12 @@ namespace SafeMessageStorage.ViewModels
|
|||||||
public class ChangePasswordViewModel : ViewModelBase
|
public class ChangePasswordViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private IAuthorizationService _authorizationService;
|
private IAuthorizationService _authorizationService;
|
||||||
|
private IMessageStorageService _messageStorage;
|
||||||
|
|
||||||
public ChangePasswordViewModel(IAuthorizationService authorizationService)
|
public ChangePasswordViewModel(IAuthorizationService authorizationService, IMessageStorageService messageStorage)
|
||||||
{
|
{
|
||||||
_authorizationService = authorizationService;
|
_authorizationService = authorizationService;
|
||||||
|
_messageStorage = messageStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _currentPassword;
|
private string _currentPassword;
|
||||||
@ -45,6 +48,7 @@ namespace SafeMessageStorage.ViewModels
|
|||||||
|
|
||||||
private async void SetPassword(string currentPassword, string password, string repeatPassword)
|
private async void SetPassword(string currentPassword, string password, string repeatPassword)
|
||||||
{
|
{
|
||||||
|
var oldData = await _messageStorage.ReadMessagesAsync();
|
||||||
if(!await _authorizationService.AuthorizeAsync(currentPassword))
|
if(!await _authorizationService.AuthorizeAsync(currentPassword))
|
||||||
PasswordSetFailed?.Invoke(this, "Current password doesn't match");
|
PasswordSetFailed?.Invoke(this, "Current password doesn't match");
|
||||||
|
|
||||||
@ -55,7 +59,16 @@ namespace SafeMessageStorage.ViewModels
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (await _authorizationService.ChangePasswordAsync(currentPassword, password))
|
if (await _authorizationService.ChangePasswordAsync(currentPassword, password))
|
||||||
|
{
|
||||||
|
await _messageStorage.DeleteAllMessagesAsync();
|
||||||
|
foreach (var message in oldData)
|
||||||
|
{
|
||||||
|
await _messageStorage.SaveMessageAsync(message);
|
||||||
|
}
|
||||||
|
|
||||||
PasswordSetSucceeded?.Invoke(this, EventArgs.Empty);
|
PasswordSetSucceeded?.Invoke(this, EventArgs.Empty);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user