Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String username;
- String password;
- String email;
- Random rd = new Random();
- int ID;
- public void registerUser(javafx.event.ActionEvent ab) {
- username = textUser.getText();
- password = textPass.getText();
- email = textEmail.getText();
- ID = rd.nextInt(999999999);
- Connection connectt = null;
- try {
- Class.forName("org.sqlite.JDBC");
- connectt = DriverManager.getConnection("jdbc:sqlite:C:\Users\barte\OneDrive\Desktop\sqlite databases\PRODUCTS\Products.db");
- String s = "INSERT INTO Users(Username,Password,Email,UserID) VALUES (?,?,?,?) ";
- PreparedStatement registera = connectt.prepareStatement(s);
- registera.setString(1, username);
- registera.setString(2, password);
- registera.setString(3, email);
- registera.setInt(4, ID);
- System.out.println(username);
- System.out.println(password);
- System.out.println(email);
- registera.executeUpdate();
- System.out.println("Added to Database");
- sendMail();
- registerr.setStyle("-fx-background-color: #69ff59;");
- registerr.setText("Check Your MailBox");
- registerr.setOnMouseClicked(event -> {
- registerr.setText("Email Has been sent");
- });
- textUser.setText(null);
- textEmail.setText(null);
- textPass.setText(null);
- regiPane.setVisible(false);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- }
- public void sendMail() throws MessagingException {
- String USER_NAME = "stoc****";
- String from = USER_NAME;
- String PASSWORD = "************";
- String pass = PASSWORD;
- String RECIPT = textEmail.getText();
- String TOPIC = "Welcome " + username + "!";
- String BODY = "Dear user! " +
- "You can sign into StockFX by your ID/Username and password" +
- "User ID: " + ID + "n" + "Password: " + password + "n" +
- "We would like to thank you for using our services now and in future!";
- String[] to = {RECIPT};
- Properties props = System.getProperties();
- String host = "smtp.gmail.com";
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", host);
- props.put("mail.smtp.user", from);
- props.put("mail.smtp.password", pass);
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.auth", "true");
- Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(
- "****", PASSWORD);
- }
- });
- MimeMessage message = new MimeMessage(session);
- try {
- try {
- message.setFrom(new InternetAddress(from));
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- InternetAddress[] toAddress = new InternetAddress[to.length];
- // To get the array of addresses
- for (int i = 0; i < to.length; i++) {
- try {
- toAddress[i] = new InternetAddress(to[i]);
- } catch (AddressException e) {
- e.printStackTrace();
- }
- }
- for (int i = 0; i < toAddress.length; i++) {
- try {
- message.addRecipient(Message.RecipientType.TO, toAddress[i]);
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- }
- try {
- message.setSubject(TOPIC);
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- try {
- message.setText(BODY);
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- try {
- message.saveChanges();
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- registerr.setStyle("-fx-background-color: #69ff59;");
- registerr.setText("You can now log in");
- registerr.setDisable(false);
- textUser.setText(null);
- textEmail.setText(null);
- textPass.setText(null);
- regiPane.setVisible(false);
- Transport transport = session.getTransport("smtp");
- System.out.println("get protocl");
- transport.connect(host, from, pass);
- System.out.println("get host,from and password");
- transport.sendMessage(message, message.getAllRecipients());
- System.out.println("get recipients");
- transport.close();
- System.out.println("close");
- System.out.println("Email Sent Successfully!");
- } finally {
- System.out.println("Complete Process");
- }
- }
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import javax.mail.internet.*;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.fxml.Initializable;
- import javafx.scene.control.*;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.image.ImageView;
- import javafx.scene.layout.AnchorPane;
- import javafx.scene.layout.Pane;
- import javafx.scene.media.Media;
- import javafx.scene.media.MediaPlayer;
- import javafx.stage.Stage;
- import java.awt.*;
- import java.io.File;
- import java.io.IOException;
- import java.net.URI;
- import java.net.URISyntaxException;
- import java.net.URL;
- import java.sql.*;
- import java.util.Properties;
- import java.util.Random;
- import java.util.ResourceBundle;
- package sample;
- import javafx.application.Application;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- import java.io.IOException;
- public class Main extends Application {
- @Override
- public void start(Stage UI) throws IOException {
- Parent root = FXMLLoader.load(getClass().getResource("DashBoard.fxml"));
- UI.setTitle("DIREXT SCANNER (DEMO VER 0.5)");
- UI.setScene(new Scene(root, 800, 600));
- UI.initStyle(StageStyle.UNDECORATED);
- UI.setResizable(false);
- UI.show();
- UI.setFullScreenExitHint("Press 'ESC' to exit full screen");
- }
- public static void main(String[] args){
- launch(args);
- }
- }
Add Comment
Please, Sign In to add comment