@@ -8,6 +8,8 @@ import { openApp, recordToSearchStr } from "../../util/appUtils";
88import { trans } from "i18n" ;
99import { logoutAction } from "redux/reduxActions/userActions" ;
1010import StoreRegistry from "@lowcoder-ee/redux/store/storeRegistry" ;
11+ import UserApi from "@lowcoder-ee/api/userApi" ;
12+ import { messageInstance } from "components/GlobalInstances" ;
1113
1214const UtilsCompBase = simpleMultiComp ( { } ) ;
1315export let UtilsComp = withExposingConfigs ( UtilsCompBase , [ ] ) ;
@@ -121,4 +123,33 @@ UtilsComp = withMethodExposing(UtilsComp, [
121123 ) ;
122124 } ,
123125 } ,
126+ {
127+ method : {
128+ name : "resetPassword" ,
129+ description : trans ( "utilsComp.resetPassword" ) ,
130+ params : [
131+ { name : "oldPassword" , type : "string" } ,
132+ { name : "newPassword" , type : "string" } ,
133+ ] ,
134+ } ,
135+ execute : async ( comp , params ) => {
136+ const oldPassword = params ?. [ 0 ] ;
137+ const newPassword = params ?. [ 1 ] ;
138+ try {
139+ if ( Boolean ( oldPassword ) && Boolean ( newPassword ) ) {
140+ const response = await UserApi . updatePassword ( {
141+ oldPassword : oldPassword as string ,
142+ newPassword : newPassword as string ,
143+ } ) ;
144+ if ( ! response . data . success ) {
145+ throw ( new Error ( response . data . message ) ) ;
146+ }
147+ } else {
148+ throw ( new Error ( 'Reset password requires both old and new passwords' ) )
149+ }
150+ } catch ( e : any ) {
151+ messageInstance . error ( e . message )
152+ }
153+ } ,
154+ }
124155] ) ;
0 commit comments