Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.company.action;
- import javax.servlet.RequestDispatcher;
- import javax.servlet.http.HttpSession;
- import br.com.company.contacts.User;
- import br.com.company.dao.DAOException;
- import br.com.company.dao.UserDAO;
- import br.com.company.dao.DBPool;
- import br.com.company.dao.PoolException;
- import com.opensymphony.xwork2.ActionSupport;
- import br.com.company.contacts.*;
- public class LoginAction extends ActionSupport {
- private static final long serialVersionUID = 1L;
- private String email;
- private String password;
- private String message;
- private DBPool dbpool;
- public LoginAction() {
- try {
- dbpool = new DBPool("org.postgresql.Driver","jdbc:postgresql://localhost:5432/DB-PI","webuser","webpass");
- }
- catch(PoolException e){
- e.printStackTrace();
- }
- }
- public String HelloWorld(){
- this.message = "hello Struts World!";
- return "SUCCESS";
- }
- public String execute(){
- //registered user
- User userRegistered = null;
- //creates a new user
- User user = new User(email,password);
- //Retrieves DBPool from context
- UserDAO userDAO = new UserDAO(dbpool);
- //retrieves user by e-mail
- try {
- userRegistered = userDAO.findByEmail(user);
- } catch (DAOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //call a login Service
- if (userRegistered == null){
- //unregistered user
- //redirects to the register Page
- return "NOTREGUSER";
- }
- else {
- if (user.getPassword().equals(userRegistered.getPassword())){
- return "SUCCESS";
- }
- else{
- return "FAIL";
- }
- }
- }
- 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 getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public DBPool getDbpool() {
- return dbpool;
- }
- public void setDbpool(DBPool dbpool) {
- this.dbpool = dbpool;
- }
- /* public String getUser() {
- return user;
- }
- public void setUser(String user) {
- this.user = user;
- }
- public String getPass() {
- return pass;
- }
- public void setPass(String pass) {
- this.pass = pass;
- }
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement