Package labsis.usuario.model

Examples of labsis.usuario.model.Usuario


    // TODO Auto-generated method stub
    String comm = "";
    String msg = "";
    String url = "/usuarios/jsp/login.jsp";
    comm = request.getParameter("comm");
    Usuario user = (Usuario) request.getSession().getAttribute("usuario");

    if (comm == null || comm.isEmpty()) {
      request.setAttribute("msg", msg);
      RequestDispatcher rd = request
          .getRequestDispatcher("/usuarios/jsp/login.jsp");
      rd.forward(request, response);
    }
    // efetua login
    else if (comm.equals("login")) {
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      url = "/usuarios/jsp/login.jsp";
      if (username != null && password != null) {
        Manager m = Manager.getInstace();
        Usuario u = null;
        u = m.login(username, password);
        if (u == null) {
          msg = "Usuario e/ou senha invalidos! Tente novamente.";
        } else {
          request.getSession().setAttribute("usuario", u);
          url = "/usuarios/jsp/welcome.jsp";
        }
      }
      request.setAttribute("msg", msg);
      RequestDispatcher rd = request.getRequestDispatcher(url);
      rd.forward(request, response);
    }
    // navega pelo sistema apenas com usuario logado
    else if (user != null) {
      // efetua logoff
      if (comm.equals("logoff")) {
        Manager m = Manager.getInstace();
        url = "/usuarios/jsp/login.jsp";
        if (m.logoff(user.getUsername())) {
          request.getSession().removeAttribute("usuario");
          msg = "Logged off";
        } else {
          url = "/usuarios/jsp/welcome.jsp";
          msg = "Erro ao efetuar log off!";
        }
        request.setAttribute("msg", msg);
        RequestDispatcher rd = request.getRequestDispatcher(url);
        rd.forward(request, response);
      }
      // consulta usuarios
      else if (comm.equals("consultaUsuario")
          || comm.equals("atualizaUsuario")
          || comm.equals("deletaUsuario")) {
        url = "/usuarios/jsp/consultaUsuario.jsp";
        Manager m = Manager.getInstace();

        int pageNum = 1;
        Integer totalPages = 1;
        String page = request.getParameter("pageNum");
        if (page != null && !page.equals("")) {
          pageNum = Integer.parseInt(page);
        }
        List<Usuario> users = m.retrieveUsers(user.getUsername(),
            pageNum);
        totalPages = Integer.parseInt(users.remove(users.size() - 1)
            .getUsername());
        request.setAttribute("totalPages", totalPages);
        request.setAttribute("pageNum", pageNum);
        request.setAttribute("users", users);

        request.setAttribute("msg", msg);
        RequestDispatcher rd = request.getRequestDispatcher(url);
        rd.forward(request, response);
      }
      // cadastro de usuarios
      else if (comm.equals("cadastraUsuario")) {
        url = "/usuarios/jsp/cadastroUsuario.jsp";
        Manager m = Manager.getInstace();

        List<TipoUsuario> tipousers = m.getTipoUsuarios();
        request.setAttribute("tipousers", tipousers);

        if (tipousers.size() == 0) {
          url = "/usuarios/jsp/welcome.jsp";
          msg = "Erro ao carregar tipos de usuarios!";
        }

        request.setAttribute("msg", msg);
        RequestDispatcher rd = request.getRequestDispatcher(url);
        rd.forward(request, response);
      }
      // cria usuario
      else if (comm.equals("create")) {
        url = "/usuarios/jsp/welcome.jsp";
        Manager m = Manager.getInstace();
        String nome = request.getParameter("nome");
        String username = request.getParameter("username");
        Integer tipousuarioid = Integer.parseInt(request
            .getParameter("tipousuario"));
        String senha = request.getParameter("senha");
        msg = m.createUser(username, senha, nome, tipousuarioid, user
            .getUsername());
        request.setAttribute("msg", msg);
        RequestDispatcher rd = request.getRequestDispatcher(url);
        rd.forward(request, response);
      }
      // deleta usuarios
      else if (comm.equals("delete")) {
        url = "/usuarios/jsp/welcome.jsp";
        Manager m = Manager.getInstace();
        String username = request.getParameter("username");

        msg = m.deleteUser(username, user.getUsername());
        if (username.equals(user.getUsername())) {
          url = "/usuarios/jsp/login.jsp";
          request.getSession().removeAttribute("usuario");
        }
        request.setAttribute("msg", msg);
        RequestDispatcher rd = request.getRequestDispatcher(url);
        rd.forward(request, response);
      }
      // alteracao de usuario
      else if (comm.equals("update")) {
        url = "/usuarios/jsp/alteraUsuario.jsp";
        Manager m = Manager.getInstace();
        String username = request.getParameter("username");

        Usuario u = m.getUser(username);
        request.getSession().setAttribute("alterUser", u);

        List<TipoUsuario> tipousers = m.getTipoUsuarios();
        request.setAttribute("tipousers", tipousers);

        request.setAttribute("msg", msg);
        RequestDispatcher rd = request.getRequestDispatcher(url);
        rd.forward(request, response);
      }
      // altera usuar
      else if (comm.equals("commitUpdate")) {
        url = "/usuarios/jsp/welcome.jsp";
        Manager m = Manager.getInstace();
        Usuario u = (Usuario) request.getSession().getAttribute(
            "alterUser");
        String nome = request.getParameter("nome");
        String username = u.getUsername();
        System.out.println(request.getParameter("tipousuario"));
        Integer tipousuarioid = Integer.parseInt(request
            .getParameter("tipousuario"));
        String senha = request.getParameter("novasenha");
        if (senha.equals("")) {
View Full Code Here


  public Usuario login(String username, String password) {
    DaoUsuario du = null;
    try {
      du = new DaoUsuario();
      Usuario u = (Usuario) du.find(username);
      if (u != null && u.getSenha().equals(password)) {
        return u;
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
View Full Code Here

    List<Usuario> ulist = new ArrayList<Usuario>();
    try {
      du = new DaoUsuario();
      List l = du.retrieve();
      for (Object o : l) {
        Usuario u = (Usuario) o;
        ulist.add(u);
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
View Full Code Here

    try {
      du = new DaoUsuario();
      List l = du.retrieve(pageNum, 5);
      Integer totalPages = (Integer) l.remove(l.size() - 1);
      for (Object o : l) {
        Usuario u = (Usuario) o;
        ulist.add(u);
      }
      ulist.add(new Usuario(totalPages + "", null, null, null));
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
View Full Code Here

  public String deleteUser(String delusername, String username) {
    DaoUsuario du = null;
    String msg = "Usuario " + delusername + " deletado com sucesso!";
    try {
      du = new DaoUsuario();
      du.delete(new Usuario(delusername, null, null, null));
    } catch (ClassNotFoundException e) {
      msg = "Erro no driver SQL!";
      e.printStackTrace();
    } catch (SQLException e) {
      msg = "Erro de consulta SQL!";
View Full Code Here

      int tipousuarioid, String username) {
    DaoUsuario du = null;
    String msg = "Usuario " + updateusername + " alterado com sucesso!";
    try {
      du = new DaoUsuario();
      du.update(new Usuario(updateusername, senha, nome, new TipoUsuario(
          tipousuarioid, "", null)));
    } catch (ClassNotFoundException e) {
      msg = "Erro no driver SQL!";
      e.printStackTrace();
    } catch (SQLException e) {
View Full Code Here

      int tipousuarioid, String username) {
    DaoUsuario du = null;
    String msg = "";
    try {
      du = new DaoUsuario();
      if(du.create(new Usuario(newusername, senha, nome, new TipoUsuario(
          tipousuarioid, "", null)))){
        msg = "Usuario '" + newusername + "' criado com sucesso!";
      }else{
        msg = "Usuario '" + newusername + "' ja existe";
      }
View Full Code Here

    return l;
  }

  public Usuario getUser(String username) {
    DaoUsuario du = null;
    Usuario u = null;
    try {
      du = new DaoUsuario();
      u = (Usuario) du.find(username);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
View Full Code Here

  private boolean addLog(String username, int operacaoid)
      throws SQLException, ClassNotFoundException {
    DaoLogUsuario dl = null;
    dl = new DaoLogUsuario();
    boolean b = dl.create(new LogUsuario(0, new Operacao(operacaoid, null,null),
        new Usuario(username, null, null, null), null));
    dl.close();
    return b;
  }
View Full Code Here

        .getPassword());
  }

  @Override
  public boolean create(Object o) throws SQLException {
    Usuario u = (Usuario) o;
    PreparedStatement st = conn
    .prepareStatement("select username from usuario where username = ?");
    st.setString(1, u.getUsername());
    ResultSet r = st.executeQuery();
    if(r.next()){
      return false;
    }
    st = conn
        .prepareStatement("insert into usuario (username, nome, senha,tipousuarioId) values(?,?,?,?)");
    st.setString(1, u.getUsername());
    st.setString(2, u.getNome());
    st.setString(3, u.getSenha());
    st.setInt(4, u.getTipoUsuario().getId());
    if (st.executeUpdate() > 0)
      return true;
    return false;
  }
View Full Code Here

TOP

Related Classes of labsis.usuario.model.Usuario

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.