-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
email rate limits followup
- Loading branch information
Showing
4 changed files
with
72 additions
and
20 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
packages/pds/src/api/com/atproto/server/requestAccountDelete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/pds/src/api/com/atproto/server/requestEmailConfirmation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/pds/src/api/com/atproto/server/requestEmailUpdate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 33 additions & 20 deletions
53
packages/pds/src/api/com/atproto/server/requestPasswordReset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
import { DAY, HOUR } from '@atproto/common' | ||
import { InvalidRequestError } from '@atproto/xrpc-server' | ||
import AppContext from '../../../../context' | ||
import { Server } from '../../../../lexicon' | ||
import { authPassthru } from '../../../proxy' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.com.atproto.server.requestPasswordReset(async ({ input, req }) => { | ||
const email = input.body.email.toLowerCase() | ||
server.com.atproto.server.requestPasswordReset({ | ||
rateLimit: [ | ||
{ | ||
durationMs: DAY, | ||
points: 50, | ||
}, | ||
{ | ||
durationMs: HOUR, | ||
points: 15, | ||
}, | ||
], | ||
handler: async ({ input, req }) => { | ||
const email = input.body.email.toLowerCase() | ||
|
||
const account = await ctx.accountManager.getAccountByEmail(email) | ||
const account = await ctx.accountManager.getAccountByEmail(email) | ||
|
||
if (!account?.email) { | ||
if (ctx.entrywayAgent) { | ||
await ctx.entrywayAgent.com.atproto.server.requestPasswordReset( | ||
input.body, | ||
authPassthru(req, true), | ||
) | ||
return | ||
if (!account?.email) { | ||
if (ctx.entrywayAgent) { | ||
await ctx.entrywayAgent.com.atproto.server.requestPasswordReset( | ||
input.body, | ||
authPassthru(req, true), | ||
) | ||
return | ||
} | ||
throw new InvalidRequestError('account does not have an email address') | ||
} | ||
throw new InvalidRequestError('account does not have an email address') | ||
} | ||
|
||
const token = await ctx.accountManager.createEmailToken( | ||
account.did, | ||
'reset_password', | ||
) | ||
await ctx.mailer.sendResetPassword( | ||
{ identifier: account.handle ?? account.email, token }, | ||
{ to: account.email }, | ||
) | ||
const token = await ctx.accountManager.createEmailToken( | ||
account.did, | ||
'reset_password', | ||
) | ||
await ctx.mailer.sendResetPassword( | ||
{ identifier: account.handle ?? account.email, token }, | ||
{ to: account.email }, | ||
) | ||
}, | ||
}) | ||
} |