Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/user-responders.js
Show First 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | if (!username) { | ||||
} | } | ||||
} | } | ||||
const userQuery = SQL` | const userQuery = SQL` | ||||
SELECT id, hash, username | SELECT id, hash, username | ||||
FROM users | FROM users | ||||
WHERE LCASE(username) = LCASE(${username}) | WHERE LCASE(username) = LCASE(${username}) | ||||
`; | `; | ||||
promises.userQuery = dbQuery(userQuery); | promises.userQuery = dbQuery(userQuery); | ||||
promises.rustAPI = getRustAPI(); | |||||
const { | const { | ||||
userQuery: [userResult], | userQuery: [userResult], | ||||
rustAPI, | |||||
} = await promiseAll(promises); | } = await promiseAll(promises); | ||||
if (userResult.length === 0) { | if (userResult.length === 0) { | ||||
if (hasMinCodeVersion(viewer.platformDetails, 150)) { | if (hasMinCodeVersion(viewer.platformDetails, 150)) { | ||||
throw new ServerError('invalid_credentials'); | throw new ServerError('invalid_credentials'); | ||||
} else { | } else { | ||||
throw new ServerError('invalid_parameters'); | throw new ServerError('invalid_parameters'); | ||||
} | } | ||||
} | } | ||||
const userRow = userResult[0]; | const userRow = userResult[0]; | ||||
if (!userRow.hash || !bcrypt.compareSync(request.password, userRow.hash)) { | if (!userRow.hash || !bcrypt.compareSync(request.password, userRow.hash)) { | ||||
throw new ServerError('invalid_credentials'); | throw new ServerError('invalid_credentials'); | ||||
} | } | ||||
const id = userRow.id.toString(); | const id = userRow.id.toString(); | ||||
if (identityKeys && signedIdentityKeysBlob) { | if (identityKeys && signedIdentityKeysBlob) { | ||||
const constIdentityKeys = identityKeys; | |||||
handleAsyncPromise( | handleAsyncPromise( | ||||
rustAPI.loginUserPake( | (async () => { | ||||
const rustAPI = await getRustAPI(); | |||||
await rustAPI.loginUserPake( | |||||
id, | id, | ||||
identityKeys.primaryIdentityPublicKeys.ed25519, | constIdentityKeys.primaryIdentityPublicKeys.ed25519, | ||||
request.password, | request.password, | ||||
signedIdentityKeysBlob, | signedIdentityKeysBlob, | ||||
), | ); | ||||
})(), | |||||
); | ); | ||||
} | } | ||||
return await processSuccessfulLogin({ | return await processSuccessfulLogin({ | ||||
viewer, | viewer, | ||||
input, | input, | ||||
userID: id, | userID: id, | ||||
calendarQuery, | calendarQuery, | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | ): Promise<LogInResponse> { | ||||
// 9. Try to double-write SIWE account info to the Identity service | // 9. Try to double-write SIWE account info to the Identity service | ||||
const userIDCopy = userID; | const userIDCopy = userID; | ||||
if (identityKeys && signedIdentityKeysBlob) { | if (identityKeys && signedIdentityKeysBlob) { | ||||
const identityKeysCopy = identityKeys; | const identityKeysCopy = identityKeys; | ||||
handleAsyncPromise( | handleAsyncPromise( | ||||
(async () => { | (async () => { | ||||
const rustAPI = await getRustAPI(); | const rustAPI = await getRustAPI(); | ||||
rustAPI.loginUserWallet( | await rustAPI.loginUserWallet( | ||||
userIDCopy, | userIDCopy, | ||||
identityKeysCopy.primaryIdentityPublicKeys.ed25519, | identityKeysCopy.primaryIdentityPublicKeys.ed25519, | ||||
siweMessage.toMessage(), | siweMessage.toMessage(), | ||||
signature, | signature, | ||||
signedIdentityKeysBlob, | signedIdentityKeysBlob, | ||||
JSON.stringify(socialProof), | JSON.stringify(socialProof), | ||||
); | ); | ||||
})(), | })(), | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |