mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #960 from gradido/add_autocorrect_keys
Add autocorrect keys
This commit is contained in:
commit
29de8e224f
@ -47,7 +47,22 @@ export class UserResolver {
|
|||||||
const user = new User(result.data.user)
|
const user = new User(result.data.user)
|
||||||
// read additional settings from settings table
|
// read additional settings from settings table
|
||||||
const userRepository = getCustomRepository(UserRepository)
|
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 userSettingRepository = getCustomRepository(UserSettingRepository)
|
||||||
const coinanimation = await userSettingRepository
|
const coinanimation = await userSettingRepository
|
||||||
|
|||||||
@ -328,6 +328,7 @@ const Poco::UInt16* Passphrase::getWordIndices() const
|
|||||||
|
|
||||||
bool Passphrase::checkIfValid()
|
bool Passphrase::checkIfValid()
|
||||||
{
|
{
|
||||||
|
if (!mWordSource) return false;
|
||||||
std::istringstream iss(mPassphraseString);
|
std::istringstream iss(mPassphraseString);
|
||||||
std::vector<std::string> results(std::istream_iterator<std::string>{iss},
|
std::vector<std::string> results(std::istream_iterator<std::string>{iss},
|
||||||
std::istream_iterator<std::string>());
|
std::istream_iterator<std::string>());
|
||||||
|
|||||||
@ -81,22 +81,30 @@ void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Po
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (json_result) {
|
if (json_result) {
|
||||||
|
NotificationList errors;
|
||||||
if (!json_result->isNull("session_id")) {
|
if (!json_result->isNull("session_id")) {
|
||||||
int session_id = 0;
|
int session_id = 0;
|
||||||
try {
|
try {
|
||||||
json_result->get("session_id").convert(session_id);
|
json_result->get("session_id").convert(session_id);
|
||||||
}
|
}
|
||||||
catch (Poco::Exception& e) {
|
catch (Poco::Exception& e) {
|
||||||
NotificationList erros;
|
errors.addError(new Error("json request", "invalid session_id"));
|
||||||
erros.addError(new Error("json request", "invalid session_id"));
|
|
||||||
erros.sendErrorsAsEmail();
|
|
||||||
}
|
}
|
||||||
if (session_id) {
|
if (session_id) {
|
||||||
auto session = SessionManager::getInstance()->getSession(session_id);
|
auto session = SessionManager::getInstance()->getSession(session_id);
|
||||||
response.addCookie(session->getLoginCookie());
|
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;
|
delete json_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -114,6 +114,14 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params)
|
|||||||
auto user_state = session->loadUser(email, password);
|
auto user_state = session->loadUser(email, password);
|
||||||
auto user_model = session->getNewUser()->getModel();
|
auto user_model = session->getNewUser()->getModel();
|
||||||
Poco::JSON::Array infos;
|
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) {
|
switch (user_state) {
|
||||||
case USER_EMPTY:
|
case USER_EMPTY:
|
||||||
|
|||||||
@ -746,7 +746,7 @@ void Session::detectSessionState()
|
|||||||
bool cryptedPassphrase = userBackups.size() > 0;
|
bool cryptedPassphrase = userBackups.size() > 0;
|
||||||
for (auto it = userBackups.begin(); it != userBackups.end(); it++) {
|
for (auto it = userBackups.begin(); it != userBackups.end(); it++) {
|
||||||
auto passphrase = (*it)->getModel()->getPassphrase();
|
auto passphrase = (*it)->getModel()->getPassphrase();
|
||||||
Mnemonic* wordSource = nullptr;
|
const Mnemonic* wordSource = Passphrase::detectMnemonic(passphrase);
|
||||||
auto passphrase_obj = Passphrase::create(passphrase, wordSource);
|
auto passphrase_obj = Passphrase::create(passphrase, wordSource);
|
||||||
if (!passphrase_obj.isNull() && passphrase_obj->checkIfValid()) {
|
if (!passphrase_obj.isNull() && passphrase_obj->checkIfValid()) {
|
||||||
auto key_pair = KeyPairEd25519::create(passphrase_obj);
|
auto key_pair = KeyPairEd25519::create(passphrase_obj);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user