-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
85 lines (74 loc) · 2.84 KB
/
User.java
File metadata and controls
85 lines (74 loc) · 2.84 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
import javax.swing.*;
import java.util.Objects;
public abstract class User {
protected DBConnect db;
protected Integer id;
protected String username;
protected Integer ManagedBy;
protected String email;
protected String password;
protected String firstName;
protected String lastName;
protected String gender;
protected String dob;
protected String userType;
public void updatePass(JPanel panel1, JFrame frame) {
panel1.setVisible(false);
JPanel panel2 = new JPanel();
frame.setSize(400,400);
panel2.setLayout(null);
panel2.setVisible(true);
JLabel password = new JLabel("Password:");
password.setBounds(50,10,300,30);
JLabel password2 = new JLabel("Confirm password:");
password2.setBounds(50,90,300,30);
JPasswordField passwordf = new JPasswordField();
passwordf.setBounds(50,40,300,30);
JPasswordField password2f = new JPasswordField();
password2f.setBounds(50,120,300,30);
JButton submit = new JButton();
submit.setText("Change Password");
submit.setBounds(120,200,160,50);
submit.addActionListener(e -> updatePassword2(passwordf.getText(), password2f.getText(), getType(), frame));
frame.add(panel2);
panel2.add(password);
panel2.add(password2);
panel2.add(passwordf);
panel2.add(password2f);
panel2.add(submit);
}
public void updatePassword2(String p1, String p2, String type, JFrame frame) {
Driver d = new Driver();
if(!Objects.equals(p1, p2)){
JOptionPane.showMessageDialog(null, "Your passwords do not match", "Error", JOptionPane.ERROR_MESSAGE);
return;
} else {
int check = db.write("UPDATE User SET password = '" + p1 + "' WHERE User_id = " + id + ";");
if(check == 0) {
password = p1;
JOptionPane.showMessageDialog(null, "Password Updated", "Success", JOptionPane.PLAIN_MESSAGE);
}
String[] result = db.read("SELECT * FROM User WHERE User_Id = " + id + ";");
if (Objects.equals(type, "Student")) {
frame.setVisible(false);
frame.dispose();
Student s = new Student(result, db);
d.student(s);
return;
} else if (Objects.equals(type, "Lecturer")) {
frame.setVisible(false);
frame.dispose();
Lecturer l = new Lecturer(result, db);
d.lecturer(l);
return;
} else {
frame.setVisible(false);
frame.dispose();
Manager m = new Manager(result, db);
d.manager(m);
return;
}
}
}
public String getType() {return userType;}
}