@@ -178,6 +178,35 @@ func (h *mobileHandler) patchMessage(device models.Device, c *fiber.Ctx) error {
178
178
return c .SendStatus (fiber .StatusNoContent )
179
179
}
180
180
181
+ // @Summary Change password
182
+ // @Description Changes the user's password
183
+ // @Security MobileToken
184
+ // @Tags Device
185
+ // @Accept json
186
+ // @Produce json
187
+ // @Param request body smsgateway.MobileChangePasswordRequest true "Password change request"
188
+ // @Success 204 {object} nil "Password changed successfully"
189
+ // @Failure 400 {object} smsgateway.ErrorResponse "Invalid request"
190
+ // @Failure 401 {object} smsgateway.ErrorResponse "Unauthorized"
191
+ // @Failure 500 {object} smsgateway.ErrorResponse "Internal server error"
192
+ // @Router /mobile/v1/user/password [patch]
193
+ //
194
+ // Change password
195
+ func (h * mobileHandler ) changePassword (device models.Device , c * fiber.Ctx ) error {
196
+ req := smsgateway.MobileChangePasswordRequest {}
197
+
198
+ if err := h .BodyParserValidator (c , & req ); err != nil {
199
+ return fiber .NewError (fiber .StatusBadRequest , err .Error ())
200
+ }
201
+
202
+ if err := h .authSvc .ChangePassword (device .UserID , req .CurrentPassword , req .NewPassword ); err != nil {
203
+ h .Logger .Error ("failed to change password" , zap .Error (err ))
204
+ return fiber .NewError (fiber .StatusUnauthorized , "Invalid current password" )
205
+ }
206
+
207
+ return c .SendStatus (fiber .StatusNoContent )
208
+ }
209
+
181
210
func (h * mobileHandler ) Register (router fiber.Router ) {
182
211
router = router .Group ("/mobile/v1" )
183
212
@@ -226,6 +255,8 @@ func (h *mobileHandler) Register(router fiber.Router) {
226
255
router .Get ("/message" , auth .WithDevice (h .getMessage ))
227
256
router .Patch ("/message" , auth .WithDevice (h .patchMessage ))
228
257
258
+ router .Patch ("/user/password" , auth .WithDevice (h .changePassword ))
259
+
229
260
h .webhooksCtrl .Register (router .Group ("/webhooks" ))
230
261
}
231
262
0 commit comments