void login2::sLogin() { QSqlDatabase db; QString databaseURL; databaseURL = _databaseURL; /* if(_cloudOption->isChecked()) { if(_demoOption->isChecked()) databaseURL = _cloudDatabaseURL.arg(_company->text().trimmed(), "demo"); else databaseURL = _cloudDatabaseURL.arg(_company->text().trimmed(), "quickstart"); } */ QString protocol; QString hostName; QString dbName; QString port; parseDatabaseURL(databaseURL, protocol, hostName, dbName, port); if (_splash) { _splash->show(); _splash->raise(); _splash->showMessage(tr("Initializing the Database Connector"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } // Open the Database Driver if (_multipleConnections) db = QSqlDatabase::addDatabase("QPSQL7", dbName); else db = QSqlDatabase::addDatabase("QPSQL7"); if (!db.isValid()) { if (_splash) _splash->hide(); QMessageBox::warning( this, tr("No Database Driver"), tr("<p>A connection could not be established with " "the specified Database as the Proper Database " "Drivers have not been installed. Contact your " "Systems Administator.")); return; } if(hostName.isEmpty() || dbName.isEmpty()) { if (_splash) _splash->hide(); QMessageBox::warning(this, tr("Incomplete Connection Options"), tr("<p>One or more connection options are missing. " "Please check that you have specified the host " "name, database name, and any other required " "options.") ); return; } db.setDatabaseName(dbName); db.setHostName(hostName); db.setPort(port.toInt()); _cUsername = _username->text().trimmed(); _cPassword = _password->text().trimmed(); //_cCompany = _company->text().trimmed(); setCursor(QCursor(Qt::WaitCursor)); qApp->processEvents(); if (_splash) { _splash->showMessage(tr("Connecting to the Database"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } /* if(_cloudOption->isChecked()) { if(_cCompany.isEmpty()) { QMessageBox::warning(this, tr("Incomplete Connection Options"), tr("<p>You must specify the Cloud ID name to connect to the cloud.")); return; } } */ db.setUserName(_cUsername); QRegExp xtuplecloud(".*\\.xtuplecloud\\.com"); QRegExp xtuple(".*\\.xtuple\\.com"); bool isCloud = xtuplecloud.exactMatch(hostName); bool isXtuple = xtuple.exactMatch(hostName); QString salt; if(isCloud || isXtuple) { salt = "private"; } else { salt = "xTuple"; } // try connecting to the database in each of the following ways in this order QList<QPair<QString, QString> > method; method << QPair<QString, QString>("requiressl=1", QMd5(QString(_cPassword + salt + _cUsername))) << QPair<QString, QString>("requiressl=1", _cPassword) << QPair<QString, QString>("requiressl=1", QMd5(QString(_cPassword + "OpenMFG" + _cUsername))) << QPair<QString, QString>("", QMd5(QString(_cPassword + salt + _cUsername))) << QPair<QString, QString>("", _cPassword) << QPair<QString, QString>("", QMd5(QString(_cPassword + "OpenMFG" + _cUsername))) ; int methodidx; // not declared in for () because we'll need it later for (methodidx = 0; methodidx < method.size(); methodidx++) { db.setConnectOptions(method.at(methodidx).first); db.setPassword(method.at(methodidx).second); if (db.open()) break; // break instead of for-loop condition to preserve methodidx } // if connected using OpenMFG enhanced auth, remangle the password if (db.isOpen() && (methodidx == 2 || methodidx == 5)) XSqlQuery chgpass(QString("ALTER USER \"%1\" WITH PASSWORD '%2'") .arg(_cUsername, QMd5(QString(_cPassword + "xTuple" + _cUsername)))); else if (db.isOpen() && method.at(methodidx).first.isEmpty()) { XSqlQuery sslq("SHOW ssl;"); //TODO: Add SSL to installer and require it by default for all xTuple users /*if (sslq.first() && sslq.value("ssl").toString() != "on") QMessageBox::warning(this, tr("Could Not Enforce Security"), tr("The connection to the xTuple ERP Server is not " "secure. Please ask your administrator to set " "the 'ssl' configuration option to 'on'."));*/ } if (! db.isOpen()) { if (_splash) _splash->hide(); setCursor(QCursor(Qt::ArrowCursor)); QMessageBox::critical(this, tr("Cannot Connect to xTuple ERP Server"), tr("<p>Sorry, can't connect to the specified xTuple ERP server. " "<p>This may be due to a problem with your user name, password, or server connection information. " "<p>Below is more detail on the connection problem: " "<p>%1" ).arg(db.lastError().text())); if (!_captive) { _username->setText(""); _username->setFocus(); } else _password->setFocus(); _password->setText(""); return; } /* xtsettingsSetValue("/xTuple/_demoOption", (bool)_demoOption->isChecked()); xtsettingsSetValue("/xTuple/_cloudOption", (bool)_cloudOption->isChecked()); xtsettingsSetValue("/xTuple/cloud_company", _company->text()); */ if (_splash) { _splash->showMessage(tr("Logging into the Database"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } if(!_nonxTupleDB) { QString loginqry = ""; if (_setSearchPath) loginqry="SELECT login(true) AS result, CURRENT_USER AS user;"; else loginqry="SELECT login() AS result, CURRENT_USER AS user;"; XSqlQuery login( loginqry ); setCursor(QCursor(Qt::ArrowCursor)); if (login.first()) { int result = login.value("result").toInt(); if (result < 0) { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("Error Logging In"), storedProcErrorLookup("login", result)); return; } _user = login.value("user").toString(); _databaseURL = databaseURL; updateRecentOptions(); if (login.exec("SELECT getEffectiveXtUser() AS user;") && login.first() && ! login.value("user").toString().isEmpty()) _user = login.value("user").toString(); // no error check - older databases don't have getEffectiveXtUser accept(); } else if (login.lastError().type() != QSqlError::NoError) { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("System Error"), tr("A System Error occurred at %1::%2:\n%3") .arg(__FILE__).arg(__LINE__) .arg(login.lastError().databaseText())); } else { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("System Error"), tr("<p>An unknown error occurred at %1::%2. You may" " not log in to the specified xTuple ERP Server " "at this time.") .arg(__FILE__).arg(__LINE__)); } } else { setCursor(QCursor(Qt::ArrowCursor)); _databaseURL = databaseURL; updateRecentOptions(); accept(); } }
void login2::sLogin() { QSqlDatabase db; QString databaseURL; databaseURL = _databaseURL; if (_demoOption->isChecked()) databaseURL = _evalDatabaseURL.arg(_username->text().trimmed()); QString protocol; QString hostName; QString dbName; QString port; parseDatabaseURL(databaseURL, protocol, hostName, dbName, port); if (_splash) { _splash->show(); _splash->raise(); _splash->showMessage(tr("Initializing the Database Connector"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } // Open the Database Driver if (_multipleConnections) db = QSqlDatabase::addDatabase("QPSQL7", dbName); else db = QSqlDatabase::addDatabase("QPSQL7"); if (!db.isValid()) { if (_splash) _splash->hide(); QMessageBox::warning( this, tr("No Database Driver"), tr("<p>A connection could not be established with " "the specified Database as the Proper Database " "Drivers have not been installed. Contact your " "Systems Administator.")); return; } if(hostName.isEmpty() || dbName.isEmpty()) { if (_splash) _splash->hide(); QMessageBox::warning(this, tr("Incomplete Connection Options"), tr("<p>One or more connection options are missing. " "Please check that you have specified the host " "name, database name, and any other required " "options.") ); return; } db.setDatabaseName(dbName); db.setHostName(hostName); db.setPort(port.toInt()); _cUsername = _username->text().trimmed(); _cPassword = _password->text().trimmed(); db.setUserName(_cUsername); if(_demoOption->isChecked()) { QString passwd = QMd5(QString(_cPassword + "private" + _cUsername)); db.setPassword(passwd); } else { if(_enhancedAuth) { QString passwd = QMd5(QString(_cPassword + "xTuple" + _cUsername)); db.setPassword(passwd); } else db.setPassword(_cPassword); if(_requireSSL) db.setConnectOptions("requiressl=1"); } setCursor(QCursor(Qt::WaitCursor)); if (_splash) { _splash->showMessage(tr("Connecting to the Database"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } // Try to connect to the Database bool result = db.open(); if(!result && _enhancedAuth) { QString altpasswd = QMd5(QString(_cPassword + "OpenMFG" + _cUsername)); db.setPassword(altpasswd); result = db.open(); if(result) { altpasswd = QMd5(QString(_cPassword + "xTuple" + _cUsername)); XSqlQuery chgpass(QString("ALTER USER %1 WITH PASSWORD '%2'").arg(_cUsername).arg(altpasswd)); } } if (!result) { if(_requireSSL) db.setConnectOptions(); if (_splash) _splash->hide(); setCursor(QCursor(Qt::ArrowCursor)); QMessageBox::critical(this, tr("Cannot Connect to xTuple ERP Server"), tr("<p>A connection to the specified xTuple ERP " "Server cannot be made. This may be due to an " "incorrect Username and/or Password or the " "server in question cannot support any more " "connections.<p>Please verify your Username and " "Password and try again or wait until the " "specified xTuple ERP Server is less busy.<br>" "System Error<pre>%1" ) .arg(db.lastError().driverText() )); if (!_captive) { _username->setText(""); _username->setFocus(); } else _password->setFocus(); _password->setText(""); return; } xtsettingsSetValue("/xTuple/_demoOption", (bool)_demoOption->isChecked()); if (_splash) { _splash->showMessage(tr("Logging into the Database"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } if(!_nonxTupleDB) { XSqlQuery login( "SELECT login() AS result," " CURRENT_USER AS user;" ); setCursor(QCursor(Qt::ArrowCursor)); if (login.first()) { int result = login.value("result").toInt(); if (result < 0) { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("Error Logging In"), storedProcErrorLookup("login", result)); return; } _user = login.value("user").toString(); _databaseURL = databaseURL; updateRecentOptions(); accept(); } else if (login.lastError().type() != QSqlError::NoError) { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("System Error"), tr("A System Error occurred at %1::%2:\n%1") .arg(__FILE__).arg(__LINE__) .arg(login.lastError().databaseText())); } else { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("System Error"), tr("<p>An unknown error occurred at %1::%2. You may" " not log in to the specified xTuple ERP Server " "at this time.") .arg(__FILE__).arg(__LINE__)); } } else { setCursor(QCursor(Qt::ArrowCursor)); _databaseURL = databaseURL; updateRecentOptions(); accept(); } }
void login2::sLogin() { QSqlDatabase db; QString databaseURL; databaseURL = _databaseURL; if (_demoOption->isChecked()) databaseURL = _evalDatabaseURL.arg(_username->text().trimmed()); else if(_cloudOption->isChecked()) databaseURL = _cloudDatabaseURL.arg(_company->text().trimmed()); QString protocol; QString hostName; QString dbName; QString port; parseDatabaseURL(databaseURL, protocol, hostName, dbName, port); if (_splash) { _splash->show(); _splash->raise(); _splash->showMessage(tr("Initializing the Database Connector"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } // Open the Database Driver if (_multipleConnections) db = QSqlDatabase::addDatabase("QPSQL7", dbName); else db = QSqlDatabase::addDatabase("QPSQL7"); if (!db.isValid()) { if (_splash) _splash->hide(); QMessageBox::warning( this, tr("No Database Driver"), tr("<p>A connection could not be established with " "the specified Database as the Proper Database " "Drivers have not been installed. Contact your " "Systems Administator.")); return; } if(hostName.isEmpty() || dbName.isEmpty()) { if (_splash) _splash->hide(); QMessageBox::warning(this, tr("Incomplete Connection Options"), tr("<p>One or more connection options are missing. " "Please check that you have specified the host " "name, database name, and any other required " "options.") ); return; } db.setDatabaseName(dbName); db.setHostName(hostName); db.setPort(port.toInt()); _cUsername = _username->text().trimmed(); _cPassword = _password->text().trimmed(); _cCompany = _company->text().trimmed(); if(_cloudOption->isChecked()) { if(_cCompany.isEmpty()) { QMessageBox::warning(this, tr("Incomplete Connection Options"), tr("<p>You must specify the Company name to connect to the cloud.")); return; } _cUsername = _cUsername + "_" + _cCompany; } db.setUserName(_cUsername); if(_demoOption->isChecked()) { QString passwd = QMd5(QString(_cPassword + "private" + _cUsername)); db.setPassword(passwd); } else if(_cloudOption->isChecked()) { QString passwd = QMd5(QString(_cPassword + "cloudkey" + _cUsername)); db.setPassword(passwd); } else { if(_enhancedAuth) { QString passwd = QMd5(QString(_cPassword + "xTuple" + _cUsername)); db.setPassword(passwd); } else db.setPassword(_cPassword); if(_requireSSL) db.setConnectOptions("requiressl=1"); } setCursor(QCursor(Qt::WaitCursor)); if (_splash) { _splash->showMessage(tr("Connecting to the Database"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } // Try to connect to the Database bool result = db.open(); if(!result && _enhancedAuth) { QString altpasswd = QMd5(QString(_cPassword + "OpenMFG" + _cUsername)); db.setPassword(altpasswd); result = db.open(); if(result) { altpasswd = QMd5(QString(_cPassword + "xTuple" + _cUsername)); XSqlQuery chgpass(QString("ALTER USER %1 WITH PASSWORD '%2'").arg(_cUsername).arg(altpasswd)); } } if (!result) { if(_requireSSL) db.setConnectOptions(); if (_splash) _splash->hide(); setCursor(QCursor(Qt::ArrowCursor)); QMessageBox::critical(this, tr("Cannot Connect to xTuple ERP Server"), tr("<p>Sorry, can't connect to the specified xTuple ERP server. " "<p>This may be due to a problem with your user name, password, or server connection information. " "<p>Below is more detail on the connection problem: " "<p>%1" ) .arg(db.lastError().databaseText().replace('\n', "<br>") )); if (!_captive) { _username->setText(""); _username->setFocus(); } else _password->setFocus(); _password->setText(""); return; } xtsettingsSetValue("/xTuple/_demoOption", (bool)_demoOption->isChecked()); xtsettingsSetValue("/xTuple/_cloudOption", (bool)_cloudOption->isChecked()); xtsettingsSetValue("/xTuple/cloud_company", _company->text()); if (_splash) { _splash->showMessage(tr("Logging into the Database"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); } if(!_nonxTupleDB) { XSqlQuery login( "SELECT login() AS result," " CURRENT_USER AS user;" ); setCursor(QCursor(Qt::ArrowCursor)); if (login.first()) { int result = login.value("result").toInt(); if (result < 0) { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("Error Logging In"), storedProcErrorLookup("login", result)); return; } _user = login.value("user").toString(); _databaseURL = databaseURL; updateRecentOptions(); if (login.exec("SELECT getEffectiveXtUser() AS user;") && login.first() && ! login.value("user").toString().isEmpty()) _user = login.value("user").toString(); // no error check - older databases don't have getEffectiveXtUser accept(); } else if (login.lastError().type() != QSqlError::NoError) { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("System Error"), tr("A System Error occurred at %1::%2:\n%3") .arg(__FILE__).arg(__LINE__) .arg(login.lastError().databaseText())); } else { if (_splash) _splash->hide(); QMessageBox::critical(this, tr("System Error"), tr("<p>An unknown error occurred at %1::%2. You may" " not log in to the specified xTuple ERP Server " "at this time.") .arg(__FILE__).arg(__LINE__)); } } else { setCursor(QCursor(Qt::ArrowCursor)); _databaseURL = databaseURL; updateRecentOptions(); accept(); } }