X-Git-Url: http://git.squeep.com/?p=squeep-indie-auther;a=blobdiff_plain;f=src%2Fdb%2Fsqlite%2Findex.js;fp=src%2Fdb%2Fsqlite%2Findex.js;h=a618b9abde14fdfff4adfdf7a49bb652baedddc8;hp=97027be662733e4cac566a7eccb284bd9256aad0;hb=fba42a499fe1af051b0982c1f3e8b3873c9ed2fb;hpb=e8dccf76ec2776f07eddd1ce2f1c4fc150a6f790 diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js index 97027be..a618b9a 100644 --- a/src/db/sqlite/index.js +++ b/src/db/sqlite/index.js @@ -21,7 +21,7 @@ const schemaVersionsSupported = { }, max: { major: 1, - minor: 1, + minor: 2, patch: 0, }, }; @@ -342,17 +342,34 @@ class DatabaseSQLite extends Database { } - authenticationUpsert(dbCtx, identifier, credential) { + authenticationUpsert(dbCtx, identifier, credential, otpKey) { const _scope = _fileScope('authenticationUpsert'); const scrubbedCredential = '*'.repeat((credential || '').length); - this.logger.debug(_scope, 'called', { identifier, scrubbedCredential }); + const scrubbedOTPKey = '*'.repeat((otpKey || '').length); + this.logger.debug(_scope, 'called', { identifier, scrubbedCredential, scrubbedOTPKey }); - let result; try { - result = this.statement.authenticationUpsert.run({ identifier, credential }); + const result = this.statement.authenticationUpsert.run({ identifier, credential, otpKey }); if (result.changes != 1) { throw new DBErrors.UnexpectedResult('did not upsert authentication'); } + } catch (e) { + this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential, scrubbedOTPKey }); + throw e; + } + } + + + authenticationUpdateCredential(dbCtx, identifier, credential) { + const _scope = _fileScope('authenticationUpdateCredential'); + const scrubbedCredential = '*'.repeat((credential || '').length); + this.logger.debug(_scope, 'called', { identifier, scrubbedCredential }); + + try { + const result = this.statement.authenticationUpdateCredential.run({ identifier, credential }); + if (result.changes != 1) { + throw new DBErrors.UnexpectedResult('did not update credential'); + } } catch (e) { this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential }); throw e; @@ -360,6 +377,23 @@ class DatabaseSQLite extends Database { } + authenticationUpdateOTPKey(dbCtx, identifier, otpKey) { + const _scope = _fileScope('authenticationUpdateOTPKey'); + const scrubbedOTPKey = '*'.repeat((otpKey || '').length); + this.logger.debug(_scope, 'called', { identifier, scrubbedOTPKey }); + + try { + const result = this.statement.authenticationUpdateOtpKey.run({ identifier, otpKey }); + if (result.changes != 1) { + throw new DBErrors.UnexpectedResult('did not update otpKey'); + } + } catch (e) { + this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedOTPKey }); + throw e; + } + } + + profileIdentifierInsert(dbCtx, profile, identifier) { const _scope = _fileScope('profileIdentifierInsert'); this.logger.debug(_scope, 'called', { profile, identifier });