Merge pull request #960 from gradido/add_autocorrect_keys

Add autocorrect keys
This commit is contained in:
einhornimmond 2021-10-12 17:00:36 +02:00 committed by GitHub
commit 29de8e224f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 6 deletions

View File

@ -47,7 +47,22 @@ export class UserResolver {
const user = new User(result.data.user)
// read additional settings from settings table
const userRepository = getCustomRepository(UserRepository)
const userEntity = await userRepository.findByPubkeyHex(user.pubkey)
let userEntity: void | DbUser
userEntity = await userRepository.findByPubkeyHex(user.pubkey).catch(() => {
userEntity = new DbUser()
userEntity.firstName = user.firstName
userEntity.lastName = user.lastName
userEntity.username = user.username
userEntity.email = user.email
userEntity.pubkey = Buffer.from(fromHex(user.pubkey))
userEntity.save().catch(() => {
throw new Error('error by save userEntity')
})
})
if (!userEntity) {
throw new Error('error with cannot happen')
}
const userSettingRepository = getCustomRepository(UserSettingRepository)
const coinanimation = await userSettingRepository

View File

@ -328,6 +328,7 @@ const Poco::UInt16* Passphrase::getWordIndices() const
bool Passphrase::checkIfValid()
{
if (!mWordSource) return false;
std::istringstream iss(mPassphraseString);
std::vector<std::string> results(std::istream_iterator<std::string>{iss},
std::istream_iterator<std::string>());

View File

@ -81,22 +81,30 @@ void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Po
}
if (json_result) {
NotificationList errors;
if (!json_result->isNull("session_id")) {
int session_id = 0;
try {
json_result->get("session_id").convert(session_id);
}
catch (Poco::Exception& e) {
NotificationList erros;
erros.addError(new Error("json request", "invalid session_id"));
erros.sendErrorsAsEmail();
errors.addError(new Error("json request", "invalid session_id"));
}
if (session_id) {
auto session = SessionManager::getInstance()->getSession(session_id);
response.addCookie(session->getLoginCookie());
}
}
json_result->stringify(responseStream);
try {
json_result->stringify(responseStream);
}
catch (Poco::Exception& e) {
errors.addError(new ParamError("json request", "error on stringify from json result:", e.message()));
errors.addError(new ParamError("json request", "caller url", request.getURI()));
}
if (errors.errorCount()) {
errors.sendErrorsAsEmail();
}
delete json_result;
}

View File

@ -115,6 +115,14 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params)
auto user_model = session->getNewUser()->getModel();
Poco::JSON::Array infos;
// AUTOMATIC ERROR CORRECTION
// if something went wrong by initial key generation for user, generate keys again
if (user_state >= USER_LOADED_FROM_DB && !user_model->getPublicKey()) {
if (session->generateKeys(true, true)) {
user_state = session->getNewUser()->getUserState();
}
}
switch (user_state) {
case USER_EMPTY:
case USER_PASSWORD_INCORRECT:

View File

@ -746,7 +746,7 @@ void Session::detectSessionState()
bool cryptedPassphrase = userBackups.size() > 0;
for (auto it = userBackups.begin(); it != userBackups.end(); it++) {
auto passphrase = (*it)->getModel()->getPassphrase();
Mnemonic* wordSource = nullptr;
const Mnemonic* wordSource = Passphrase::detectMnemonic(passphrase);
auto passphrase_obj = Passphrase::create(passphrase, wordSource);
if (!passphrase_obj.isNull() && passphrase_obj->checkIfValid()) {
auto key_pair = KeyPairEd25519::create(passphrase_obj);