forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1631 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
a052e0bda6
commit
bc72f0f7c9
@ -1,119 +1,124 @@
|
||||
package com.evolute.siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class doGetListaEmpresas extends siprpServlet
|
||||
{
|
||||
|
||||
public doGetListaEmpresas( HttpServletRequest req, HttpServletResponse res ) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery;
|
||||
String userRole="", temp="";
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector links = new Vector();
|
||||
Vector desc = new Vector();
|
||||
String empresa_nome;
|
||||
try
|
||||
{
|
||||
userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
empresa_nome = ( String ) session.getAttribute( sessionCompanyName );
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
if (userRole == null)
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
import com.evolute.utils.arrays.ResultSet2DArray;
|
||||
|
||||
if ( userRole.equals ( super.superUserRole ) )
|
||||
{
|
||||
empresa_nome = null;
|
||||
Class.forName(super.bdDriver);
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append(
|
||||
"SELECT id, designacao_social, designacao_social_plain " +
|
||||
"FROM empresas " +
|
||||
"WHERE " +
|
||||
"inactivo <> 'y' " +
|
||||
"AND data_cancelamento IS NULL " +
|
||||
"ORDER BY designacao_social_plain" );
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
public class doGetListaEmpresas extends siprpServlet
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
int index=0;
|
||||
int max = rs.columnLength();
|
||||
public doGetListaEmpresas( HttpServletRequest req, HttpServletResponse res ) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null;
|
||||
Statement stmt = null;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery;
|
||||
String userRole = "", temp = "";
|
||||
HttpSession session = req.getSession( false );
|
||||
List< String > links = new LinkedList< String >();
|
||||
List< String > desc = new LinkedList< String >();
|
||||
String empresa_nome;
|
||||
try
|
||||
{
|
||||
userRole = ( String ) session.getAttribute( sessionUserRole );
|
||||
empresa_nome = ( String ) session.getAttribute( sessionCompanyName );
|
||||
|
||||
while ( index < max )
|
||||
{
|
||||
String str = (String)rs.get(index,1);
|
||||
if( str != null && str.trim().length() > 0 )
|
||||
{
|
||||
temp=""+rs.get(index,0); // converter de int para String
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append("/"+super.servletName+"/?"+temp); // contruir url
|
||||
links.add(dbQuery.toString());
|
||||
desc.add((String)rs.get(index,1));
|
||||
}
|
||||
++index;
|
||||
}
|
||||
stmt.close();
|
||||
con.close();
|
||||
if ( userRole == null )
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if ( userRole.equals( superUserRole ) )
|
||||
{
|
||||
empresa_nome = null;
|
||||
Class.forName( bdDriver );
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT id, designacao_social, designacao_social_plain " + "FROM empresas " + "WHERE " + "inactivo <> 'y' "
|
||||
+ "AND data_cancelamento IS NULL " + "ORDER BY designacao_social_plain" );
|
||||
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
|
||||
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
int index = 0;
|
||||
int max = rs.columnLength();
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
//hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_nome", empresa_nome );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , super.msgListaEmpresas ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, super.queryStringEmpresas );
|
||||
hmValues.put( templateVector1,links);
|
||||
hmValues.put( templateVector2,desc);
|
||||
hmValues.put( templateVector3,null);
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
while ( index < max )
|
||||
{
|
||||
String str = ( String ) rs.get( index, 1 );
|
||||
if ( str != null && str.trim().length() > 0 )
|
||||
{
|
||||
temp = "" + rs.get( index, 0 ); // converter de int para
|
||||
// String
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "/" + servletName + "/?" + temp ); // contruir
|
||||
// url
|
||||
links.add( dbQuery.toString() );
|
||||
desc.add( ( String ) rs.get( index, 1 ) );
|
||||
}
|
||||
++index;
|
||||
}
|
||||
stmt.close();
|
||||
con.close();
|
||||
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
|
||||
//out.println( mergeTemplate( super.msgListaEmpresas, userRole, super.queryStringEmpresas, links, desc, null, super.authenticatedUserTemplate) );
|
||||
Map< String, Object > hmValues = new HashMap< String, Object >();
|
||||
// hmValues.put( "empresa_nome", session.getAttribute(
|
||||
// sessionCompanyName ) );
|
||||
hmValues.put( "empresa_nome", empresa_nome );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate, msgListaEmpresas );
|
||||
hmValues.put( templateUserRole, userRole );
|
||||
hmValues.put( templateQuery, queryStringEmpresas );
|
||||
hmValues.put( templateVector1, links );
|
||||
hmValues.put( templateVector2, desc );
|
||||
hmValues.put( templateVector3, null );
|
||||
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
}
|
||||
// out.println( mergeTemplate( super.msgListaEmpresas, userRole,
|
||||
// super.queryStringEmpresas, links, desc, null,
|
||||
// super.authenticatedUserTemplate) );
|
||||
|
||||
}
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgSessionTimeout, errorTemplate ) );
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgErroBd, errorTemplate ) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgGenericError, userRole, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,105 +1,119 @@
|
||||
package com.evolute.siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class doGetListaEstabelecimentos extends siprpServlet{
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/** Creates a new instance of doGetListaEstabelecimentos */
|
||||
public doGetListaEstabelecimentos(HttpServletRequest req, HttpServletResponse res) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery, sBuffer;
|
||||
String userRole, empresaId, temp;
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector links = new Vector();
|
||||
Vector desc = new Vector();
|
||||
try
|
||||
{
|
||||
userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
|
||||
import com.evolute.utils.arrays.ResultSet2DArray;
|
||||
|
||||
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
|
||||
{
|
||||
Class.forName(super.bdDriver);
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( " SELECT id, nome, nome_plain FROM estabelecimentos WHERE inactivo <> 'y' AND empresa_id = '"+empresaId+"' order by nome_plain" );
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
public class doGetListaEstabelecimentos extends siprpServlet
|
||||
|
||||
int index=0;
|
||||
int max = rs.columnLength();
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
while ( index < max )
|
||||
{
|
||||
temp=""+rs.get(index,0); // converter de int para String
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+temp); // contruir url
|
||||
links.add(dbQuery.toString());
|
||||
desc.add((String)rs.get(index,1));
|
||||
++index;
|
||||
}
|
||||
sBuffer = new StringBuffer();
|
||||
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b>");
|
||||
public doGetListaEstabelecimentos( HttpServletRequest req, HttpServletResponse res ) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null;
|
||||
Statement stmt = null;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery, sBuffer;
|
||||
String userRole, empresaId, temp;
|
||||
HttpSession session = req.getSession( false );
|
||||
List< String > links = new LinkedList< String >();
|
||||
List< String > desc = new LinkedList< String >();
|
||||
try
|
||||
{
|
||||
userRole = ( String ) session.getAttribute( sessionUserRole );
|
||||
empresaId = ( String ) session.getAttribute( sessionEmpresaId );
|
||||
|
||||
if( userRole.equals( "manager" ) )
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, ( String ) session.getAttribute( sessionEmpresaId ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, userRole ) );
|
||||
}
|
||||
if ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) )
|
||||
{
|
||||
Class.forName( bdDriver );
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( " SELECT id, nome, nome_plain FROM estabelecimentos WHERE inactivo <> 'y' AND empresa_id = '" + empresaId
|
||||
+ "' order by nome_plain" );
|
||||
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
|
||||
|
||||
int index = 0;
|
||||
int max = rs.columnLength();
|
||||
|
||||
while ( index < max )
|
||||
{
|
||||
temp = "" + rs.get( index, 0 ); // converter de int para
|
||||
// String
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "/" + servletName + "/?" + empresaId + "/" + temp ); // contruir
|
||||
// url
|
||||
links.add( dbQuery.toString() );
|
||||
desc.add( ( String ) rs.get( index, 1 ) );
|
||||
++index;
|
||||
}
|
||||
sBuffer = new StringBuffer();
|
||||
sBuffer.append( "<b>" + super.nomeEmpresa( con, empresaId ) + "</b>" );
|
||||
|
||||
if ( userRole.equals( "manager" ) )
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, ( String ) session.getAttribute( sessionEmpresaId ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, userRole ) );
|
||||
}
|
||||
|
||||
session.setAttribute( sessionCompanyEmail, emailEmpresa( con, empresaId ) );
|
||||
session.setAttribute( sessionCompanyEmail, emailEmpresa( con, empresaId ) );
|
||||
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , sBuffer.toString() ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, super.queryStringEstabelecimentos );
|
||||
hmValues.put( templateVector1,links);
|
||||
hmValues.put( templateVector2,desc);
|
||||
hmValues.put( templateVector3,null);
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
Map< String, Object > hmValues = new HashMap< String, Object >();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate, sBuffer.toString() );
|
||||
hmValues.put( templateUserRole, userRole );
|
||||
hmValues.put( templateQuery, queryStringEstabelecimentos );
|
||||
hmValues.put( templateVector1, links );
|
||||
hmValues.put( templateVector2, desc );
|
||||
hmValues.put( templateVector3, null );
|
||||
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
|
||||
|
||||
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringEstabelecimentos, links, desc, null, super.authenticatedUserTemplate) );
|
||||
stmt.close();
|
||||
con.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
// out.println( mergeTemplate( sBuffer.toString(), userRole,
|
||||
// super.queryStringEstabelecimentos, links, desc, null,
|
||||
// super.authenticatedUserTemplate) );
|
||||
stmt.close();
|
||||
con.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgErroBd, errorTemplate ) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,152 +1,142 @@
|
||||
package com.evolute.siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.evolute.utils.arrays.ResultSet2DArray;
|
||||
|
||||
public class doPostLogin extends siprpServlet
|
||||
{
|
||||
|
||||
/** Creates a new instance of doPostLogin */
|
||||
public doPostLogin(HttpServletRequest req, HttpServletResponse res) throws IOException
|
||||
{
|
||||
System.out.println( "doPostLogin()" );
|
||||
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
StringBuffer dbQuery;
|
||||
ResultSet2DArray rs;
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
String user, userRole, password;
|
||||
|
||||
try
|
||||
{
|
||||
user = req.getParameter("user");
|
||||
password = req.getParameter("password");
|
||||
|
||||
if (user.equals(""))
|
||||
{
|
||||
String msgErro = msgErroNoUser.replace( '+', ' ' );
|
||||
out.println( mergeTemplate( msgErro, indexTemplate ) );
|
||||
|
||||
// out.println( mergeTemplate( msgErroNoUser, errorTemplate) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Class.forName( bdDriver );
|
||||
con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT password FROM users WHERE username = '"+user+"'");
|
||||
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
|
||||
if ( rs.columnLength() > 0 && password.equals((String)rs.get(0,0)))
|
||||
{
|
||||
// Obter Role
|
||||
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT role FROM roles WHERE username = '"+user+"'");
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
userRole = (String)rs.get(0,0);
|
||||
|
||||
// UPDATE HTTP SESSION
|
||||
HttpSession session = req.getSession(true);
|
||||
session.setMaxInactiveInterval(sessionTimeout);
|
||||
|
||||
session.setAttribute(sessionUser, user);
|
||||
session.setAttribute(sessionUserRole, userRole);
|
||||
session.setAttribute(sessionPassword, password);
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
session.setAttribute( sessionEmpresaId, userRole );
|
||||
if( userRole.equals( "manager" ) )
|
||||
{
|
||||
// session.setAttribute( sessionCompanyName, nomeEmpresa( con, "" + session.getAttribute( sessionEmpresaId ) ) );
|
||||
session.setAttribute( sessionCompanyName, null );
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
//hmValues.put( templateQuery, super.queryStringEmpresas );
|
||||
new doGetListaEmpresas( req, res );
|
||||
}
|
||||
else
|
||||
{
|
||||
session.setAttribute( sessionCompanyName,
|
||||
nomeEmpresa( DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword ),
|
||||
userRole ) );
|
||||
session.setAttribute( sessionEstabelecimentoId, "-1" );
|
||||
//hmValues.put( templateQuery, super.queryStringEstabelecimentos );
|
||||
new doGetListaEstabelecimentos( req, res );
|
||||
}
|
||||
stmt.close();
|
||||
con.close();
|
||||
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", user );
|
||||
//out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
|
||||
//out.println( mergeTemplate( user, userRole, super.authenticatedUserTemplate));
|
||||
}
|
||||
else
|
||||
{
|
||||
String msgErro = msgErroAuthFail.replace( '+', ' ' );
|
||||
out.println( mergeTemplate( msgErro, indexTemplate ) );
|
||||
|
||||
// out.println( mergeTemplate( msgErroAuthFail, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
doErro( "erro=" + msgErroBd, out );
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// out.println( mergeTemplate( msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
doErro( "erro=" + msgSessionTimeout, out );
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
doErro( "erro=" + msgGenericError, out );
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// out.println( mergeTemplate( msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public doPostLogin( HttpServletRequest req, HttpServletResponse res ) throws IOException
|
||||
{
|
||||
System.out.println( "doPostLogin()" );
|
||||
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
StringBuffer dbQuery;
|
||||
ResultSet2DArray rs;
|
||||
Connection con = null;
|
||||
Statement stmt = null;
|
||||
String user, userRole, password;
|
||||
|
||||
try
|
||||
{
|
||||
user = req.getParameter( "user" );
|
||||
password = req.getParameter( "password" );
|
||||
|
||||
if ( user.equals( "" ) )
|
||||
{
|
||||
String msgErro = msgErroNoUser.replace( '+', ' ' );
|
||||
out.println( mergeTemplate( msgErro, indexTemplate ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Class.forName( bdDriver );
|
||||
con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT password FROM users WHERE username = '" + user + "'" );
|
||||
|
||||
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
|
||||
|
||||
if ( rs.columnLength() > 0 && password.equals( ( String ) rs.get( 0, 0 ) ) )
|
||||
{
|
||||
// Obter Role
|
||||
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT role FROM roles WHERE username = '" + user + "'" );
|
||||
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
||||
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
|
||||
userRole = ( String ) rs.get( 0, 0 );
|
||||
|
||||
// UPDATE HTTP SESSION
|
||||
HttpSession session = req.getSession( true );
|
||||
session.setMaxInactiveInterval( sessionTimeout );
|
||||
|
||||
session.setAttribute( sessionUser, user );
|
||||
session.setAttribute( sessionUserRole, userRole );
|
||||
session.setAttribute( sessionPassword, password );
|
||||
|
||||
Map< String, Object > hmValues = new HashMap< String, Object >();
|
||||
session.setAttribute( sessionEmpresaId, userRole );
|
||||
if ( userRole.equals( "manager" ) )
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, null );
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
new doGetListaEmpresas( req, res );
|
||||
}
|
||||
else
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword ),
|
||||
userRole ) );
|
||||
session.setAttribute( sessionEstabelecimentoId, "-1" );
|
||||
new doGetListaEstabelecimentos( req, res );
|
||||
}
|
||||
stmt.close();
|
||||
con.close();
|
||||
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", user );
|
||||
}
|
||||
else
|
||||
{
|
||||
String msgErro = msgErroAuthFail.replace( '+', ' ' );
|
||||
out.println( mergeTemplate( msgErro, indexTemplate ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
doErro( "erro=" + msgErroBd, out );
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
doErro( "erro=" + msgSessionTimeout, out );
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
doErro( "erro=" + msgGenericError, out );
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue