Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. package br.com.company.action;
  2. import javax.servlet.RequestDispatcher;
  3. import javax.servlet.http.HttpSession;
  4.  
  5. import br.com.company.contacts.User;
  6. import br.com.company.dao.DAOException;
  7. import br.com.company.dao.UserDAO;
  8. import br.com.company.dao.DBPool;
  9. import br.com.company.dao.PoolException;
  10.  
  11. import com.opensymphony.xwork2.ActionSupport;
  12. import br.com.company.contacts.*;
  13.  
  14.  
  15. public class LoginAction extends ActionSupport {
  16.  
  17.    
  18.     private static final long serialVersionUID = 1L;
  19.     private String email;
  20.     private String password;
  21.     private String message;
  22.     private DBPool dbpool;
  23.    
  24.     public LoginAction() {
  25.         try {
  26.             dbpool = new DBPool("org.postgresql.Driver","jdbc:postgresql://localhost:5432/DB-PI","webuser","webpass");
  27.         }
  28.             catch(PoolException e){
  29.                 e.printStackTrace();
  30.             }
  31.     }
  32.    
  33.     public String HelloWorld(){
  34.         this.message = "hello Struts World!";
  35.         return "SUCCESS";
  36.     }
  37.  
  38.     public String execute(){
  39.  
  40.         //registered user
  41.         User userRegistered = null;
  42.  
  43.         //creates a new user
  44.         User user = new User(email,password);
  45.         //Retrieves DBPool from context
  46.         UserDAO userDAO = new UserDAO(dbpool);
  47.    
  48.         //retrieves user by e-mail
  49.  
  50.         try {
  51.             userRegistered = userDAO.findByEmail(user);
  52.         } catch (DAOException e) {
  53.             // TODO Auto-generated catch block
  54.             e.printStackTrace();
  55.         }
  56.  
  57.         //call a login Service
  58.         if (userRegistered == null){
  59.             //unregistered user
  60.             //redirects to the register Page
  61.             return "NOTREGUSER";
  62.         }
  63.         else {
  64.             if (user.getPassword().equals(userRegistered.getPassword())){
  65.                 return "SUCCESS";
  66.             }
  67.             else{
  68.                 return "FAIL";
  69.             }
  70.         }
  71.     }
  72.  
  73.  
  74.  
  75.     public String getEmail() {
  76.         return email;
  77.     }
  78.  
  79.  
  80.  
  81.     public void setEmail(String email) {
  82.         this.email = email;
  83.     }
  84.  
  85.  
  86.  
  87.     public String getPassword() {
  88.         return password;
  89.     }
  90.  
  91.  
  92.  
  93.     public void setPassword(String password) {
  94.         this.password = password;
  95.     }
  96.  
  97.  
  98.  
  99.     public String getMessage() {
  100.         return message;
  101.     }
  102.  
  103.  
  104.  
  105.     public void setMessage(String message) {
  106.         this.message = message;
  107.     }
  108.  
  109.  
  110.  
  111.     public DBPool getDbpool() {
  112.         return dbpool;
  113.     }
  114.  
  115.  
  116.  
  117.     public void setDbpool(DBPool dbpool) {
  118.         this.dbpool = dbpool;
  119.     }
  120.    
  121.    
  122. /*  public String getUser() {
  123.         return user;
  124.     }
  125.  
  126.     public void setUser(String user) {
  127.         this.user = user;
  128.     }
  129.  
  130.     public String getPass() {
  131.         return pass;
  132.     }
  133.  
  134.     public void setPass(String pass) {
  135.         this.pass = pass;
  136.     }
  137.    
  138.     public String getMessage() {
  139.         return message;
  140.     }
  141.  
  142.     public void setMessage(String message) {
  143.         this.message = message;
  144.     }
  145. */
  146.    
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement