init app
This commit is contained in:
37
internal/api/handler/prosody_hdl.go
Normal file
37
internal/api/handler/prosody_hdl.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.urkob.com/urko/prosody-password/internal/services/prosody"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func NewProsodyHandler(prosodyService *prosody.Prosody) ProsodyHandler {
|
||||
return ProsodyHandler{
|
||||
prosodyService: prosodyService,
|
||||
}
|
||||
}
|
||||
|
||||
type ProsodyHandler struct {
|
||||
prosodyService *prosody.Prosody
|
||||
}
|
||||
|
||||
type changePasswordReq struct {
|
||||
CurrentPassword string `json:"current_password"`
|
||||
NewPassword string `json:"new_password"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
func (handler ProsodyHandler) Post(c *fiber.Ctx) error {
|
||||
req := changePasswordReq{}
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return RenderError(c, fmt.Errorf("id is empty"), defaultErrMessage)
|
||||
}
|
||||
|
||||
if err := handler.prosodyService.ChangePassword(req.User, req.CurrentPassword, req.NewPassword); err != nil {
|
||||
return RenderError(c, fmt.Errorf("ChangePassword: %w", err), defaultErrMessage)
|
||||
}
|
||||
|
||||
return c.Render("success", fiber.Map{}, "")
|
||||
}
|
||||
Reference in New Issue
Block a user