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