mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Update passwordReset resolver/spec
This commit is contained in:
parent
d39e702e70
commit
3c6932e21a
@ -12,25 +12,29 @@ export default {
|
||||
const stillValid = new Date()
|
||||
stillValid.setDate(stillValid.getDate() - 1)
|
||||
const encryptedNewPassword = await bcrypt.hashSync(newPassword, 10)
|
||||
const cypher = `
|
||||
MATCH (pr:PasswordReset {nonce: $nonce})
|
||||
MATCH (e:EmailAddress {email: $email})<-[:PRIMARY_EMAIL]-(u:User)-[:REQUESTED]->(pr)
|
||||
WHERE duration.between(pr.issuedAt, datetime()).days <= 0 AND pr.usedAt IS NULL
|
||||
SET pr.usedAt = datetime()
|
||||
SET u.encryptedPassword = $encryptedNewPassword
|
||||
RETURN pr
|
||||
`
|
||||
const session = driver.session()
|
||||
try {
|
||||
const transactionRes = await session.run(cypher, {
|
||||
stillValid,
|
||||
email,
|
||||
nonce,
|
||||
encryptedNewPassword,
|
||||
const passwordResetTxPromise = session.writeTransaction(async transaction => {
|
||||
const passwordResetTransactionResponse = await transaction.run(
|
||||
`
|
||||
MATCH (passwordReset:PasswordReset {nonce: $nonce})
|
||||
MATCH (email:EmailAddress {email: $email})<-[:PRIMARY_EMAIL]-(user:User)-[:REQUESTED]->(passwordReset)
|
||||
WHERE duration.between(passwordReset.issuedAt, datetime()).days <= 0 AND passwordReset.usedAt IS NULL
|
||||
SET passwordReset.usedAt = datetime()
|
||||
SET user.encryptedPassword = $encryptedNewPassword
|
||||
RETURN passwordReset
|
||||
`,
|
||||
{
|
||||
stillValid,
|
||||
email,
|
||||
nonce,
|
||||
encryptedNewPassword,
|
||||
},
|
||||
)
|
||||
return passwordResetTransactionResponse.records.map(record => record.get('passwordReset'))
|
||||
})
|
||||
const [reset] = transactionRes.records.map(record => record.get('pr'))
|
||||
const response = !!(reset && reset.properties.usedAt)
|
||||
return response
|
||||
const [reset] = await passwordResetTxPromise
|
||||
return !!(reset && reset.properties.usedAt)
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
|
||||
@ -14,14 +14,11 @@ let authenticatedUser
|
||||
let variables
|
||||
|
||||
const getAllPasswordResets = async () => {
|
||||
const session = driver.session()
|
||||
try {
|
||||
const transactionRes = await session.run('MATCH (r:PasswordReset) RETURN r')
|
||||
const resets = transactionRes.records.map(record => record.get('r'))
|
||||
return resets
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
const passwordResetQuery = await neode.cypher(
|
||||
'MATCH (passwordReset:PasswordReset) RETURN passwordReset',
|
||||
)
|
||||
const resets = passwordResetQuery.records.map(record => record.get('passwordReset'))
|
||||
return resets
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user