Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loginButton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- String username = usernameTextBox.getText();
- String password = passwordField.getText();
- String[] credentials = { username, password };
- String query = "SELECT \"Type\" FROM \"Users\" where LOWER(\"Username\") = LOWER(?) AND \"Password\" = ?";
- final ClientQuery userTypeQuery = new ClientQuery(query, credentials);
- ExecutorService executor = Executors.newCachedThreadPool();
- Future<ClientQuery> future = executor.submit(new Callable<ClientQuery>(){
- @Override
- public ClientQuery call() throws Exception {
- return QuerySender.sendQuery(userTypeQuery, socket);
- }
- });
- ClientQuery userTypeResponse = null;
- try {
- userTypeResponse = future.get();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ExecutionException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- // getting type of username based on the response from server
- // 0 - superadmin, 1 - normal admin, 2 - buyer
- UserType type;
- try {
- type = UserType.values()[Integer.parseInt(userTypeResponse.getResponse().get(0)[0])];
- } catch (Exception exception) {
- type = null;
- }
- if (type == null) {
- invalidPassLabel.setVisible(true);
- } else {
- switch (type) {
- case SuperAdmin:
- new SuperAdmin(username);
- primaryStage.close();
- break;
- case NormalAdmin:
- new NormalAdmin(username);
- primaryStage.close();
- break;
- case Buyer:
- new Buyer(username);
- primaryStage.close();
- break;
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement