import getPool from "@cocalc/database/pool" ; import getAccountId from "@cocalc/database/pool/account/get" ; import setPassword from "@cocalc/database/pool/account/set-password" ; export default async function redeemPasswordReset ( password , passwordResetId ) { if ( password . length < 6 ) { throw Error ( "password is too short" ) ; } const pool = getPool ( ) ; const { rows } = await pool . query ( "SELECT email_address FROM password_reset WHERE expire > NOW() AND id=$1::UUID" , [ passwordResetId ] ) ; if ( rows . length == 0 ) { throw Error ( "Password reset no longer valid." ) ; } const { email_address } = rows [ 0 ] ; await pool . query ( "UPDATE password_reset SET expire=NOW() WHERE id=$1::UUID" , [ passwordResetId , ] ) ; const account_id = await getAccountId ( { email_address } ) ; await setPassword ( account_id , password ) ; return account_id ; }