use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WLogin method doPost.
// doGet
/**
* Process the HTTP Post request.
* <pre>
* - Optionally create Session
* - Check database connection
* - LoginInfo from request?
* - Yes: DoLogin success ?
* - Yes: return (second) preferences page
* - No: return (first) user/password page
* - No: User Principal ?
* - Yes: DoLogin success ?
* - Yes: return (second) preferences page
* - No: return (first) user/password page
* - No: return (first) user/password page
* </pre>
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("");
// Create New Session
HttpSession sess = request.getSession(true);
sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
// Get Cookie Properties
Properties cProp = WebUtil.getCookieProprties(request);
// Create Context
WebSessionCtx wsc = WebSessionCtx.get(request);
// Page
WebDoc doc = null;
// Check DB connection
if (!DB.isConnected()) {
String msg = Msg.getMsg(wsc.ctx, "WLoginNoDB");
if (msg.equals("WLoginNoDB"))
msg = "No Database Connection";
doc = WebDoc.createWindow(msg);
} else // Login Info from request?
{
// Get Parameters: UserName/Password
String usr = WebUtil.getParameter(request, P_USERNAME);
String pwd = WebUtil.getParameter(request, P_PASSWORD);
// Get Principle
Principal userPrincipal = request.getUserPrincipal();
log.info("Principal=" + userPrincipal + "; User=" + usr);
// Login info not from request and not pre-authorized
if (userPrincipal == null && (usr == null || pwd == null))
doc = createFirstPage(cProp, request, "");
else // Login info from request or authorized
{
KeyNamePair[] roles = null;
Login login = new Login(wsc.ctx);
// Pre-authorized
if (userPrincipal != null) {
roles = login.getRoles(userPrincipal);
usr = userPrincipal.getName();
} else
roles = login.getRoles(usr, pwd);
//
if (roles == null)
doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
else {
doc = createSecondPage(request, WebUtil.convertToOption(roles, null), "");
// Create adempiere Session - user id in ctx
MSession.get(wsc.ctx, request.getRemoteAddr(), request.getRemoteHost(), sess.getId());
}
// Can we save Cookie ?
if (WebUtil.getParameter(request, P_STORE) == null) {
// erase all
cProp.clear();
} else // Save Cookie Parameter
{
cProp.setProperty(P_USERNAME, usr);
cProp.setProperty(P_STORE, "Y");
// For test only
cProp.setProperty(P_PASSWORD, pwd);
}
}
}
WebUtil.createResponse(request, response, this, cProp, doc, false);
}
use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WChat method doGet.
// init
/**
* Process the HTTP Get request
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.fine("doGet");
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
//
WebDoc doc = null;
if (ws == null) {
doc = WebDoc.createPopup("No Context");
doc.addPopupClose(wsc.ctx);
} else {
doc = CreateChatPage(ws, wsc, doc, 0);
}
//
WebUtil.createResponse(request, response, this, null, doc, false);
}
use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WAccount method doGet.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.config("WAccount.doGet");
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
if (wsc == null || ws == null) {
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
String columnName = WebUtil.getParameter(request, "ColumnName");
GridField mField = ws.curTab.getField(columnName);
log.config(" ColumnName=" + columnName + ", MField=" + mField.toString());
if (mField == null || columnName == null || columnName.equals("")) {
WebUtil.createTimeoutPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
return;
}
String target = "opener.document.WForm." + columnName;
WebDoc doc = WebDoc.create(mField.getHeader());
body body = doc.getBody();
body.setOnBlur("self.focus();");
body.addElement(fillTable(ws, mField, target));
button reset = new button();
reset.addElement("Reset");
reset.setOnClick(target + "D.value='';" + target + "F.value='';window.close();");
button cancel = new button();
cancel.addElement("Cancel");
cancel.setOnClick("window.close();");
body.addElement(new p(AlignType.RIGHT).addElement(reset).addElement(" ").addElement(cancel));
WebUtil.createResponse(request, response, this, null, doc, true);
}
use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WFindAdv method doGet.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession sess = request.getSession(false);
WWindowStatus ws = null;
WebSessionCtx wsc = WebSessionCtx.get(request);
if (sess != null)
ws = WWindowStatus.get(request);
if (wsc == null) {
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
WebDoc doc = preparePage();
body body = doc.getBody();
String pTab = request.getParameter(P_Tab);
if (pTab != null && pTab.equals("FindAdv")) {
body.addElement(createPageFindAdv(request, response, ws));
} else {
body.addElement(createPageFind(request, response, ws));
}
WebUtil.createResponse(request, response, this, null, doc, true);
}
use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.
the class WReport method launchReport.
// launchReport
/**
* Launch Report
* @param pf print format
*/
private File launchReport(MPrintFormat pf, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
int Record_ID = 0;
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
//Instance pInstance = new MPInstance (wsc.ctx, 0, 0);
File fileName = null;
if (m_query.getRestrictionCount() == 1 && m_query.getCode(0) instanceof Integer) {
Record_ID = ((Integer) m_query.getCode(0)).intValue();
}
PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
info.setDescription(m_query.getInfo());
if (pf != null && pf.getJasperProcess_ID() > 0) {
// It's a report using the JasperReports engine
ProcessInfo pi = new ProcessInfo("", pf.getJasperProcess_ID());
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
// Execute Process
WProcessCtl.process(this, m_curTab.getAD_Window_ID(), pi, trx, request);
} else {
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine(wsc.ctx, pf, m_query, info);
if (re == null) {
log.info("Could not start ReportEngine");
} else {
try {
File file = File.createTempFile("WProcess", ".pdf");
boolean ok = re.createPDF(file);
if (ok) {
fileName = file;
} else {
log.info("Could not create Report");
}
} catch (Exception e) {
log.info(e.toString());
}
}
}
return fileName;
}
Aggregations