12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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.Settings.Password = user.Password;
- new LocalConfiguration<ConnectionSettings>().Save(App.Settings);
- }
- 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;
- }
- }
- }
|