user saving on db

This commit is contained in:
joseji 2022-11-24 11:21:47 +01:00
parent 60e3f62832
commit 2a74b92472
3 changed files with 13 additions and 9 deletions

View File

@ -1193,9 +1193,11 @@ describe('UserResolver', () => {
let bibi: User
beforeAll(async () => {
const users = await User.find()
bibi = users[1]
const usercontact = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
bibi = usercontact.user
bibi.passwordEncryptionType = PasswordEncryptionType.EMAIL
bibi.password = SecretKeyCryptographyCreateKey(
'bibi@bloxberg.de',
@ -1208,11 +1210,15 @@ describe('UserResolver', () => {
it('changes to gradidoID on login', async () => {
await mutate({ mutation: login, variables: variables })
const users = await User.find()
bibi = users[0]
const usercontact = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
bibi = usercontact.user
expect(bibi).toEqual(
expect.objectContaining({
firstName: 'Bibi',
password: SecretKeyCryptographyCreateKey(bibi.gradidoID.toString(), 'Aa12345_')[0]
.readBigUInt64LE()
.toString(),

View File

@ -311,6 +311,7 @@ export class UserResolver {
if (dbUser.passwordEncryptionType !== PasswordEncryptionType.GRADIDO_ID) {
dbUser.passwordEncryptionType = PasswordEncryptionType.GRADIDO_ID
dbUser.password = encryptPassword(dbUser, password)
await dbUser.save()
}
// add pubKey in logger-context for layout-pattern X{user} to print it in each logging message
logger.addContext('user', dbUser.id)

View File

@ -10,8 +10,5 @@ export const encryptPassword = (dbUser: User, password: string): bigint => {
}
export const verifyPassword = (dbUser: User, password: string): boolean => {
if (dbUser.password.toString() !== encryptPassword(dbUser, password).toString()) {
return false
}
return true
return dbUser.password.toString() === encryptPassword(dbUser, password).toString()
}