-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminModule.java
More file actions
150 lines (116 loc) · 3.96 KB
/
Copy pathAdminModule.java
File metadata and controls
150 lines (116 loc) · 3.96 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
139
140
141
142
143
144
145
146
147
148
149
150
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import Basic.Member;
import Basic.User;
import Basic.Utility;
import Common.DBQuery;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
public class AdminModule {
private LoginView login;
public boolean authStatus = false;
private JPanel panel;
private JButton submitButton;
private JLabel label0;
private JTextField passwordField;
private static JFrame loginFrame;
private JButton btnRegister;
private JLabel lblNewLabel;
private JTextField usernameField;
private static RegisterMemberView fRegister;
private static DBQuery dp;
public static void main(String args[]) {
AdminModule am = new AdminModule();
dp = new DBQuery();
fRegister = new RegisterMemberView(am);
am.run();
}
public void run() {
System.out.println(Utility.getHash("password"));
loginFrame = new JFrame();
loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loginFrame.setBounds(100, 100, 450, 300);
panel = new JPanel();
//panel.setBounds(0, 0, 450, 278);
label0 = new JLabel("Password");
label0.setBounds(24, 103, 101, 28);
passwordField = new JTextField();
passwordField.setBounds(121, 96, 323, 43);
submitButton = new JButton("Log in");
submitButton.setBounds(167, 159, 117, 51);
submitButton.addActionListener(new SubmitButtonListener());
loginFrame.getContentPane().setLayout(new BorderLayout(0, 0));
panel.setLayout(null);
panel.add(label0);
panel.add(passwordField);
panel.add(submitButton);
panel.setBorder(BorderFactory.createTitledBorder("Login"));
//panel.setLayout(new GridLayout(3,2));
panel.setBackground(Color.white);
loginFrame.getContentPane().add(panel);
btnRegister = new JButton("Register");
btnRegister.addActionListener(new ButtonRegisterListener());
btnRegister.setBounds(167, 212, 117, 51);
panel.add(btnRegister);
lblNewLabel = new JLabel("Username");
lblNewLabel.setBounds(24, 47, 81, 28);
panel.add(lblNewLabel);
usernameField = new JTextField();
usernameField.setBounds(121, 40, 323, 43);
panel.add(usernameField);
usernameField.setColumns(10);
//loginFrame.setLocationRelativeTo(c);
//System.out.println(loginFrame.getLocationOnScreen());
//loginFrame.pack();
//loginFrame.setPreferredSize(new Dimension(400, 300));
//loginFrame.pack();
loginFrame.setLocationRelativeTo(null);
loginFrame.setVisible(true);
}
private class SubmitButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String username = usernameField.getText();
String password = passwordField.getText();
String hashedPassword = Utility.getHash(password);
User logInUser;
try {
logInUser = dp.authenticateMember(username, hashedPassword);
if (logInUser!=null){
loginFrame.setVisible(false);
DataPool playerPool = new DataPool();
AdminController controller = new AdminController(logInUser, playerPool);
AdminView view = new AdminView(logInUser, controller);
controller.attachView(view);
controller.run();
}
else JOptionPane.showMessageDialog(panel, "Log in failed!","Information", JOptionPane.PLAIN_MESSAGE);
} catch (Exception ex) {
JOptionPane.showMessageDialog(panel, ex.getMessage(),"Information", JOptionPane.PLAIN_MESSAGE);
}
}
}
private class ButtonRegisterListener implements ActionListener{
public void actionPerformed(ActionEvent e){
fRegister.setVisible(true);
loginFrame.setVisible(false);
}
}
public void viewLoginFrame(){
fRegister.setVisible(false);
loginFrame.setVisible(true);
}
}