Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package login;
- import javax.inject.Named;
- import javax.enterprise.context.SessionScoped;
- import java.io.Serializable;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- *
- * @author Magdy
- */
- @Named(value = "signout")
- @SessionScoped
- public class Signout implements Serializable {
- String GetsUsername, GetsPassword, GetsEmail;
- public String getGetsUsername() {
- return GetsUsername;
- }
- public void setGetsUsername(String GetsUsername) {
- this.GetsUsername = GetsUsername;
- }
- public String getGetsPassword() {
- return GetsPassword;
- }
- public void setGetsPassword(String GetsPassword) {
- this.GetsPassword = GetsPassword;
- }
- public Signout() {
- }
- String username,
- Email,
- password,
- Error,
- Age;
- public boolean load() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
- Statement STF = MC.createStatement();
- ResultSet R = STF.executeQuery("Select * from user");
- while (R.next()) {
- GetsUsername = (R.getString("Name"));
- GetsEmail = (R.getString("Email"));
- if (username.equals(GetsUsername) || Email.equals(GetsEmail)) {
- return true;
- }
- }
- } //#{Sessionname}
- catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
- System.out.println(E);
- }
- return false;
- }
- public String check() {
- if (load()) {
- Error = "The user name or Email Found for current user";
- return "index.xhtml?faces-redirect=true";
- } else {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
- Statement STF = MC.createStatement();
- String R = "Insert into user(Name,Email,Password,Age) VALUES ('" + username + "','" + Email + "','" + password + "','" + Age + "')";
- STF.executeUpdate(R);
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
- System.out.println(E);
- }
- return "login.xhtml?faces-redirect=true";
- }
- }
- public String getGetsEmail() {
- return GetsEmail;
- }
- public void setGetsEmail(String GetsEmail) {
- this.GetsEmail = GetsEmail;
- }
- public String getError() {
- return Error;
- }
- public void setError(String Error) {
- this.Error = Error;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getEmail() {
- return Email;
- }
- public void setEmail(String Email) {
- this.Email = Email;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getAge() {
- return Age;
- }
- public void setAge(String Age) {
- this.Age = Age;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement