Guest User

Untitled

a guest
Sep 13th, 2018
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. String username;
  2. String password;
  3. String email;
  4. Random rd = new Random();
  5. int ID;
  6. public void registerUser(javafx.event.ActionEvent ab) {
  7. username = textUser.getText();
  8. password = textPass.getText();
  9. email = textEmail.getText();
  10.  
  11. ID = rd.nextInt(999999999);
  12. Connection connectt = null;
  13.  
  14.  
  15. try {
  16.  
  17. Class.forName("org.sqlite.JDBC");
  18. connectt = DriverManager.getConnection("jdbc:sqlite:C:\Users\barte\OneDrive\Desktop\sqlite databases\PRODUCTS\Products.db");
  19. String s = "INSERT INTO Users(Username,Password,Email,UserID) VALUES (?,?,?,?) ";
  20. PreparedStatement registera = connectt.prepareStatement(s);
  21. registera.setString(1, username);
  22. registera.setString(2, password);
  23. registera.setString(3, email);
  24. registera.setInt(4, ID);
  25.  
  26. System.out.println(username);
  27. System.out.println(password);
  28. System.out.println(email);
  29. registera.executeUpdate();
  30. System.out.println("Added to Database");
  31. sendMail();
  32. registerr.setStyle("-fx-background-color: #69ff59;");
  33. registerr.setText("Check Your MailBox");
  34. registerr.setOnMouseClicked(event -> {
  35. registerr.setText("Email Has been sent");
  36. });
  37. textUser.setText(null);
  38. textEmail.setText(null);
  39. textPass.setText(null);
  40. regiPane.setVisible(false);
  41.  
  42. } catch (ClassNotFoundException e) {
  43. e.printStackTrace();
  44. } catch (SQLException e) {
  45. e.printStackTrace();
  46. } catch (MessagingException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50.  
  51. public void sendMail() throws MessagingException {
  52. String USER_NAME = "stoc****";
  53. String from = USER_NAME;
  54. String PASSWORD = "************";
  55. String pass = PASSWORD;
  56. String RECIPT = textEmail.getText();
  57. String TOPIC = "Welcome " + username + "!";
  58. String BODY = "Dear user! " +
  59. "You can sign into StockFX by your ID/Username and password" +
  60. "User ID: " + ID + "n" + "Password: " + password + "n" +
  61. "We would like to thank you for using our services now and in future!";
  62. String[] to = {RECIPT};
  63. Properties props = System.getProperties();
  64. String host = "smtp.gmail.com";
  65. props.put("mail.smtp.starttls.enable", "true");
  66. props.put("mail.smtp.host", host);
  67. props.put("mail.smtp.user", from);
  68. props.put("mail.smtp.password", pass);
  69. props.put("mail.smtp.port", "587");
  70. props.put("mail.smtp.auth", "true");
  71. Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
  72. protected PasswordAuthentication getPasswordAuthentication() {
  73. return new PasswordAuthentication(
  74. "****", PASSWORD);
  75. }
  76. });
  77. MimeMessage message = new MimeMessage(session);
  78.  
  79.  
  80. try {
  81. try {
  82. message.setFrom(new InternetAddress(from));
  83. } catch (MessagingException e) {
  84. e.printStackTrace();
  85. }
  86. InternetAddress[] toAddress = new InternetAddress[to.length];
  87. // To get the array of addresses
  88. for (int i = 0; i < to.length; i++) {
  89. try {
  90. toAddress[i] = new InternetAddress(to[i]);
  91. } catch (AddressException e) {
  92. e.printStackTrace();
  93. }
  94. }
  95. for (int i = 0; i < toAddress.length; i++) {
  96. try {
  97. message.addRecipient(Message.RecipientType.TO, toAddress[i]);
  98. } catch (MessagingException e) {
  99. e.printStackTrace();
  100. }
  101. }
  102. try {
  103. message.setSubject(TOPIC);
  104. } catch (MessagingException e) {
  105. e.printStackTrace();
  106. }
  107. try {
  108. message.setText(BODY);
  109. } catch (MessagingException e) {
  110. e.printStackTrace();
  111. }
  112. try {
  113. message.saveChanges();
  114. } catch (MessagingException e) {
  115. e.printStackTrace();
  116. }
  117.  
  118.  
  119. registerr.setStyle("-fx-background-color: #69ff59;");
  120. registerr.setText("You can now log in");
  121. registerr.setDisable(false);
  122. textUser.setText(null);
  123. textEmail.setText(null);
  124. textPass.setText(null);
  125. regiPane.setVisible(false);
  126. Transport transport = session.getTransport("smtp");
  127. System.out.println("get protocl");
  128. transport.connect(host, from, pass);
  129. System.out.println("get host,from and password");
  130. transport.sendMessage(message, message.getAllRecipients());
  131. System.out.println("get recipients");
  132. transport.close();
  133. System.out.println("close");
  134. System.out.println("Email Sent Successfully!");
  135. } finally {
  136. System.out.println("Complete Process");
  137. }
  138.  
  139. }
  140.  
  141. import javax.mail.Message;
  142. import javax.mail.MessagingException;
  143. import javax.mail.PasswordAuthentication;
  144. import javax.mail.Session;
  145. import javax.mail.Transport;
  146. import javax.mail.internet.InternetAddress;
  147. import javax.mail.internet.MimeMessage;
  148. import javax.mail.internet.*;
  149. import javafx.fxml.FXML;
  150. import javafx.fxml.FXMLLoader;
  151. import javafx.fxml.Initializable;
  152. import javafx.scene.control.*;
  153. import javafx.scene.control.Button;
  154. import javafx.scene.control.Label;
  155. import javafx.scene.control.TextField;
  156. import javafx.scene.image.ImageView;
  157. import javafx.scene.layout.AnchorPane;
  158. import javafx.scene.layout.Pane;
  159. import javafx.scene.media.Media;
  160. import javafx.scene.media.MediaPlayer;
  161. import javafx.stage.Stage;
  162. import java.awt.*;
  163. import java.io.File;
  164. import java.io.IOException;
  165. import java.net.URI;
  166. import java.net.URISyntaxException;
  167. import java.net.URL;
  168. import java.sql.*;
  169. import java.util.Properties;
  170. import java.util.Random;
  171. import java.util.ResourceBundle;
  172.  
  173. package sample;
  174. import javafx.application.Application;
  175. import javafx.fxml.FXMLLoader;
  176. import javafx.scene.Parent;
  177. import javafx.scene.Scene;
  178. import javafx.stage.Stage;
  179. import javafx.stage.StageStyle;
  180. import java.io.IOException;
  181.  
  182. public class Main extends Application {
  183.  
  184. @Override
  185. public void start(Stage UI) throws IOException {
  186. Parent root = FXMLLoader.load(getClass().getResource("DashBoard.fxml"));
  187. UI.setTitle("DIREXT SCANNER (DEMO VER 0.5)");
  188. UI.setScene(new Scene(root, 800, 600));
  189. UI.initStyle(StageStyle.UNDECORATED);
  190. UI.setResizable(false);
  191. UI.show();
  192. UI.setFullScreenExitHint("Press 'ESC' to exit full screen");
  193.  
  194. }
  195. public static void main(String[] args){
  196. launch(args);
  197. }
  198. }
Add Comment
Please, Sign In to add comment