add ganti password pic / pat
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
package corporate_handlers
|
||||
|
||||
import (
|
||||
sidebaruserprofile "cpone/component/sidebar_user_profile"
|
||||
customtoastv2 "cpone/component/toastbootstrap"
|
||||
"cpone/models"
|
||||
"cpone/utils"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type AccountService interface {
|
||||
ChangePasswordPIC(token string, currPassword string, newPassword string) (models.ResponseStatus, error)
|
||||
ChangePasswordPIC(host string, token string, currPassword string, newPassword string) (models.ResponseStatus, error)
|
||||
ChangePasswordPAT(token string, currPassword string, newPassword string) (models.ResponseStatus, error)
|
||||
}
|
||||
|
||||
@@ -30,14 +35,74 @@ func (as *AccountHandler) HandleChangePassword(c echo.Context) error {
|
||||
token := userToken.Raw
|
||||
claims := userToken.Claims.(jwt.MapClaims)
|
||||
userGroup := claims["M_UserGroupDashboard"].(string)
|
||||
h := c.Request().Host
|
||||
|
||||
old_pass := c.FormValue("oldpassword")
|
||||
new_pass := c.FormValue("newpassword")
|
||||
old_pass := c.FormValue("oldpassid")
|
||||
new_pass := c.FormValue("newpassid")
|
||||
re_new_pass := c.FormValue("renewpassid")
|
||||
// logger.Info("params", zap.Any("old", old_pass), zap.Any("new", new_pass), zap.Any("re-new", re_new_pass))
|
||||
|
||||
old_validation := ""
|
||||
new_validation := ""
|
||||
renew_validation := ""
|
||||
errorPop := ""
|
||||
|
||||
if strings.TrimSpace(old_pass) == "" {
|
||||
old_validation = "Tidak boleh kosong"
|
||||
errorPop = "Tidak boleh kosong"
|
||||
}
|
||||
if strings.TrimSpace(new_pass) == "" {
|
||||
new_validation = "Tidak boleh kosong"
|
||||
errorPop = "Tidak boleh kosong"
|
||||
}
|
||||
if strings.TrimSpace(re_new_pass) == "" {
|
||||
renew_validation = "Tidak boleh kosong"
|
||||
errorPop = "Tidak boleh kosong"
|
||||
}
|
||||
if strings.TrimSpace(new_pass) != strings.TrimSpace(re_new_pass) {
|
||||
new_validation = "Password tidak sama"
|
||||
renew_validation = "Password tidak sama"
|
||||
errorPop = "Password tidak sama"
|
||||
}
|
||||
|
||||
if old_validation != "" || new_validation != "" || renew_validation != "" {
|
||||
newBody := sidebaruserprofile.RetModalGantiPassword(
|
||||
models.CustomTextFieldv2Prm{
|
||||
ID: "oldPassID",
|
||||
Name: "oldpassid",
|
||||
Type: "password",
|
||||
Placeholder: "Masukan password lama",
|
||||
Label: "Password Lama",
|
||||
ErrorMsg: old_validation,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
ID: "newPassID",
|
||||
Name: "newpassid",
|
||||
Type: "password",
|
||||
Placeholder: "Masukan password baru",
|
||||
Label: "Password Baru",
|
||||
ErrorMsg: new_validation,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
ID: "reNewPassID",
|
||||
Name: "renewpassid",
|
||||
Type: "password",
|
||||
Placeholder: "Masukan ulang password baru",
|
||||
Label: "Ulangi Password Baru",
|
||||
ErrorMsg: renew_validation,
|
||||
},
|
||||
sidebaruserprofile.JSHideModal(""),
|
||||
)
|
||||
toast := customtoastv2.CustomToastV2Show("Warning", errorPop, "warning")
|
||||
return utils.ViewMulti(c, []templ.Component{toast, newBody})
|
||||
}
|
||||
|
||||
if userGroup == "pic" {
|
||||
resp, err := as.AccountService.ChangePasswordPIC(token, old_pass, new_pass)
|
||||
resp, err := as.AccountService.ChangePasswordPIC(h, token, old_pass, new_pass)
|
||||
if err != nil {
|
||||
return err
|
||||
newBody := sidebaruserprofile.ModalGantiPassword()
|
||||
toast := customtoastv2.CustomToastV2Show("Warning", err.Error(), "warning")
|
||||
return utils.ViewMulti(c, []templ.Component{toast, newBody})
|
||||
}
|
||||
response = resp
|
||||
}
|
||||
@@ -45,13 +110,17 @@ func (as *AccountHandler) HandleChangePassword(c echo.Context) error {
|
||||
if userGroup == "patient" {
|
||||
resp, err := as.AccountService.ChangePasswordPAT(token, old_pass, new_pass)
|
||||
if err != nil {
|
||||
return err
|
||||
newBody := sidebaruserprofile.ModalGantiPassword()
|
||||
toast := customtoastv2.CustomToastV2Show("Warning", "Error ganti password pat", "warning")
|
||||
return utils.ViewMulti(c, []templ.Component{toast, newBody})
|
||||
}
|
||||
response = resp
|
||||
}
|
||||
|
||||
if response.Status == "ERR" {
|
||||
return nil
|
||||
newBody := sidebaruserprofile.ModalGantiPassword()
|
||||
toast := customtoastv2.CustomToastV2Show("Warning", response.Message, "warning")
|
||||
return utils.ViewMulti(c, []templ.Component{toast, newBody})
|
||||
}
|
||||
|
||||
expire := time.Now().Add(-7 * 24 * time.Hour)
|
||||
@@ -65,6 +134,7 @@ func (as *AccountHandler) HandleChangePassword(c echo.Context) error {
|
||||
|
||||
ret := `
|
||||
<script>
|
||||
$("#body-ganti-pass").modal('hide')
|
||||
console.log("signout")
|
||||
localStorage.removeItem("token")
|
||||
localStorage.removeItem("user")
|
||||
@@ -78,3 +148,9 @@ func (as *AccountHandler) HandleChangePassword(c echo.Context) error {
|
||||
c.Response().Header().Set("HX-Trigger", "script")
|
||||
return c.String(http.StatusOK, ret)
|
||||
}
|
||||
|
||||
func (as *AccountHandler) HandleCloseChangePassword(c echo.Context) error {
|
||||
newBody := sidebaruserprofile.ModalGantiPassword()
|
||||
|
||||
return utils.View(c, newBody)
|
||||
}
|
||||
|
||||
16
handlers/public/toast.handlers.go
Normal file
16
handlers/public/toast.handlers.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package public_handlers
|
||||
|
||||
import (
|
||||
customtoastv2 "cpone/component/toastbootstrap"
|
||||
"cpone/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func HandlerHideToast(c echo.Context) error {
|
||||
toastComponent := customtoastv2.CustomToastV2Hide()
|
||||
|
||||
si := toastComponent
|
||||
|
||||
return utils.View(c, si)
|
||||
}
|
||||
@@ -71,8 +71,8 @@ func SetupRoutesPublic(app *echo.Echo, appStore db.AppStore) {
|
||||
public.GET("landingpage", lh.ShowLandingPage)
|
||||
public.GET("home", lh.ShowLandingPage)
|
||||
public.GET("home/login", lh.HandleBtnLogin)
|
||||
// loginHdr := public_handlers.NewLoginHandler(l)
|
||||
// public.GET("login", loginHdr.HandlerShowLogin)
|
||||
|
||||
public.GET("home/hidetoast", public_handlers.HandlerHideToast)
|
||||
|
||||
loginServ := public_services.NewServicesLogin(appStore)
|
||||
loginHadlr := public_handlers.NewLoginHandler(loginServ)
|
||||
@@ -109,6 +109,12 @@ func SetupRoutesCorporate(app *echo.Echo, appStore db.AppStore) {
|
||||
lh := corporate_handlers.NewCompanyHandler(l)
|
||||
corp.GET("/company", lh.ShowCompany)
|
||||
|
||||
// ganti password
|
||||
accountService := corporate_services.NewAccountService(appStore)
|
||||
accountHandler := corporate_handlers.NewAccountHandler(accountService)
|
||||
corp.POST("/dashboard_pic/tutupgantipassword", accountHandler.HandleCloseChangePassword)
|
||||
corp.POST("/dashboard_pic/gantipassword", accountHandler.HandleChangePassword)
|
||||
|
||||
// dashboard_pic
|
||||
dashbrdPicServ := corporate_services.NewDashboardPicServices(appStore)
|
||||
dashbrdPicHandl := corporate_handlers.NewDashboardPicHandler(dashbrdPicServ)
|
||||
|
||||
Reference in New Issue
Block a user