-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUserProfileWindow.xaml.cs
More file actions
138 lines (126 loc) · 5.36 KB
/
UserProfileWindow.xaml.cs
File metadata and controls
138 lines (126 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using FlamyPOS.Data;
using FlamyPOS.Models;
using FlamyPOS.Utilities;
using FlamyPOS.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace FlamyPOS
{
/// <summary>
/// Interaction logic for UserProfileWindow.xaml
/// </summary>
public partial class UserProfileWindow : Window
{
public UserProfileWindow()
{
InitializeComponent();
DataContext = Mains.UserProfileVM;
}
private void Change_Passcode_ButtonClick(object sender, RoutedEventArgs e)
{
if (String.IsNullOrWhiteSpace(CurrentPasscodeBox.Password) ||
String.IsNullOrWhiteSpace(NewPasscodeBox.Password) ||
String.IsNullOrWhiteSpace(ConfirmPasscodeBox.Password))
{
MessageBox.Show("Please fill in all the columns!", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
return;
}
if (!Helpers.IsNumericString(CurrentPasscodeBox.Password) ||
!Helpers.IsNumericString(NewPasscodeBox.Password) ||
!Helpers.IsNumericString(ConfirmPasscodeBox.Password))
{
MessageBox.Show("Must contain numeric passcodes only!", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
return;
}
Staff user = Mains.UserProfileVM.CurrentUser;
string hashedPasscodeInput = Security.GetHash(CurrentPasscodeBox.Password);
/*Mains.LoginVM.StaffDictionary*/ //Passcode ... StaffID
string currentHashedPasscode = Mains.LoginVM.StaffDictionary
.FirstOrDefault(x => x.Value == user.Id)
.Key;
if (hashedPasscodeInput != currentHashedPasscode)
{
MessageBox.Show("Please enter the correct passcode!");
return;
}
if (NewPasscodeBox.Password != ConfirmPasscodeBox.Password)
{
MessageBox.Show("New passcode and Confirm passcode must match!", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
return;
}
string hashedNewPasscode = Security.GetHash(NewPasscodeBox.Password);
bool status = Database.UpdatePasscode(user.Name, hashedNewPasscode);
if (status)
{
Mains.LoginVM.StaffDictionary.Remove(Security.GetHash(CurrentPasscodeBox.Password));
Mains.LoginVM.StaffDictionary.Add(hashedNewPasscode, user.Id);
MessageBox.Show("Password changed successfully!", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Information);
CurrentPasscodeBox.Clear();
NewPasscodeBox.Clear();
ConfirmPasscodeBox.Clear();
}
else
{
MessageBox.Show("Duplicate passcode!", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
}
private void DeleteAccountButton_Click(object sender, RoutedEventArgs e)
{
Staff user = Mains.UserProfileVM.CurrentUser;
string passcode = DeleteAccountPasswordBox.Password;
if (String.IsNullOrWhiteSpace(passcode))
{
return;
}
if (user.IsAdmin)
{
bool onlyOneAdminRemaining = Mains.AdminVM.StaffList.Count(x => x.IsAdmin) == 1;
if (onlyOneAdminRemaining)
{
MessageBox.Show("Can't delete the only one admin!", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
DeleteAccountPasswordBox.Clear();
return;
}
}
string hashedPasscodeInput = Security.GetHash(passcode);
/*Mains.LoginVM.StaffDictionary*/ //Passcode ... StaffID
string currentHashedPasscode = Mains.LoginVM.StaffDictionary
.FirstOrDefault(x => x.Value == user.Id)
.Key;
if (hashedPasscodeInput != currentHashedPasscode)
{
MessageBox.Show("Wrong passcode input!", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
return;
}
else
{
bool status = Database.UpdateStaffPosition(user.Name, Access.Disabled);
if (!status)
{
MessageBox.Show("Failed to remove account", "FlamyPOS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
else
{
var list = Mains.AdminVM.StaffList
.Where(x => x.Name != user.Name)
.ToList();
Mains.AdminVM.StaffList = new ObservableCollection<Staff>(list);
new MainWindow().Show();
this.Close();
}
}
}
}
}