package actions;

import java.util.ArrayList;
import org.apache.struts2.interceptor.*;
import org.apache.struts2.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
import modelo.GestionClientes;
import modelo.GestionTelefonos;

public class Validar implements ServletContextAware{
    private String password="hola";
    private String username;
    private ArrayList<Integer> telefonos;
    ServletContext context;
    public String execute() throws Exception {
      String driver=context.getInitParameter("driver");
      String cadenaCon=context.getInitParameter("cadenaCon");
      GestionClientes gc=new GestionClientes(driver,cadenaCon);
      
      if(gc.validar(username,password)){
          GestionTelefonos gt=new GestionTelefonos(driver,cadenaCon);
          telefonos=gt.getTelefonos(password);
	  return "ok";
      }
      else{
	  return "error";
      }
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public ArrayList<Integer> getTelefonos() {
        return telefonos;
    }
    public void setTelefonos(ArrayList<Integer> telefonos) {
        this.telefonos = telefonos;
    }  
    public void setServletContext(ServletContext context){
      this.context=context;
    }
} 
