1334 QString hash = config->passwordHash(); |
1334 QString hash = config->passwordHash(); |
1335 QString temphash = config->tempHash(); |
1335 QString temphash = config->tempHash(); |
1336 QString nickname = config->value("net/nick", "").toString(); |
1336 QString nickname = config->value("net/nick", "").toString(); |
1337 QString password; |
1337 QString password; |
1338 |
1338 |
1339 if (nickname.isEmpty() || hash.isEmpty()) { //if something from login is missing, start dialog loop |
1339 //if something from login is missing, start dialog loop |
1340 |
1340 if (nickname.isEmpty() || hash.isEmpty()) |
|
1341 { |
1341 while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing |
1342 while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing |
1342 { |
1343 { |
1343 //open dialog |
1344 //open dialog |
1344 HWPasswordDialog * pwDialog = new HWPasswordDialog(this); |
1345 HWPasswordDialog * pwDialog = new HWPasswordDialog(this); |
1345 // make the "new account" button dialog open a browser with the registration page |
1346 // make the "new account" button dialog open a browser with the registration page |
1346 connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage())); |
1347 connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage())); |
1347 pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool()); |
1348 pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool()); |
1348 |
1349 |
1349 //if nickname is present, put it into the field |
1350 //if nickname is present, put it into the field |
1350 if (!nickname.isEmpty()) { |
1351 if (!nickname.isEmpty()) { |
1351 pwDialog->leNickname->setText(nickname); |
1352 pwDialog->leNickname->setText(nickname); |
1352 pwDialog->lePassword->setFocus(); |
1353 pwDialog->lePassword->setFocus(); |
1353 } |
1354 } |
1354 |
1355 |
1355 //if dialog close, create an error message |
1356 //if dialog close, create an error message |
1356 if (pwDialog->exec() != QDialog::Accepted) { |
1357 if (pwDialog->exec() != QDialog::Accepted) { |
|
1358 delete pwDialog; |
|
1359 GoBack(); |
|
1360 return; |
|
1361 } |
|
1362 |
|
1363 //set nick and pass from the dialog |
|
1364 nickname = pwDialog->leNickname->text(); |
|
1365 password = pwDialog->lePassword->text(); |
|
1366 |
|
1367 //check the nickname variable |
|
1368 if (nickname.isEmpty()) { |
|
1369 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
|
1370 GoBack(); |
|
1371 delete pwDialog; |
|
1372 if (retry) { |
|
1373 NetConnectOfficialServer(); |
|
1374 } |
|
1375 return; |
|
1376 } |
|
1377 |
|
1378 if (!password.isEmpty()) { |
|
1379 //calculate temphash and set it into config |
|
1380 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
|
1381 config->setTempHash(temphash); |
|
1382 |
|
1383 //if user wants to save password |
|
1384 bool save = pwDialog->cbSave->isChecked(); |
|
1385 config->setValue("net/savepassword", save); |
|
1386 if (save) // user wants to save password |
|
1387 { |
|
1388 ui.pageOptions->CBSavePassword->setChecked(true); |
|
1389 config->setPasswordHash(temphash); |
|
1390 } |
|
1391 } |
|
1392 else { |
|
1393 delete pwDialog; |
|
1394 config->setValue("net/nick", nickname); |
|
1395 config->updNetNick(); |
|
1396 config->clearPasswordHash(); |
|
1397 break; |
|
1398 } |
|
1399 |
1357 delete pwDialog; |
1400 delete pwDialog; |
1358 GoBack(); |
1401 |
1359 return; |
1402 //update nickname |
1360 } |
|
1361 |
|
1362 //set nick and pass from the dialog |
|
1363 nickname = pwDialog->leNickname->text(); |
|
1364 password = pwDialog->lePassword->text(); |
|
1365 |
|
1366 //check the nickname variable |
|
1367 if (nickname.isEmpty()) { |
|
1368 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
|
1369 GoBack(); |
|
1370 delete pwDialog; |
|
1371 if (retry) { |
|
1372 NetConnectOfficialServer(); |
|
1373 } |
|
1374 return; |
|
1375 } |
|
1376 |
|
1377 if (!password.isEmpty()) { |
|
1378 //calculate temphash and set it into config |
|
1379 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
|
1380 config->setTempHash(temphash); |
|
1381 |
|
1382 //if user wants to save password |
|
1383 bool save = pwDialog->cbSave->isChecked(); |
|
1384 config->setValue("net/savepassword", save); |
|
1385 if (save) // user wants to save password |
|
1386 { |
|
1387 config->setPasswordHash(temphash); |
|
1388 } |
|
1389 } |
|
1390 else { |
|
1391 delete pwDialog; |
|
1392 config->setValue("net/nick", nickname); |
1403 config->setValue("net/nick", nickname); |
1393 config->updNetNick(); |
1404 config->updNetNick(); |
1394 config->clearPasswordHash(); |
1405 |
1395 break; |
1406 //and all the variables |
1396 } |
1407 hash = config->passwordHash(); |
1397 |
1408 temphash = config->tempHash(); |
1398 delete pwDialog; |
1409 nickname = config->value("net/nick", "").toString(); |
1399 |
|
1400 //update nickname |
|
1401 config->setValue("net/nick", nickname); |
|
1402 config->updNetNick(); |
|
1403 |
|
1404 //and all the variables |
|
1405 hash = config->passwordHash(); |
|
1406 temphash = config->tempHash(); |
|
1407 nickname = config->value("net/nick", "").toString(); |
|
1408 } |
1410 } |
1409 } |
1411 } |
1410 |
1412 |
1411 ui.pageRoomsList->setUser(nickname); |
1413 ui.pageRoomsList->setUser(nickname); |
1412 ui.pageNetGame->setUser(nickname); |
1414 ui.pageNetGame->setUser(nickname); |