Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////// SESSION HANDLER
- package flightmanager;
- import model.UserModel;
- public class SessionHandler {
- /*
- * Create a session for user after loading all data from the database
- */
- public SQLHandler sql;
- private UserModel user;
- public SessionHandler(String name)
- {
- this.sql = new SQLHandler();
- //TODO: load mysql data
- user.setUserName(name);
- user.setIsAdmin(1);
- }
- public String getUserName()
- {
- return user.getUserName();
- }
- public int isadmin()
- {
- return user.getIsAdmin();
- }
- }
- /////////////////////////////////////// LOGIN
- package flightmanager;
- import java.awt.EventQueue;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import java.awt.BorderLayout;
- import javax.swing.JSplitPane;
- import javax.swing.JTabbedPane;
- import javax.swing.JTextField;
- import javax.swing.JTextArea;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.SwingConstants;
- import javax.swing.JPasswordField;
- import java.awt.Color;
- import javax.swing.JButton;
- public class Login {
- private JFrame frame;
- private JTextField textField;
- private JPasswordField passwordField;
- public static SessionHandler session;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Login window = new Login();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public Login() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setAutoRequestFocus(false);
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- textField = new JTextField();
- textField.setBounds(108, 88, 96, 20);
- frame.getContentPane().add(textField);
- textField.setColumns(10);
- JPanel panel = new JPanel();
- panel.setBackground(Color.DARK_GRAY);
- panel.setBounds(214, 0, 220, 261);
- frame.getContentPane().add(panel);
- JLabel lblNewLabel = new JLabel("ש� משתמש:");
- lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel.setBounds(108, 73, 96, 14);
- frame.getContentPane().add(lblNewLabel);
- JLabel label = new JLabel("סיסמ�:");
- label.setHorizontalAlignment(SwingConstants.RIGHT);
- label.setBounds(156, 119, 48, 14);
- frame.getContentPane().add(label);
- passwordField = new JPasswordField();
- passwordField.setBounds(108, 136, 96, 20);
- frame.getContentPane().add(passwordField);
- JButton loginButton = new JButton("התחברות");
- loginButton.setBounds(10, 197, 89, 23);
- frame.getContentPane().add(loginButton);
- loginButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- //get username and password fields
- String username = textField.getText().toString();
- String password = passwordField.getText().toString();
- //verify login
- if(!username.equals("admin") || !password.equals("admin"))
- {
- JOptionPane.showMessageDialog(null, "ש� משתמש/סיסמ� שגויי�!");
- passwordField.setText("");
- }
- else
- {
- JOptionPane.showMessageDialog(null, "!התחברת");
- session = new SessionHandler(username);
- MainDisplay s = new MainDisplay();
- frame.setVisible(false);
- MainDisplay main_display = new MainDisplay();
- main_display.frame.setVisible(true);
- }
- }
- });
- }
- }
- //////////// USER MODEL
- package model;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- @Entity
- public class UserModel {
- // data table model for a user
- @Id
- private int userId; // primary key field.
- private String userName; // Must Have field
- private String password; // Must have field. Needs authentication TODO
- private String email; // Must have field. Email
- private int isAdmin; // 0 = no, 1 = yes. tinyInt type.
- public UserModel(String _userName, String _password)
- {
- userName = _userName;
- password = _password;
- }
- public int getUserId() {
- return userId;
- }
- public void setUserId(int userId) {
- this.userId = userId;
- }
- public String getUserName() {
- return userName;
- }
- public void setUserName(String userName) {
- this.userName = userName;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public int getIsAdmin() {
- return isAdmin;
- }
- public void setIsAdmin(int isAdmin) {
- this.isAdmin = isAdmin;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement