add auto correct keys to apollo, copy also disabled field of user

This commit is contained in:
einhornimmond 2021-10-12 15:24:14 +02:00
parent ff75bbd558
commit 1486476571
6 changed files with 39 additions and 8 deletions

View File

@ -19,6 +19,7 @@ export class User {
this.pubkey = json.public_hex
this.language = json.language
this.publisherId = json.publisher_id
this.disabled = json.disabled
}
@Field(() => String)
@ -56,10 +57,8 @@ export class User {
@Field(() => String)
language: string
/*
@Field(() => Boolean)
disabled: boolean
*/
/* I suggest to have a group as type here
@Field(() => ID)

View File

@ -47,7 +47,21 @@ 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 = await userRepository.findByPubkeyHex(user.pubkey).catch(() => {})
if(!userEntity) {
// create user if it don't exist with this pubkey
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.disabled = user.disabled
userEntity.save().catch(() => {
throw new Error('error by save userEntity')
})
}
const userSettingRepository = getCustomRepository(UserSettingRepository)
const coinanimation = await userSettingRepository
@ -111,6 +125,7 @@ export class UserResolver {
dbuser.firstName = user.firstName
dbuser.lastName = user.lastName
dbuser.username = user.username
dbuser.disabled = user.disabled
dbuser.save().catch(() => {
throw new Error('error saving user')

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

@ -108,6 +108,14 @@ Poco::JSON::Object* JsonUnsecureLogin::handle(Poco::Dynamic::Var params)
auto user_state = session->loadUser(email, password);
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 (mSession->generateKeys(true, true)) {
user_state = session->getNewUser()->getUserState();
}
}
switch (user_state) {
case USER_EMPTY:

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);