add change password pic and pat service and handler
This commit is contained in:
80
handlers/corporate/account.handlers.go
Normal file
80
handlers/corporate/account.handlers.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package corporate_handlers
|
||||
|
||||
import (
|
||||
"cpone/models"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type AccountService interface {
|
||||
ChangePasswordPIC(token string, currPassword string, newPassword string) (models.ResponseStatus, error)
|
||||
ChangePasswordPAT(token string, currPassword string, newPassword string) (models.ResponseStatus, error)
|
||||
}
|
||||
|
||||
func NewAccountHandler(as AccountService) *AccountHandler {
|
||||
return &AccountHandler{
|
||||
AccountService: as,
|
||||
}
|
||||
}
|
||||
|
||||
type AccountHandler struct {
|
||||
AccountService AccountService
|
||||
}
|
||||
|
||||
func (as *AccountHandler) HandleChangePassword(c echo.Context) error {
|
||||
var response models.ResponseStatus
|
||||
userToken := c.Get("user").(*jwt.Token)
|
||||
token := userToken.Raw
|
||||
claims := userToken.Claims.(jwt.MapClaims)
|
||||
userGroup := claims["M_UserGroupDashboard"].(string)
|
||||
|
||||
old_pass := c.FormValue("oldpassword")
|
||||
new_pass := c.FormValue("newpassword")
|
||||
|
||||
if userGroup == "pic" {
|
||||
resp, err := as.AccountService.ChangePasswordPIC(token, old_pass, new_pass)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response = resp
|
||||
}
|
||||
|
||||
if userGroup == "patient" {
|
||||
resp, err := as.AccountService.ChangePasswordPAT(token, old_pass, new_pass)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response = resp
|
||||
}
|
||||
|
||||
if response.Status == "ERR" {
|
||||
return nil
|
||||
}
|
||||
|
||||
expire := time.Now().Add(-7 * 24 * time.Hour)
|
||||
cookie := new(http.Cookie)
|
||||
cookie.Name = "token"
|
||||
cookie.Value = ""
|
||||
cookie.Path = "/"
|
||||
cookie.Expires = expire
|
||||
cookie.HttpOnly = true
|
||||
c.SetCookie(cookie)
|
||||
|
||||
ret := `
|
||||
<script>
|
||||
console.log("signout")
|
||||
localStorage.removeItem("token")
|
||||
localStorage.removeItem("user")
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.replace("/login");
|
||||
}, 200)
|
||||
</script>
|
||||
`
|
||||
|
||||
c.Response().Header().Set("HX-Trigger", "script")
|
||||
return c.String(http.StatusOK, ret)
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func (mcud *McuDetailHandler) HandlerShowMcuDetailScreen(c echo.Context) error {
|
||||
claims := userCok.Claims.(jwt.MapClaims)
|
||||
name := claims["M_StaffName"].(string)
|
||||
position := claims["M_UserGroupDashboard"].(string)
|
||||
logger.Info("jwt", zap.Any("name", name))
|
||||
// logger.Info("jwt", zap.Any("name", name))
|
||||
|
||||
user := models.User{
|
||||
UserID: 1,
|
||||
|
||||
6
models/account.models.go
Normal file
6
models/account.models.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package models
|
||||
|
||||
type ResponseStatus struct {
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
102
services/corporate/account.services.go
Normal file
102
services/corporate/account.services.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package corporate_services
|
||||
|
||||
import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type AccountService struct {
|
||||
AccountStore db.AppStore
|
||||
}
|
||||
|
||||
func NewAccountService(aStore db.AppStore) *AccountService {
|
||||
return &AccountService{
|
||||
AccountStore: aStore,
|
||||
}
|
||||
}
|
||||
|
||||
func (as *AccountService) ChangePasswordPIC(token string, currPassword string, newPassword string) (models.ResponseStatus, error) {
|
||||
var ret models.ResponseStatus
|
||||
|
||||
uri := "/one-api/mockup/system/menu/change_password_pic"
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("new", newPassword)
|
||||
params.Add("old", currPassword)
|
||||
params.Add("token", token)
|
||||
|
||||
req, err := http.PostForm(uri, params)
|
||||
if err != nil {
|
||||
ret = models.ResponseStatus{
|
||||
Status: "ERR",
|
||||
Message: "error request change password",
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
defer req.Body.Close()
|
||||
|
||||
resp, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
ret = models.ResponseStatus{
|
||||
Status: "ERR",
|
||||
Message: "error read response",
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(resp, &ret)
|
||||
if err != nil {
|
||||
ret = models.ResponseStatus{
|
||||
Status: "ERR",
|
||||
Message: "error unmarshal response",
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (as *AccountService) ChangePasswordPAT(token string, currPassword string, newPassword string) (models.ResponseStatus, error) {
|
||||
var ret models.ResponseStatus
|
||||
|
||||
uri := "/one-api/mockup/system/menu/change_password_pat"
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("new", newPassword)
|
||||
params.Add("old", currPassword)
|
||||
params.Add("token", token)
|
||||
|
||||
req, err := http.PostForm(uri, params)
|
||||
if err != nil {
|
||||
ret = models.ResponseStatus{
|
||||
Status: "ERR",
|
||||
Message: "error request change password",
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
defer req.Body.Close()
|
||||
|
||||
resp, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
ret = models.ResponseStatus{
|
||||
Status: "ERR",
|
||||
Message: "error read response",
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(resp, &ret)
|
||||
if err != nil {
|
||||
ret = models.ResponseStatus{
|
||||
Status: "ERR",
|
||||
Message: "error unmarshal response",
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
@@ -196,14 +196,15 @@ func (tkf *TabKelainanFisikServices) GetKelainanFisikPresentase(mcuID string) (m
|
||||
count(distinct T_OrderHeaderID) as total
|
||||
FROM t_kelainan_fisik
|
||||
JOIN t_orderheader ON T_KelainanFiskT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN mcu_summaryfisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID
|
||||
JOIN mcu_summaryfisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
|
||||
Mcu_SummaryFisikID NOT IN (63,67,68,69,70,71,72,73)
|
||||
join mcu_kelainan on Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID
|
||||
join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
|
||||
where T_KelainanFiskIsActive = 'Y' and T_OrderHeaderMgm_McuID = ? AND
|
||||
Mcu_KelainanClasification NOT IN ('who','kemenkes','JNC-VIII','ESC/ESH')
|
||||
group by Mcu_KelainanID
|
||||
ORDER BY total DESC
|
||||
LIMIt 10
|
||||
LIMIT 10
|
||||
`
|
||||
if err := dbx.Handlex.Select(&data, q, mcuID); err != nil {
|
||||
return option, fmt.Errorf("error get data kelainan fisik: %v", err)
|
||||
|
||||
@@ -262,10 +262,12 @@ func (tkg *TabKelainanGlobalServices) GetKelainanGlobalV2(mcuID string) (models.
|
||||
count(distinct T_OrderHeaderID) as Total
|
||||
FROM t_kelainan_fisik
|
||||
JOIN t_orderheader ON T_KelainanFiskT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN mcu_summaryfisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID
|
||||
JOIN mcu_summaryfisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
|
||||
Mcu_SummaryFisikID NOT IN (63,67,68,69,70,71,72,73)
|
||||
join mcu_kelainan on Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID
|
||||
join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
|
||||
where T_KelainanFiskIsActive = 'Y' and T_OrderHeaderMgm_McuID = ?
|
||||
where T_KelainanFiskIsActive = 'Y' and T_OrderHeaderMgm_McuID = ? AND
|
||||
Mcu_KelainanClasification NOT IN ('who','kemenkes','JNC-VIII','ESC/ESH')
|
||||
group by Mcu_KelainanID
|
||||
) a
|
||||
|
||||
|
||||
@@ -289,11 +289,13 @@ func (tks *TabKesimpulanServices) GetListKesimpulanFisikV2(id string) ([]models.
|
||||
count(distinct T_OrderHeaderID) as total
|
||||
FROM t_kelainan_fisik
|
||||
JOIN t_orderheader ON T_KelainanFiskT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN mcu_summaryfisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID
|
||||
JOIN mcu_summaryfisik ON T_KelainanFiskMcu_SummaryFisikID = Mcu_SummaryFisikID AND
|
||||
Mcu_SummaryFisikID NOT IN (63,67,68,69,70,71,72,73)
|
||||
join mcu_kelainan on Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID
|
||||
join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
|
||||
where T_KelainanFiskIsActive = 'Y' and T_OrderHeaderMgm_McuID = ?
|
||||
group by Mcu_KelainanID
|
||||
where T_KelainanFiskIsActive = 'Y' and T_OrderHeaderMgm_McuID = ? AND
|
||||
Mcu_KelainanClasification NOT IN ('who','kemenkes','JNC-VIII','ESC/ESH')
|
||||
group by Mcu_KelainanID
|
||||
ORDER BY total DESC
|
||||
LIMIT 3
|
||||
`
|
||||
|
||||
@@ -62,8 +62,8 @@ templ TabViewMcuDetail(
|
||||
<div id="tabdaftarpeserta"></div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="kt_tab_pane_8" role="tabpanel" aria-labelledby="kt_tab_pane_8" style="height: 800px;">
|
||||
// <object data={"https://cpone.aplikasi.web.id/birt/run?__report=report/one/mcu/rpt_summary_executive.rptdesign&__format=pdf&PID="+id+"&username=adhi&tm=1717726294764"} type="application/pdf" width="100%" height="100%"></object>
|
||||
<object data={"/birt/run?__report=report/one/mcu/rpt_summary_executive.rptdesign&__format=pdf&PID="+id+"&username=adhi&tm=1717726294764"} type="application/pdf" width="100%" height="100%"></object>
|
||||
// <object data={"/birt/run?__report=report/one/mcu/rpt_summary_executive.rptdesign&__format=pdf&PID="+id+"&username=adhi&tm=1717726294764"} type="application/pdf" width="100%" height="100%"></object>
|
||||
<object data={"/birt/run?__report=report/one/mcu/rpt_executive_summary_mcu_001.rptdesign&__format=pdf&PID="+id+"&username=admin&tm=1722914077866"} type="application/pdf" width="100%" height="100%"></object>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="kt_tab_pane_9" role="tabpanel" aria-labelledby="kt_tab_pane_9">
|
||||
<div id="tabkeuangan"></div>
|
||||
|
||||
@@ -134,9 +134,9 @@ func TabViewMcuDetail(
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var10 string
|
||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs("/birt/run?__report=report/one/mcu/rpt_summary_executive.rptdesign&__format=pdf&PID=" + id + "&username=adhi&tm=1717726294764")
|
||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs("/birt/run?__report=report/one/mcu/rpt_executive_summary_mcu_001.rptdesign&__format=pdf&PID=" + id + "&username=admin&tm=1722914077866")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\corporate\mcu\mcutabview.templ`, Line: 66, Col: 139}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\corporate\mcu\mcutabview.templ`, Line: 66, Col: 148}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
Reference in New Issue
Block a user