summaryrefslogtreecommitdiffstats
path: root/Dozentenmodul/src/gui/intro/Login_GUI.java
diff options
context:
space:
mode:
authorSimon Rettberg2014-07-14 20:58:42 +0200
committerSimon Rettberg2014-07-14 20:58:42 +0200
commit67511b8aad6c1162bbd8ba01e1d4cd9a0bb1e107 (patch)
tree82b1d287d0b7304d2c5b8bc4d958694fd8fd2b4d /Dozentenmodul/src/gui/intro/Login_GUI.java
parentConverted DMS to Maven project (1/2) (diff)
downloadtutor-module-67511b8aad6c1162bbd8ba01e1d4cd9a0bb1e107.tar.gz
tutor-module-67511b8aad6c1162bbd8ba01e1d4cd9a0bb1e107.tar.xz
tutor-module-67511b8aad6c1162bbd8ba01e1d4cd9a0bb1e107.zip
mavenization on its way...
Diffstat (limited to 'Dozentenmodul/src/gui/intro/Login_GUI.java')
-rw-r--r--Dozentenmodul/src/gui/intro/Login_GUI.java336
1 files changed, 0 insertions, 336 deletions
diff --git a/Dozentenmodul/src/gui/intro/Login_GUI.java b/Dozentenmodul/src/gui/intro/Login_GUI.java
deleted file mode 100644
index 06a87307..00000000
--- a/Dozentenmodul/src/gui/intro/Login_GUI.java
+++ /dev/null
@@ -1,336 +0,0 @@
-package gui.intro;
-
-import java.awt.Color;
-import java.awt.EventQueue;
-import java.awt.Image;
-import java.awt.SystemColor;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.File;
-import java.io.IOException;
-
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JPasswordField;
-import javax.swing.JTextField;
-import javax.swing.SwingConstants;
-import javax.swing.UIManager;
-import javax.swing.UnsupportedLookAndFeelException;
-import javax.swing.border.EmptyBorder;
-
-import models.SessionData;
-import models.person;
-
-import org.apache.thrift.TException;
-import org.ini4j.Wini;
-
-import thrift.ImageServer.Client;
-import thrift.MasterThriftConnection;
-import thrift.ThriftConnection;
-import thrift.UserInfo;
-import util.GuiOrganizer;
-import config.config_file;
-
-@SuppressWarnings("serial")
-public class Login_GUI extends JFrame {
-
- private JPanel contentPane;
- private JTextField lblusername;
- private JPasswordField lblpass;
- JLabel lblConnectionInfo = new JLabel("");
- boolean isClientReturnedCorrectly = false;
- boolean login;
- String masterServerIP = MasterThriftConnection.MASTERSERVERIP;
- MasterThriftConnection thrift;
- Client client;
- String token;
-
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- // Pruefe und Erzeuge gegebenfalls Config
- config_file cf = new config_file();
- boolean conf = cf.createConfig();
- if (conf == true) {
- // Aufruf und Anzeige des Login Fensters
- Login_GUI frame = new Login_GUI();
- frame.setVisible(true);
- } else {
- JOptionPane.showMessageDialog(null,
- "Fehler beim erzeugen der Konfigurationsfile",
- "Message", JOptionPane.ERROR_MESSAGE);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, e.getStackTrace(),
- "Message", JOptionPane.ERROR_MESSAGE);
- }
- }
- });
- }
-
- /**
- * Create the frame.
- */
- public Login_GUI() {
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
-
- // Fenster darf nicht vergroessert werden
- setResizable(false);
-
- try {
- // Setzt das Look and Feel auf System
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (ClassNotFoundException | InstantiationException
- | IllegalAccessException | UnsupportedLookAndFeelException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- JOptionPane.showMessageDialog(null,
- e.getCause() + "\n" + e.getMessage(), "Debug-Message",
- JOptionPane.ERROR_MESSAGE);
- }
- // Titel des Fensters setzen
- setTitle("Dozentenmodul *Prototyp*");
- // Aktion die beim Schliessen durchgefuehrt werden soll
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- //Größe setzen und mittig ausrichten
- setBounds(0, 0, 603, 400);
- GuiOrganizer.centerGUI(this);
-
- // Erzeugen eines Panels
- contentPane = new JPanel();
- // Hintergrund Farbe des Panels setzen
- contentPane.setBackground(SystemColor.menu);
- // Rahmen des Fensters setzen
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- // Layout setzen
- contentPane.setLayout(null);
- // Label fuer das Logo erzeugen
- JLabel imgLabel = new JLabel();
- // Groesse und Position des Logos festelegen
- imgLabel.setBounds(150, 11, 350, 142);
- // Pfadangabe des Logos
-
- ImageIcon icon = new ImageIcon(getClass().getResource(
- "/Logo_bwLehrpool.png"), "Logo");
- // Skalierung des Logos
- Image scaled = icon.getImage().getScaledInstance(270, 64, 0);
- imgLabel.setIcon(new ImageIcon(scaled));
- // Hinzufuegen des Logos in das Fenster
- contentPane.add(imgLabel);
-
- // Erzeugen und Hinzufuegen des Labels
- JLabel LabelUser = new JLabel("bwIDM-Benutzername:");
- LabelUser.setBounds(111, 164, 134, 20);
- contentPane.add(LabelUser);
-
- // Erzeugen und Hinzufuegen des Textfeldes
- lblusername = new JTextField();
- lblusername
- .setToolTipText("Bitte geben Sie Ihren bwIDM-Benutzernamen ein.");
- lblusername.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- performLogin();
- }
- });
- lblusername.setBounds(292, 164, 237, 20);
- contentPane.add(lblusername);
- lblusername.setColumns(10);
-
- // Erzeugen und Hinzufuegen des Labels
- JLabel LabelPass = new JLabel("bwIDM-Passwort:");
- LabelPass.setBounds(111, 195, 134, 20);
- contentPane.add(LabelPass);
-
- // Erzeugen, Hinzufuegen und definierung der Aktion des Buttons
- JButton BtnLogin = new JButton("Login");
- BtnLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- performLogin();
- }// end actionPerformed
- });
-
- BtnLogin.setBounds(292, 244, 237, 23);
- contentPane.add(BtnLogin);
-
- // Erzeugen und Hinzufuegen des Passwortfeldes
- lblpass = new JPasswordField();
- lblpass.setToolTipText("Bitte geben Sie Ihr bwIDM-Passwort ein.");
- lblpass.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- performLogin();
- }
- });
- lblpass.setBounds(292, 195, 237, 20);
- contentPane.add(lblpass);
-
- lblConnectionInfo.setHorizontalAlignment(SwingConstants.LEFT);
- lblConnectionInfo.setBounds(292, 290, 237, 20);
- contentPane.add(lblConnectionInfo);
- //GuiOrganizer.centerGUI(this);
- }// end LoginGUI()
-
- // Versuche den Benutzer einzuloggen
- public void performLogin() {
-
- login = false;
- thrift = new MasterThriftConnection();
- client = thrift.getMasterThriftConnection();
- token = null;
- thrift.SessionData result = null;
-
- try {
- login = true;
- String passText = new String(lblpass.getPassword());
- // check if client has received a connection with information or a
- // null package
- if (checkClientPackage() == true) {
- // package has information
- result = client.authenticate(lblusername.getText(), passText);
- SessionData.session.setAuthToken(result.authToken);
- SessionData.session.setSessionID(result.sessionId);
- SessionData.session.setServerAdress(result.serverAddress);
-
- // set connection to bwLehrpoolSuiteServer
- ThriftConnection bwthrift = new ThriftConnection();
- server.Server.Client bwClient = bwthrift.getThriftConnection();
- models.Client.clientcon.setClient(bwClient);
-
- System.out.println("Session-ID: " + result.sessionId
- + "\nToken: " + result.authToken);
-
- if (login == true) {
- //Daten speichern
- if (SessionData.session.getAuthToken() == null) {
- System.out.println("Token ist null");
- JOptionPane.showMessageDialog(null,
- "Error: Token ist null", "Token defekt",
- JOptionPane.ERROR_MESSAGE);
- }
- System.out.println("Hole jetzt Infos aus SessionData...");
- UserInfo user = client.getUserFromToken(SessionData.session
- .getAuthToken());
-
- String hochschule = user.eMail.substring(user.eMail
- .indexOf("@") + 1);
-
- person.verantwortlicher.setUsername(lblusername.getText()
- .substring(0, lblusername.getText().indexOf("@")));
- person.verantwortlicher.setName(user.lastName);
- person.verantwortlicher.setVorname(user.firstName);
- person.verantwortlicher.setEMail(user.eMail);
- person.verantwortlicher.setHochschule(hochschule);
-
- try {
- // Lege config File an und entscheide welches Fenster
- // als naechstes geoeffnet wird
- Wini ini = new Wini(
- new File(
- "C:\\Users\\"
- + System.getProperty("user.name")
- + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini"));
- // Pruefe ob Bills Of Rights schon akzeptiert wurden,
- // wenn
- // nicht zeige diese an
- if (ini.get("main", "BillOfRights", boolean.class) == false) {
- // Erstellen einer Instanz der Aktionsauswahl
- BillOfRights_GUI re = new BillOfRights_GUI();
- re.setVisible(true);
- // Schliessen des Fensters nach erfolgreichen Login
- setVisible(false);
- } else {
- // Pruefe ob die Links zu vmware angezeigt werden
- // sollen
- if (ini.get("main", "vmware", boolean.class) == false) {
- VmWareLink_GUI vm = new VmWareLink_GUI();
- vm.setVisible(true);
- setVisible(false);
- } else {
-
- // oeffne das Hauptmenue
- MainMenue_GUI main = new MainMenue_GUI();
- main.setVisible(true);
- setVisible(false);
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, e.getCause() + "\n"
- + e.getMessage(), "Debug-Message",
- JOptionPane.ERROR_MESSAGE);
- }
-
- } else {
- JOptionPane.showMessageDialog(null, "Login denied!",
- "Message", JOptionPane.INFORMATION_MESSAGE);
- }
-
- } else {
- // package from server is null
- login = false;
- lblConnectionInfo.setForeground(Color.red);
- lblConnectionInfo
- .setText("Fehler: Client nicht mit Server verbunden.");
-
- }
-
- } catch (thrift.AuthenticationException e) {
- System.out
- .println("Authentifizierung fehlgeschlagen: " + e.message);
- JOptionPane
- .showMessageDialog(
- null,
- "Benutzeranmeldung fehlgeschlagen: Bitte Benutzername und Passwort \u00fcberpr\u00fcfen.",
- "Anmeldung fehlgeschlagen",
- JOptionPane.ERROR_MESSAGE);
- e.printStackTrace();
- JOptionPane.showMessageDialog(null,
- e.getCause() + "\n" + e.getMessage(), "Message",
- JOptionPane.ERROR_MESSAGE);
- return;
- } catch (TException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- JOptionPane.showMessageDialog(null,
- e.getCause() + "\n" + e.getMessage(), "Debug-Message",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- }// end performLogin
-
- public boolean checkClientPackage() {
- // check if client is null or has been returned with information
- if (client != null) {
- // client contains information
- isClientReturnedCorrectly = true;
- System.out.println("Verbindungsinformationen erhalten");
- } else {
- // client has returned with error
- isClientReturnedCorrectly = false;
- System.out
- .println("Fehler: Keine korrekten Verbindungsdaten erhalten.");
- }
-
- return isClientReturnedCorrectly;
- }// end checkServerConnection()
-
-}// end class