// todo: remove or add clone support ConnectionSettings::ConnectionSettings(const mongo::MongoURI& uri, bool isClone) : _connectionName(defaultNameConnection), _host(defaultServerHost), _port(port), _imported(false), _sshSettings(new SshSettings()), _sslSettings(new SslSettings()), _isReplicaSet((uri.type() == mongo::ConnectionString::ConnectionType::SET)), _replicaSetSettings(new ReplicaSetSettings(uri)), _clone(isClone), _uuid(QUuid::createUuid().toString()) // todo { if (!uri.getServers().empty()) { _host = uri.getServers().front().host(); _port = uri.getServers().front().port(); } auto str = std::string(uri.getOptions().getStringField("ssl")); auto sslEnabled = ("true" == str); if (sslEnabled) { _sslSettings->enableSSL(true); _sslSettings->setAllowInvalidCertificates(true); } auto credential = new CredentialSettings(); credential->setUserName(uri.getUser()); credential->setUserPassword(uri.getPassword()); credential->setDatabaseName(uri.getDatabase()); if (!credential->userName().empty() && !credential->userPassword().empty()) { // todo: credential->setEnabled(true); } addCredential(credential); }
QVariant CredentialSettings::toVariant() const { QVariantMap map; map.insert("userName", QtUtils::toQString(userName())); map.insert("userPassword", QtUtils::toQString(userPassword())); map.insert("databaseName", QtUtils::toQString(databaseName())); map.insert("enabled", enabled()); return map; }
//---------------------------------------------------------------------------------------------- void QLoginDialog::accept() { auto app = QBarApplication::instance(); QString user_name = ui->lineEditUser->text(); int user_id = app->userID(user_name); QPoint pos = QCursor::pos(); QString pass = app->userPassword(user_id); if(ui->lineEditPassword->text() == pass && !pass.isEmpty()) { app->setCurrentUser(user_id); auto app = QBarApplication::instance(); bool is_checked = ui->checkBoxSave->isChecked(); app->settings().setValue("login/save_password", is_checked); if(!is_checked) { pass = ""; user_name = ""; } app->settings().setValue("login/last_password", pass); app->settings().setValue("login/last_user", user_name); QString new_pwd = ui->lineEditNewPassword->text(); QString new_pwd_copy = ui->lineEditNewPasswordCopy->text(); if(!new_pwd.isEmpty()) { if(new_pwd != new_pwd_copy) { std::wstring str = L"Новый пароль не верный"; QToolTip::showText(pos, QString::fromUtf16(str.c_str()), 0, QRect(), 500); return; } else { if(false == app->changePassword(pass, new_pwd)) { std::wstring str = L"Пароль должен быть длиной от 4-х до 15-ти символов и содержать латинские буквы и цифри"; QToolTip::showText(pos, QString::fromUtf16(str.c_str()), 0, QRect(), 500); return; } } } QDialog::accept(); } else { std::wstring str = L"Неправильный логин/пароль"; QToolTip::showText(pos, QString::fromUtf16(str.c_str()), 0, QRect(), 500); } }