feat: fix get clients ip
This commit is contained in:
parent
cd42a6b0bf
commit
91585fdb0a
|
@ -2,6 +2,7 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"gitea.urkob.com/urko/prosody-password/internal/services/fail2ban"
|
"gitea.urkob.com/urko/prosody-password/internal/services/fail2ban"
|
||||||
"gitea.urkob.com/urko/prosody-password/internal/services/prosody"
|
"gitea.urkob.com/urko/prosody-password/internal/services/prosody"
|
||||||
|
@ -31,12 +32,13 @@ func (handler ProsodyHandler) Post(c *fiber.Ctx) error {
|
||||||
if err := c.BodyParser(&req); err != nil {
|
if err := c.BodyParser(&req); err != nil {
|
||||||
return RenderError(c, fmt.Errorf(" c.BodyParser(&req): %w", err), defaultErrMessage)
|
return RenderError(c, fmt.Errorf(" c.BodyParser(&req): %w", err), defaultErrMessage)
|
||||||
}
|
}
|
||||||
|
log.Println("request ip", c.IP())
|
||||||
req.CurrentPassword = c.FormValue("current_password")
|
req.CurrentPassword = c.FormValue("current_password")
|
||||||
req.NewPassword = c.FormValue("new_password")
|
req.NewPassword = c.FormValue("new_password")
|
||||||
if err := handler.prosodyService.ChangePassword(req.User, req.CurrentPassword, req.NewPassword); err != nil {
|
if err := handler.prosodyService.ChangePassword(req.User, req.CurrentPassword, req.NewPassword); err != nil {
|
||||||
// for _, ip := range c.IPs() {
|
for _, ip := range c.IPs() {
|
||||||
// handler.fail2banSrv.FailedAttempt(ip)
|
handler.fail2banSrv.FailedAttempt(ip)
|
||||||
// }
|
}
|
||||||
return RenderError(c, fmt.Errorf("ChangePassword: %w", err), defaultErrMessage)
|
return RenderError(c, fmt.Errorf("ChangePassword: %w", err), defaultErrMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,9 @@ func NewRestServer(
|
||||||
func (s *RestServer) Start(apiPort, views string) error {
|
func (s *RestServer) Start(apiPort, views string) error {
|
||||||
engine := handlebars.New(views, ".hbs")
|
engine := handlebars.New(views, ".hbs")
|
||||||
s.app = fiber.New(fiber.Config{
|
s.app = fiber.New(fiber.Config{
|
||||||
Views: engine,
|
Views: engine,
|
||||||
|
ProxyHeader: "X-Forwarded-For",
|
||||||
|
EnableIPValidation: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
s.app.Use(limiter.New(limiter.Config{
|
s.app.Use(limiter.New(limiter.Config{
|
||||||
|
@ -47,7 +49,6 @@ func (s *RestServer) Start(apiPort, views string) error {
|
||||||
AllowHeaders: "Origin, Accept, Content-Type, X-CSRF-Token, Authorization",
|
AllowHeaders: "Origin, Accept, Content-Type, X-CSRF-Token, Authorization",
|
||||||
ExposeHeaders: "Origin",
|
ExposeHeaders: "Origin",
|
||||||
}))
|
}))
|
||||||
|
|
||||||
s.loadViews()
|
s.loadViews()
|
||||||
|
|
||||||
prosodyHdl := handler.NewProsodyHandler(s.prosodyService, s.fail2banSrv)
|
prosodyHdl := handler.NewProsodyHandler(s.prosodyService, s.fail2banSrv)
|
||||||
|
|
Loading…
Reference in New Issue