Skip to content

Commit

Permalink
Admin: updateAccountPassword (#2212)
Browse files Browse the repository at this point in the history
* add update account password route

* add test
  • Loading branch information
dholms authored Feb 22, 2024
1 parent 6d30e2c commit 87d59ff
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lexicons/com/atproto/admin/updateAccountPassword.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"lexicon": 1,
"id": "com.atproto.admin.updateAccountPassword",
"defs": {
"main": {
"type": "procedure",
"description": "Update the password for a user account as an administrator.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["did", "password"],
"properties": {
"did": { "type": "string", "format": "did" },
"password": { "type": "string" }
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRep
import * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
import * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
import * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
import * as ComAtprotoAdminUpdateAccountPassword from './types/com/atproto/admin/updateAccountPassword'
import * as ComAtprotoAdminUpdateCommunicationTemplate from './types/com/atproto/admin/updateCommunicationTemplate'
import * as ComAtprotoAdminUpdateSubjectStatus from './types/com/atproto/admin/updateSubjectStatus'
import * as ComAtprotoIdentityGetRecommendedDidCredentials from './types/com/atproto/identity/getRecommendedDidCredentials'
Expand Down Expand Up @@ -182,6 +183,7 @@ export * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRep
export * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
export * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
export * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
export * as ComAtprotoAdminUpdateAccountPassword from './types/com/atproto/admin/updateAccountPassword'
export * as ComAtprotoAdminUpdateCommunicationTemplate from './types/com/atproto/admin/updateCommunicationTemplate'
export * as ComAtprotoAdminUpdateSubjectStatus from './types/com/atproto/admin/updateSubjectStatus'
export * as ComAtprotoIdentityGetRecommendedDidCredentials from './types/com/atproto/identity/getRecommendedDidCredentials'
Expand Down Expand Up @@ -654,6 +656,17 @@ export class ComAtprotoAdminNS {
})
}

updateAccountPassword(
data?: ComAtprotoAdminUpdateAccountPassword.InputSchema,
opts?: ComAtprotoAdminUpdateAccountPassword.CallOptions,
): Promise<ComAtprotoAdminUpdateAccountPassword.Response> {
return this._service.xrpc
.call('com.atproto.admin.updateAccountPassword', opts?.qp, data, opts)
.catch((e) => {
throw ComAtprotoAdminUpdateAccountPassword.toKnownErr(e)
})
}

updateCommunicationTemplate(
data?: ComAtprotoAdminUpdateCommunicationTemplate.InputSchema,
opts?: ComAtprotoAdminUpdateCommunicationTemplate.CallOptions,
Expand Down
29 changes: 29 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,33 @@ export const schemaDict = {
},
},
},
ComAtprotoAdminUpdateAccountPassword: {
lexicon: 1,
id: 'com.atproto.admin.updateAccountPassword',
defs: {
main: {
type: 'procedure',
description:
'Update the password for a user account as an administrator.',
input: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['did', 'password'],
properties: {
did: {
type: 'string',
format: 'did',
},
password: {
type: 'string',
},
},
},
},
},
},
},
ComAtprotoAdminUpdateCommunicationTemplate: {
lexicon: 1,
id: 'com.atproto.admin.updateCommunicationTemplate',
Expand Down Expand Up @@ -8860,6 +8887,8 @@ export const ids = {
ComAtprotoAdminSendEmail: 'com.atproto.admin.sendEmail',
ComAtprotoAdminUpdateAccountEmail: 'com.atproto.admin.updateAccountEmail',
ComAtprotoAdminUpdateAccountHandle: 'com.atproto.admin.updateAccountHandle',
ComAtprotoAdminUpdateAccountPassword:
'com.atproto.admin.updateAccountPassword',
ComAtprotoAdminUpdateCommunicationTemplate:
'com.atproto.admin.updateCommunicationTemplate',
ComAtprotoAdminUpdateSubjectStatus: 'com.atproto.admin.updateSubjectStatus',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { Headers, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'

export interface QueryParams {}

export interface InputSchema {
did: string
password: string
[k: string]: unknown
}

export interface CallOptions {
headers?: Headers
qp?: QueryParams
encoding: 'application/json'
}

export interface Response {
success: boolean
headers: Headers
}

export function toKnownErr(e: any) {
if (e instanceof XRPCError) {
}
return e
}
12 changes: 12 additions & 0 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRep
import * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
import * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
import * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
import * as ComAtprotoAdminUpdateAccountPassword from './types/com/atproto/admin/updateAccountPassword'
import * as ComAtprotoAdminUpdateCommunicationTemplate from './types/com/atproto/admin/updateCommunicationTemplate'
import * as ComAtprotoAdminUpdateSubjectStatus from './types/com/atproto/admin/updateSubjectStatus'
import * as ComAtprotoIdentityGetRecommendedDidCredentials from './types/com/atproto/identity/getRecommendedDidCredentials'
Expand Down Expand Up @@ -444,6 +445,17 @@ export class ComAtprotoAdminNS {
return this._server.xrpc.method(nsid, cfg)
}

updateAccountPassword<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoAdminUpdateAccountPassword.Handler<ExtractAuth<AV>>,
ComAtprotoAdminUpdateAccountPassword.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.admin.updateAccountPassword' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

updateCommunicationTemplate<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
29 changes: 29 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,33 @@ export const schemaDict = {
},
},
},
ComAtprotoAdminUpdateAccountPassword: {
lexicon: 1,
id: 'com.atproto.admin.updateAccountPassword',
defs: {
main: {
type: 'procedure',
description:
'Update the password for a user account as an administrator.',
input: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['did', 'password'],
properties: {
did: {
type: 'string',
format: 'did',
},
password: {
type: 'string',
},
},
},
},
},
},
},
ComAtprotoAdminUpdateCommunicationTemplate: {
lexicon: 1,
id: 'com.atproto.admin.updateCommunicationTemplate',
Expand Down Expand Up @@ -8860,6 +8887,8 @@ export const ids = {
ComAtprotoAdminSendEmail: 'com.atproto.admin.sendEmail',
ComAtprotoAdminUpdateAccountEmail: 'com.atproto.admin.updateAccountEmail',
ComAtprotoAdminUpdateAccountHandle: 'com.atproto.admin.updateAccountHandle',
ComAtprotoAdminUpdateAccountPassword:
'com.atproto.admin.updateAccountPassword',
ComAtprotoAdminUpdateCommunicationTemplate:
'com.atproto.admin.updateCommunicationTemplate',
ComAtprotoAdminUpdateSubjectStatus: 'com.atproto.admin.updateSubjectStatus',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import express from 'express'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'
import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'

export interface QueryParams {}

export interface InputSchema {
did: string
password: string
[k: string]: unknown
}

export interface HandlerInput {
encoding: 'application/json'
body: InputSchema
}

export interface HandlerError {
status: number
message?: string
}

export type HandlerOutput = HandlerError | void
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA
params: QueryParams
input: HandlerInput
req: express.Request
res: express.Response
}
export type Handler<HA extends HandlerAuth = never> = (
ctx: HandlerReqCtx<HA>,
) => Promise<HandlerOutput> | HandlerOutput
12 changes: 12 additions & 0 deletions packages/ozone/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRep
import * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
import * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
import * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
import * as ComAtprotoAdminUpdateAccountPassword from './types/com/atproto/admin/updateAccountPassword'
import * as ComAtprotoAdminUpdateCommunicationTemplate from './types/com/atproto/admin/updateCommunicationTemplate'
import * as ComAtprotoAdminUpdateSubjectStatus from './types/com/atproto/admin/updateSubjectStatus'
import * as ComAtprotoIdentityGetRecommendedDidCredentials from './types/com/atproto/identity/getRecommendedDidCredentials'
Expand Down Expand Up @@ -444,6 +445,17 @@ export class ComAtprotoAdminNS {
return this._server.xrpc.method(nsid, cfg)
}

updateAccountPassword<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoAdminUpdateAccountPassword.Handler<ExtractAuth<AV>>,
ComAtprotoAdminUpdateAccountPassword.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.admin.updateAccountPassword' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

updateCommunicationTemplate<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
29 changes: 29 additions & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,33 @@ export const schemaDict = {
},
},
},
ComAtprotoAdminUpdateAccountPassword: {
lexicon: 1,
id: 'com.atproto.admin.updateAccountPassword',
defs: {
main: {
type: 'procedure',
description:
'Update the password for a user account as an administrator.',
input: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['did', 'password'],
properties: {
did: {
type: 'string',
format: 'did',
},
password: {
type: 'string',
},
},
},
},
},
},
},
ComAtprotoAdminUpdateCommunicationTemplate: {
lexicon: 1,
id: 'com.atproto.admin.updateCommunicationTemplate',
Expand Down Expand Up @@ -8860,6 +8887,8 @@ export const ids = {
ComAtprotoAdminSendEmail: 'com.atproto.admin.sendEmail',
ComAtprotoAdminUpdateAccountEmail: 'com.atproto.admin.updateAccountEmail',
ComAtprotoAdminUpdateAccountHandle: 'com.atproto.admin.updateAccountHandle',
ComAtprotoAdminUpdateAccountPassword:
'com.atproto.admin.updateAccountPassword',
ComAtprotoAdminUpdateCommunicationTemplate:
'com.atproto.admin.updateCommunicationTemplate',
ComAtprotoAdminUpdateSubjectStatus: 'com.atproto.admin.updateSubjectStatus',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import express from 'express'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'
import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'

export interface QueryParams {}

export interface InputSchema {
did: string
password: string
[k: string]: unknown
}

export interface HandlerInput {
encoding: 'application/json'
body: InputSchema
}

export interface HandlerError {
status: number
message?: string
}

export type HandlerOutput = HandlerError | void
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA
params: QueryParams
input: HandlerInput
req: express.Request
res: express.Response
}
export type Handler<HA extends HandlerAuth = never> = (
ctx: HandlerReqCtx<HA>,
) => Promise<HandlerOutput> | HandlerOutput
5 changes: 5 additions & 0 deletions packages/pds/src/account-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ export class AccountManager {
'reset_password',
opts.token,
)
await this.updateAccountPassword({ did, password: opts.password })
}

async updateAccountPassword(opts: { did: string; password: string }) {
const { did } = opts
const passwordScrypt = await scrypt.genSaltAndHash(opts.password)
await this.db.transaction(async (dbTxn) =>
Promise.all([
Expand Down
2 changes: 2 additions & 0 deletions packages/pds/src/api/com/atproto/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import disableInviteCodes from './disableInviteCodes'
import getInviteCodes from './getInviteCodes'
import updateAccountHandle from './updateAccountHandle'
import updateAccountEmail from './updateAccountEmail'
import updateAccountPassword from './updateAccountPassword'
import sendEmail from './sendEmail'
import deleteAccount from './deleteAccount'
import queryModerationStatuses from './queryModerationStatuses'
Expand All @@ -40,6 +41,7 @@ export default function (server: Server, ctx: AppContext) {
getInviteCodes(server, ctx)
updateAccountHandle(server, ctx)
updateAccountEmail(server, ctx)
updateAccountPassword(server, ctx)
sendEmail(server, ctx)
deleteAccount(server, ctx)
listCommunicationTemplates(server, ctx)
Expand Down
Loading

0 comments on commit 87d59ff

Please sign in to comment.