Use request host for internal API URLs

This commit is contained in:
2026-06-19 17:04:46 +07:00
parent f8ad467b3d
commit 0b1cd60738
7 changed files with 125 additions and 94 deletions

View File

@@ -15,8 +15,8 @@ import (
)
type AccountService interface {
ChangePasswordPIC(host string, token string, currPassword string, newPassword string) (models.ResponseStatus, error)
ChangePasswordPAT(token string, currPassword string, newPassword string) (models.ResponseStatus, error)
ChangePasswordPIC(host string, token string, currPassword string, newPassword string, baseURL string) (models.ResponseStatus, error)
ChangePasswordPAT(token string, currPassword string, newPassword string, baseURL string) (models.ResponseStatus, error)
}
func NewAccountHandler(as AccountService) *AccountHandler {
@@ -97,8 +97,10 @@ func (as *AccountHandler) HandleChangePassword(c echo.Context) error {
return utils.ViewMulti(c, []templ.Component{toast, newBody})
}
baseURL := utils.RequestBaseURL(c.Request())
if userGroup == "pic" {
resp, err := as.AccountService.ChangePasswordPIC(h, token, old_pass, new_pass)
resp, err := as.AccountService.ChangePasswordPIC(h, token, old_pass, new_pass, baseURL)
if err != nil {
newBody := sidebaruserprofile.ModalGantiPassword()
toast := customtoastv2.CustomToastV2Show("Warning", err.Error(), "warning")
@@ -108,7 +110,7 @@ func (as *AccountHandler) HandleChangePassword(c echo.Context) error {
}
if userGroup == "patient" {
resp, err := as.AccountService.ChangePasswordPAT(token, old_pass, new_pass)
resp, err := as.AccountService.ChangePasswordPAT(token, old_pass, new_pass, baseURL)
if err != nil {
newBody := sidebaruserprofile.ModalGantiPassword()
toast := customtoastv2.CustomToastV2Show("Warning", "Error ganti password pat", "warning")

View File

@@ -17,11 +17,11 @@ import (
type TabDaftarPesertaServices interface {
SearchDaftarPesertaMCU(mcuID string, keyword string, page int, perPage int) ([]models.ModelMcuDaftarPeserta, int, error)
GenerataPasswordMCU(mgmMCUID string, host string) (models.GeneratePasswordResponse, error)
GenerataPasswordMCU(mgmMCUID string, baseURL string) (models.GeneratePasswordResponse, error)
GetAkunPeserta(patientID string) (models.AuthPatient, error)
GetListReportPesertaV4(orderheaderID string, staffname string) ([]models.TabViewReportMcu, error)
GetListReportPesertaV5(orderheaderID string, mcuid string, staffname string) ([]models.TabViewReportMcu, error)
ResetPasswordPeserta(token string, newPassword string, email string, authuserid string) (models.ResponseStatus, error)
ResetPasswordPeserta(token string, newPassword string, email string, authuserid string, baseURL string) (models.ResponseStatus, error)
DetailTestdanPaket(orderheaderID string) ([]models.TableTestPaket, error)
GetListAttachmentFile(orderheaderID string) ([]models.AttachmentFIle, error)
}
@@ -363,7 +363,8 @@ func (tdp *TabDaftarPesertaHandlers) HandleDialogGenPass(c echo.Context) error {
pageparam := c.FormValue("currpage" + paginat_id)
msg := "Apakah anda yakin untuk me-generate password untuk seluruh peserta"
resp, err := tdp.TabDaftarPesertaServices.GenerataPasswordMCU(id, "")
baseURL := utils.RequestBaseURL(c.Request())
resp, err := tdp.TabDaftarPesertaServices.GenerataPasswordMCU(id, baseURL)
if err != nil {
body_pass := corporate_daftarpeserta.Body_GenPass(dialog_passbody_id, msg, corporate_daftarpeserta.JSShowModal(""))
toast := customtoastv2.CustomToastV2Show("Warning", "Gagal generate password peserta", "warning")
@@ -637,7 +638,8 @@ func (tdp *TabDaftarPesertaHandlers) HandleAkun(c echo.Context) error {
return utils.ViewMulti(c, ret)
}
resp, err := tdp.TabDaftarPesertaServices.ResetPasswordPeserta(token, newPass, akunEmail, akunID)
baseURL := utils.RequestBaseURL(c.Request())
resp, err := tdp.TabDaftarPesertaServices.ResetPasswordPeserta(token, newPass, akunEmail, akunID, baseURL)
body_err := corporate_daftarpeserta.Body_Account(
dialog_akunbody_id,
models.CustomTextFieldv2Prm{

View File

@@ -16,7 +16,7 @@ import (
type LoginService interface {
CheckIsAccountCpone(email string) (string, error)
CheckAccountHasLocation(email string) (bool, error)
MultiSignInV2(username string, password string) (models.Response, error)
MultiSignInV2(username string, password string, baseURL string) (models.Response, error)
}
func NewLoginHandler(us LoginService) *LoginHandler {
@@ -44,7 +44,9 @@ func (lh *LoginHandler) HandleSignIn(c echo.Context) error {
defer logger.Sync()
logger.Info("Params", zap.Any("username", username), zap.Any("pass", password))
resp, err := lh.LoginService.MultiSignInV2(username, password)
// get the server hostname
baseURL := utils.RequestBaseURL(c.Request())
resp, err := lh.LoginService.MultiSignInV2(username, password, baseURL)
if err != nil {
defer logger.Sync()
logger.Info("Error", zap.Any("error multi signin", err))
@@ -103,12 +105,12 @@ func (lh *LoginHandler) HandleSignIn(c echo.Context) error {
htmx.on("htmx:configRequest", (e)=> {
e.detail.headers["Authorization"] = "Bearer ` + resp.Data.Token + `"
})
})
setTimeout(() => {
htmx.ajax('GET', '/login/redirect?url=` + url + `')
}, 200)
</script>
</script>
`
c.Response().Header().Set("HX-Trigger", "script")
return c.String(http.StatusOK, store)
@@ -186,7 +188,7 @@ func (lh *LoginHandler) HandleAutoLoginPage(c echo.Context) error {
}
})
}, 200)
</script>
</script>
`
c.Response().Header().Set("HX-Trigger", "script")
return c.String(http.StatusOK, redirect)
@@ -215,8 +217,10 @@ func (lh *LoginHandler) HandleSignInV2(c echo.Context) error {
return c.String(http.StatusOK, utype)
}
// get the server hostname
baseURL := utils.RequestBaseURL(c.Request())
// resp, err := lh.LoginService.MultiSignIn(username, password, "")
resp, err := lh.LoginService.MultiSignInV2(username, password)
resp, err := lh.LoginService.MultiSignInV2(username, password, baseURL)
if err != nil {
logger.Info("[ERROR]", zap.Any("error multi sigin: ", err))
@@ -268,7 +272,7 @@ func (lh *LoginHandler) HandleSignInV2(c echo.Context) error {
htmx.on("htmx:configRequest", (e)=> {
e.detail.headers["Authorization"] = "Bearer ` + resp.Data.Token + `"
})
})
setTimeout(() => {
htmx.ajax('GET', '/login/redirect?url=` + url + `')
@@ -286,8 +290,11 @@ func (lh *LoginHandler) HandleSignInV3(c echo.Context) error {
username := c.FormValue("username")
password := c.FormValue("password")
// get the server hostname
baseURL := utils.RequestBaseURL(c.Request())
// check is type cpone and exist in location
resp, err := lh.LoginService.MultiSignInV2(username, password)
resp, err := lh.LoginService.MultiSignInV2(username, password, baseURL)
if err != nil {
logger.Error("[ERROR]", zap.Any("multi signin process: ", err))
ret := public_login.ShowLogin("Login", public_login.MainLogin(false), public_login.CssLogin(), public_login.JsLogin())
@@ -337,7 +344,7 @@ func (lh *LoginHandler) HandleSignInV3(c echo.Context) error {
htmx.on("htmx:configRequest", (e)=> {
e.detail.headers["Authorization"] = "Bearer ` + resp.Data.Token + `"
})
})
setTimeout(() => {
htmx.ajax('GET', '/login/redirect?url=` + url + `')