use of org.compiere.util.Login in project adempiere by adempiere.
the class WFieldUpdate method reply_Login2_Org.
// reply_Login2_Client
/**
* Login 2nd page Response - Field Org.
* <p>
* fill Warehouse
* @param body document body
* @param wsc web session context
* @param formName
* @param fieldValue
*/
private static void reply_Login2_Org(body body, WebSessionCtx wsc, WWindowStatus ws, String formName, String fieldValue, String locationValue) {
// Formname
String form = null;
log.info("Location-Org: " + locationValue);
//if (locationValue!=null)
form = locationValue + WebEnv.TARGET_WINDOW + ".document." + formName + ".";
//else
//form = "top." + WebEnv.TARGET_WINDOW + ".document." + formName + ".";
//log.info("form_org->"+form);
StringBuffer script = new StringBuffer();
// Set Warehouse ----
// var A=top.WWindow.document.formName.selectName.options;
script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; ");
// A.length=0; // resets options
script.append("C.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair org = new KeyNamePair(Integer.parseInt(fieldValue), fieldValue);
Login login = new Login(wsc.ctx);
String error = login.validateLogin(org);
if (error != null && error.length() > 0) {
//todo graceful dead
log.severe(error);
ws.mWindow = null;
wsc.ctx = new Properties();
return;
}
KeyNamePair[] whs = login.getWarehouses(org);
if (whs != null) {
for (int i = 0; i < whs.length; i++) {
KeyNamePair p = whs[i];
script.append("C[").append(i).append("]=new Option('");
// text
script.append(p.getName());
script.append("','");
// value
script.append(p.getKey());
script.append("'); ");
}
}
// add script
body.addElement(new p().addElement(WLogin.P_WAREHOUSE + "="));
body.addElement(new script(script.toString()));
// log.trace(log.l6_Database, "Login2-Org - Script=" + script.toString());
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class WFieldUpdate method reply_Login2_Role.
// getReply
/**
* Login 2nd page Response - Field Role.
* <p>
* fill Client, Org, Warehouse
* @param body document body
* @param wsc web session context
* @param formName
* @param fieldValue
*/
private static void reply_Login2_Role(body body, WebSessionCtx wsc, String formName, String fieldValue, String locationValue) {
// Formname
String form = null;
log.info("Location-Role: " + locationValue);
//if (locationValue!=null)
form = locationValue + WebEnv.TARGET_WINDOW + ".document.forms." + formName + ".";
//else
//form = "top." + WebEnv.TARGET_WINDOW + ".document.forms." + formName + ".";
//log.info("form_role->"+form);
Login login = new Login(wsc.ctx);
// Get Data
KeyNamePair[] clients = login.getClients(new KeyNamePair(Integer.parseInt(fieldValue), fieldValue));
// Set Client ----
StringBuffer script = new StringBuffer();
// var A=top.WWindow.document.formName.selectName.options;
script.append("var A=").append(form).append(WLogin.P_CLIENT).append(".options; ");
// A.length=0; // resets options
script.append("A.length=0; ");
for (int i = 0; i < clients.length; i++) {
KeyNamePair p = clients[i];
script.append("A[").append(i).append("]=new Option('");
// text
script.append(p.getName());
script.append("','");
// value
script.append(p.getKey());
script.append("'); ");
}
script.append("\n");
if (clients.length > 0) {
// var A=top.WWindow.document.formName.selectName.options;
script.append("var B=").append(form).append(WLogin.P_ORG).append(".options; ");
// A.length=0; // resets options
script.append("B.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] orgs = login.getOrgs(clients[0]);
for (int i = 0; i < orgs.length; i++) {
KeyNamePair p = orgs[i];
script.append("B[").append(i).append("]=new Option('");
// text
script.append(p.getName());
script.append("','");
// value
script.append(p.getKey());
script.append("'); ");
}
script.append("\n");
if (orgs.length > 0) {
// var A=top.WWindow.document.formName.selectName.options;
script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; ");
// A.length=0; // resets options
script.append("C.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] whs = login.getWarehouses(orgs[0]);
if (whs != null) {
for (int i = 0; i < whs.length; i++) {
KeyNamePair p = whs[i];
script.append("C[").append(i).append("]=new Option('");
// text
script.append(p.getName());
script.append("','");
// value
script.append(p.getKey());
script.append("'); ");
}
}
}
// we have a org
}
// we have a client
// add script
body.addElement(new p().addElement(WLogin.P_CLIENT + "="));
body.addElement(new script(script.toString()));
// log.trace(log.l6_Database, "reply_Login2_Role - Script=" + script.toString());
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class WFieldUpdate method reply_Login2_Client.
// reply_Login2_Role
/**
* Login 2nd page Response - Field Client.
* <p>
* fill Org & Warehouse -
* @param body body
* @param wsc context
* @param formName form name
* @param fieldValue value
*/
private static void reply_Login2_Client(body body, WebSessionCtx wsc, String formName, String fieldValue, String locationValue) {
log.info("Location-Client: " + locationValue);
// Formname
String form = null;
//if (locationValue!=null)
form = locationValue + WebEnv.TARGET_WINDOW + ".document." + formName + ".";
//else
//form = "top." + WebEnv.TARGET_WINDOW + ".document." + formName + ".";
StringBuffer script = new StringBuffer();
//log.info("form_client->"+form);
// Set Organization ----
// var A=top.WWindow.document.formName.selectName.options;
script.append("var B=").append(form).append(WLogin.P_ORG).append(".options; ");
// A.length=0; // resets options
script.append("B.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair client = new KeyNamePair(Integer.parseInt(fieldValue), fieldValue);
Login login = new Login(wsc.ctx);
KeyNamePair[] orgs = login.getOrgs(client);
for (int i = 0; i < orgs.length; i++) {
KeyNamePair p = orgs[i];
script.append("B[").append(i).append("]=new Option('");
// text
script.append(p.getName());
script.append("','");
// value
script.append(p.getKey());
script.append("'); ");
}
script.append("\n");
// Set Warehouse ----
// var A=top.WWindow.document.formName.selectName.options;
script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; ");
// A.length=0; // resets options
script.append("C.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] whs = login.getWarehouses(orgs[0]);
if (whs != null) {
for (int i = 0; i < whs.length; i++) {
KeyNamePair p = whs[i];
script.append("C[").append(i).append("]=new Option('");
// text
script.append(p.getName());
script.append("','");
// value
script.append(p.getKey());
script.append("'); ");
}
}
// add script
body.addElement(new p().addElement(WLogin.P_WAREHOUSE + "="));
body.addElement(new script(script.toString()));
// log.trace(log.l6_Database, "Login2-Client - Script=" + script.toString());
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class ALogin method tryConnection.
// defaultsOK
/**************************************************************************
* Try to connect.
* - Get Connection
* - Compare User info
* @return true if connected
*/
private boolean tryConnection() {
m_user = userTextField.getText();
m_pwd = new String(passwordField.getPassword());
// Establish connection
if (!DB.isConnected(false))
validateConnection();
if (!DB.isConnected(false)) {
statusBar.setStatusLine(txt_NoDatabase, true);
hostField.setBackground(AdempierePLAF.getFieldBackground_Error());
return false;
}
// Reference check
Ini.setProperty(Ini.P_ADEMPIERESYS, "Reference".equalsIgnoreCase(CConnection.get().getDbUid()));
// Reference check
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, "Reference".equalsIgnoreCase(CConnection.get().getDbUid()));
// Get Roles
m_login = new Login(m_ctx);
KeyNamePair[] roles = null;
try {
roles = m_login.getRoles(m_user, m_pwd);
if (roles == null || roles.length == 0) {
statusBar.setStatusLine(txt_UserPwdError, true);
userTextField.setBackground(AdempierePLAF.getFieldBackground_Error());
passwordField.setBackground(AdempierePLAF.getFieldBackground_Error());
return false;
}
} catch (Throwable e) {
if (e.getCause() instanceof AccessException) {
statusBar.setStatusLine(txt_UserPwdError, true);
userTextField.setBackground(AdempierePLAF.getFieldBackground_Error());
passwordField.setBackground(AdempierePLAF.getFieldBackground_Error());
return false;
} else {
log.severe(CLogger.getRootCause(e).getLocalizedMessage());
statusBar.setStatusLine(CLogger.getRootCause(e).getLocalizedMessage(), true);
return false;
}
}
// Delete existing role items
m_comboActive = true;
if (roleCombo.getItemCount() > 0)
roleCombo.removeAllItems();
// Initial role
KeyNamePair iniValue = null;
String iniDefault = Ini.getProperty(Ini.P_ROLE);
// fill roles
for (int i = 0; i < roles.length; i++) {
roleCombo.addItem(roles[i]);
if (roles[i].getName().equals(iniDefault))
iniValue = roles[i];
}
if (iniValue != null)
roleCombo.setSelectedItem(iniValue);
// If we have only one role, we can hide the combobox - metas-2009_0021_AP1_G94
if (roleCombo.getItemCount() == 1 && !MSysConfig.getBooleanValue("ALogin_ShowOneRole", true)) {
roleCombo.setSelectedIndex(0);
roleLabel.setVisible(false);
roleCombo.setVisible(false);
} else {
roleLabel.setVisible(true);
roleCombo.setVisible(true);
}
userTextField.setBackground(AdempierePLAF.getFieldBackground_Normal());
passwordField.setBackground(AdempierePLAF.getFieldBackground_Normal());
//
this.setTitle(hostField.getDisplay());
statusBar.setStatusLine(txt_LoggedIn);
m_comboActive = false;
roleComboChanged();
return true;
}
use of org.compiere.util.Login in project adempiere by adempiere.
the class AdempiereLoginModule method login.
/**
* Perform login process
*/
public boolean login() throws LoginException {
//get username and password from standard callback
Callback[] callbacks = new Callback[] { new NameCallback("Login:"), new PasswordCallback("Password:", false) };
try {
handler.handle(callbacks);
} catch (IOException e) {
} catch (UnsupportedCallbackException e) {
}
name = ((NameCallback) callbacks[0]).getName();
char[] pass = ((PasswordCallback) callbacks[1]).getPassword();
String passwd = pass != null ? new String(pass) : null;
//do authentication
if (name != null && passwd != null) {
//perform db authentication
Login login = new Login(Env.getCtx());
roles = login.getRoles(name, passwd);
} else {
//no username or password
roles = null;
}
return true;
}
Aggregations