| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- namespace comal.timesheets
- {
- public delegate void PasswordResetEvent();
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class PasswordResetPage : ContentPage
- {
- public event PasswordResetEvent OnPasswordReset;
- private User user;
- public PasswordResetPage(string userid)
- {
- InitializeComponent();
- Task.Run(() =>
- {
- ClientFactory.SetBypass();
- CoreTable table = new Client<User>().Query(new Filter<User>(x => x.UserID).IsEqualTo(userid));
- if (table.Rows.Any())
- {
- user = table.Rows.FirstOrDefault().ToObject<User>();
- }
- else
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- DisplayAlert("Error", "User not found", "OK");
- });
- }
- });
- }
- private async void SaveNewPassword_Clicked(object sender, EventArgs e)
- {
- bool bOK = CheckPasswordValidity();
- if (user.ID != Guid.Empty && bOK)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Saving"))
- {
- user.Password = newPasswordEnt1.Text;
- new Client<User>().Save(user, "Password updated by User from Timebench");
- ClientFactory.UnsetBypass();
- App.DBSettings.Password = user.Password;
- new LocalConfiguration<DatabaseSettings>().Save(App.DBSettings);
- }
- DisplayAlert("Success", "Password changed", "OK");
- Navigation.PopAsync();
- OnPasswordReset?.Invoke();
- }
- }
- private bool CheckPasswordValidity()
- {
- if (string.IsNullOrWhiteSpace(newPasswordEnt1.Text) || string.IsNullOrWhiteSpace(newPasswordEnt2.Text))
- {
- DisplayAlert("Error", "Password entries may not be blank", "OK");
- return false;
- }
- if (newPasswordEnt1.Text.Length < 5 || newPasswordEnt2.Text.Length < 5)
- {
- DisplayAlert("Error", "Passwords must be at least 5 characters", "OK");
- return false;
- }
- if (newPasswordEnt1.Text != newPasswordEnt2.Text)
- {
- DisplayAlert("Error", "Passwords do not match", "OK");
- return false;
- }
- return true;
- }
- }
- }
|