Advertisement
Guest User

خرا

a guest
Apr 27th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.70 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package login;
  7.  
  8. import javax.inject.Named;
  9. import javax.enterprise.context.SessionScoped;
  10. import java.io.Serializable;
  11. import java.sql.Connection;
  12. import java.sql.DriverManager;
  13. import java.sql.ResultSet;
  14. import java.sql.SQLException;
  15. import java.sql.Statement;
  16.  
  17. /**
  18.  *
  19.  * @author Magdy
  20.  */
  21. @Named(value = "signout")
  22. @SessionScoped
  23. public class Signout implements Serializable {
  24.  
  25.     String GetsUsername, GetsPassword, GetsEmail;
  26.  
  27.     public String getGetsUsername() {
  28.         return GetsUsername;
  29.     }
  30.  
  31.     public void setGetsUsername(String GetsUsername) {
  32.         this.GetsUsername = GetsUsername;
  33.     }
  34.  
  35.     public String getGetsPassword() {
  36.         return GetsPassword;
  37.     }
  38.  
  39.     public void setGetsPassword(String GetsPassword) {
  40.         this.GetsPassword = GetsPassword;
  41.     }
  42.  
  43.     public Signout() {
  44.  
  45.     }
  46.  
  47.     String username,
  48.             Email,
  49.             password,
  50.             Error,
  51.             Age;
  52.  
  53.     public boolean load() {
  54.         try {
  55.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  56.             Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
  57.             Statement STF = MC.createStatement();
  58.             ResultSet R = STF.executeQuery("Select * from user");
  59.             while (R.next()) {
  60.                 GetsUsername = (R.getString("Name"));
  61.                 GetsEmail = (R.getString("Email"));
  62.                 if (username.equals(GetsUsername) || Email.equals(GetsEmail)) {
  63.                     return true;
  64.                 }
  65.             }
  66.         } //#{Sessionname}
  67.         catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
  68.             System.out.println(E);
  69.         }
  70.         return false;
  71.  
  72.     }
  73.  
  74.     public String check() {
  75.         if (load()) {
  76.             Error = "The user name or Email Found for current user";
  77.             return "index.xhtml?faces-redirect=true";
  78.         } else {
  79.             try {
  80.                 Class.forName("com.mysql.jdbc.Driver").newInstance();
  81.                 Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
  82.                 Statement STF = MC.createStatement();
  83.                 String R = "Insert into user(Name,Email,Password,Age) VALUES ('" + username + "','" + Email + "','" + password + "','" + Age + "')";
  84.                 STF.executeUpdate(R);
  85.             } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
  86.                 System.out.println(E);
  87.             }
  88.             return "login.xhtml?faces-redirect=true";
  89.         }
  90.     }
  91.  
  92.     public String getGetsEmail() {
  93.         return GetsEmail;
  94.     }
  95.  
  96.     public void setGetsEmail(String GetsEmail) {
  97.         this.GetsEmail = GetsEmail;
  98.     }
  99.  
  100.     public String getError() {
  101.         return Error;
  102.     }
  103.  
  104.     public void setError(String Error) {
  105.         this.Error = Error;
  106.     }
  107.  
  108.     public String getUsername() {
  109.         return username;
  110.     }
  111.  
  112.     public void setUsername(String username) {
  113.         this.username = username;
  114.     }
  115.  
  116.     public String getEmail() {
  117.         return Email;
  118.     }
  119.  
  120.     public void setEmail(String Email) {
  121.         this.Email = Email;
  122.     }
  123.  
  124.     public String getPassword() {
  125.         return password;
  126.     }
  127.  
  128.     public void setPassword(String password) {
  129.         this.password = password;
  130.     }
  131.  
  132.     public String getAge() {
  133.         return Age;
  134.     }
  135.  
  136.     public void setAge(String Age) {
  137.         this.Age = Age;
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement