@@ -8,7 +8,8 @@ const sessionRequest: SessionManagerMap = {
88 login2 : sessionManager ( "login2" , "/login/2" ) ,
99 logout : sessionManager ( "logout" , "/logout" ) ,
1010 forgotPassword : sessionManager ( "forgotPassword" , "/login/forgot-password" ) ,
11- resetPassword : sessionManager ( "resetPassword" , "/login/reset-password" )
11+ resetPassword : sessionManager ( "resetPassword" , "/login/reset-password" ) ,
12+ user_update_password : sessionManager ( "user_update_password" , "/login/user_update_password" ) ,
1213}
1314
1415function sessionManager < K extends keyof SessionManagerMap > ( key : K , path : SessionManagerMap [ K ] [ "path" ] ) {
@@ -29,32 +30,6 @@ function sessionManager<K extends keyof SessionManagerMap>(key: K, path: Session
2930 return t ;
3031}
3132
32- const user_update_password_body = ( z : Z2 < "JSON" > ) => z . object ( {
33- user_id : z . prismaField ( "Users" , "user_id" , "string" ) ,
34- registrationRequest : z . string ( ) . optional ( ) ,
35- registrationRecord : z . string ( ) . optional ( ) ,
36- session_id : z . string ( ) . optional ( ) ,
37- signature : z . string ( ) . optional ( ) ,
38- } ) ;
39-
40- async function user_update_password ( data : zod . infer < ART < typeof user_update_password_body > > ) : Promise < string | null | undefined > {
41- const result = await fetch ( "/admin/user_update_password" , {
42- headers : {
43- "X-Requested-With" : "TiddlyWiki" ,
44- "Content-Type" : "application/json" ,
45- } ,
46- body : JSON . stringify ( data )
47- } ) ;
48-
49- if ( result . ok ) {
50- return ( result . status === 200 ) ? await result . json ( ) : undefined ;
51- } else {
52- throw new Error ( await result . text ( ) ) ;
53- }
54-
55- }
56-
57-
5833function arrayBufferToBase64_viaBlob ( buffer : ArrayBuffer ) {
5934 return new Promise < string > ( ( resolve , reject ) => {
6035 const blob = new Blob ( [ buffer ] , { type : "application/octet-stream" } ) ;
@@ -89,7 +64,7 @@ export async function createNewPassword({ user_id, password }: { user_id: string
8964 password
9065 } ) ;
9166
92- const registrationResponse = await user_update_password ( {
67+ const registrationResponse = await sessionRequest . user_update_password ( {
9368 user_id, registrationRequest
9469 } ) ;
9570
@@ -99,7 +74,7 @@ export async function createNewPassword({ user_id, password }: { user_id: string
9974 clientRegistrationState, registrationResponse, password
10075 } ) ;
10176
102- await user_update_password ( {
77+ await sessionRequest . user_update_password ( {
10378 user_id, registrationRecord
10479 } ) ;
10580
@@ -112,7 +87,7 @@ export async function changeExistingPasswordAdmin({ user_id, newPassword }: { us
11287
11388 const { clientRegistrationState, registrationRequest } = opaque . client . startRegistration ( { password : newPassword } ) ;
11489
115- const registrationResponse = await user_update_password ( {
90+ const registrationResponse = await sessionRequest . user_update_password ( {
11691 user_id, registrationRequest
11792 } ) ;
11893
@@ -122,7 +97,7 @@ export async function changeExistingPasswordAdmin({ user_id, newPassword }: { us
12297 clientRegistrationState, registrationResponse, password : newPassword ,
12398 } ) ;
12499
125- await user_update_password ( { user_id, registrationRecord } ) ;
100+ await sessionRequest . user_update_password ( { user_id, registrationRecord } ) ;
126101
127102}
128103
@@ -139,7 +114,7 @@ export async function changeExistingPasswordWithPassword({ username, password, n
139114
140115 const signature = await generateSessionSignature ( sessionKey , session_id ) ;
141116
142- const registrationResponse = await user_update_password ( {
117+ const registrationResponse = await sessionRequest . user_update_password ( {
143118 user_id, registrationRequest, session_id, signature
144119 } ) ;
145120
@@ -149,7 +124,7 @@ export async function changeExistingPasswordWithPassword({ username, password, n
149124 clientRegistrationState, registrationResponse, password : newPassword ,
150125 } ) ;
151126
152- await user_update_password ( { user_id, registrationRecord, session_id, signature } ) ;
127+ await sessionRequest . user_update_password ( { user_id, registrationRecord, session_id, signature } ) ;
153128
154129 // this closes the login session we opened for the password change
155130 await sessionRequest . logout ( { session_id, signature, skipCookie : true } ) ;
0 commit comments