90 lines
4.9 KiB
HTML
90 lines
4.9 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>UserController.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Client</a> > <a href="index.source.html" class="el_package">gogreen.client.controller</a> > <span class="el_source">UserController.java</span></div><h1>UserController.java</h1><pre class="source lang-java linenums">package gogreen.client.controller;
|
|
|
|
import gogreen.client.rest.UserService;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.Parent;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.control.Alert;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.PasswordField;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.Window;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import java.io.IOException;
|
|
|
|
@Controller
|
|
<span class="nc" id="L22">public class UserController {</span>
|
|
@Autowired
|
|
UserService userService;
|
|
|
|
@FXML
|
|
private TextField usernameField;
|
|
|
|
@FXML
|
|
private PasswordField passwordField;
|
|
|
|
@FXML
|
|
private Button loginButton;
|
|
|
|
@FXML
|
|
private Button signupButton;
|
|
|
|
// @Value("${my.url}")
|
|
// private String myUrl;
|
|
|
|
// @FXML
|
|
// private void initialize(ActionEvent event) throws IOException {
|
|
// Parent parent = FXMLLoader.load(getClass().getResource("sample.fxml"));
|
|
// Scene scene = new Scene(parent);
|
|
// Stage app_stage = (Stage)((Node) event.getSource()).getScene().getWindow();
|
|
// app_stage.setScene(scene);
|
|
// app_stage.show();
|
|
// }
|
|
|
|
@FXML
|
|
protected void handleLoginButtonAction(ActionEvent event) throws IOException {
|
|
<span class="nc" id="L52"> Window owner = loginButton.getScene().getWindow();</span>
|
|
<span class="nc bnc" id="L53" title="All 2 branches missed."> if(usernameField.getText().isEmpty()) {</span>
|
|
<span class="nc" id="L54"> AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",</span>
|
|
"Please enter your username");
|
|
<span class="nc" id="L56"> return;</span>
|
|
} else {
|
|
// newUser.setUsername(usernameField.getText());
|
|
<span class="nc" id="L59"> System.out.println("Username is " + usernameField.getText());</span>
|
|
}
|
|
<span class="nc bnc" id="L61" title="All 2 branches missed."> if(passwordField.getText().isEmpty()) {</span>
|
|
<span class="nc" id="L62"> AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",</span>
|
|
"Please enter a password");
|
|
<span class="nc" id="L64"> return;</span>
|
|
} else {
|
|
// newUser.setPassword(passwordField.getText());
|
|
<span class="nc" id="L67"> System.out.println("Password is " + passwordField.getText());</span>
|
|
}
|
|
|
|
<span class="nc" id="L70"> userService.registerUser(usernameField.getText(), passwordField.getText());</span>
|
|
// Parent parent = FXMLLoader.load(this.getClass().getClassLoader().getResource("/fxml/dashboard.fxml"));
|
|
// Scene scene = new Scene(parent);
|
|
// Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
|
// app_stage.setScene(scene);
|
|
// app_stage.show();
|
|
<span class="nc" id="L76"> }</span>
|
|
|
|
<span class="nc" id="L78"> public static class AlertHelper {</span>
|
|
public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
|
|
<span class="nc" id="L80"> Alert alert = new Alert(alertType);</span>
|
|
<span class="nc" id="L81"> alert.setTitle(title);</span>
|
|
<span class="nc" id="L82"> alert.setHeaderText(null);</span>
|
|
<span class="nc" id="L83"> alert.setContentText(message);</span>
|
|
<span class="nc" id="L84"> alert.initOwner(owner);</span>
|
|
<span class="nc" id="L85"> alert.show();</span>
|
|
<span class="nc" id="L86"> }</span>
|
|
}
|
|
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.2.201808211720</span></div></body></html> |