Skip to content

Commit

Permalink
Fixes Password not getting updated in Traits
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryan51203 committed Jan 27, 2024
1 parent ac89340 commit 6c55932
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
61 changes: 32 additions & 29 deletions api/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ func HandleUpdateProfile(c *gin.Context) {
err := c.BindJSON(&req_body)

traitsinterface := map[string]interface{}{
"email": req_body.Traits.Email,
"name": req_body.Traits.Name,
"phone_number": req_body.Traits.PhoneNumber,
"password": req_body.Traits.Password,
"img_url": req_body.Traits.ImgURL,
"phone_number": req_body.Traits.PhoneNumber,
"invite_status": req_body.Traits.InviteStatus,
"email": req_body.Traits.Email,
"totp_enabled": req_body.Traits.TOTP_Enabled,
"created_at": req_body.Traits.Created_At,
"verified": req_body.Traits.Verified,
"role": req_body.Traits.Role,
"created_at": req_body.Traits.Created_At,
"totp_enabled": req_body.Traits.TOTP_Enabled,
}

if err != nil {
Expand Down Expand Up @@ -210,40 +212,41 @@ func HandleChangePassword(c *gin.Context) {

recovery_cookie, _ := c.Cookie("ory_kratos_session")

if recovery_cookie != "" {
session, err := middleware.GetSession(c)
if err != nil {
log.ErrorLogger("Unable to get session", err)
errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0])
c.JSON(errCode, gin.H{
"error": err.Error(),
"message": "Unable to get session",
})
return
}
identity := session.GetIdentity()
traits := identity.GetTraits()
profile := traits.(map[string]interface{})
session, err := middleware.GetSession(c)
if err != nil {
log.ErrorLogger("Unable to get session", err)
errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0])
c.JSON(errCode, gin.H{
"error": err.Error(),
"message": "Unable to get session",
})
return
}
identity := session.GetIdentity()
traits := identity.GetTraits()
profile := traits.(map[string]interface{})

profile["password"] = req_body.Password

if recovery_cookie != "" {
if profile["verified"] == false {
profile["verified"] = true
}

if profile["invite_status"] == "pending" {
profile["invite_status"] = "accepted"
}
}

_, err = settings.SubmitSettingsFlowProfileMethod(flow_cookie, session_cookie, req_body.FlowID, req_body.CsrfToken, profile)
if err != nil {
log.ErrorLogger("Kratos post settings update profile flow failed", err)
_, err = settings.SubmitSettingsFlowProfileMethod(flow_cookie, session_cookie, req_body.FlowID, req_body.CsrfToken, profile)
if err != nil {
log.ErrorLogger("Kratos post settings update profile flow failed", err)

errCode, _ := strconv.Atoi((strings.Split(err.Error(), " "))[0])
c.JSON(errCode, gin.H{
"error": err.Error(),
"message": "Kratos post settings update profile flow failed",
})
return
}
errCode, _ := strconv.Atoi((strings.Split(err.Error(), " "))[0])
c.JSON(errCode, gin.H{
"error": err.Error(),
"message": "Kratos post settings update profile flow failed",
})
return
}
c.JSON(http.StatusOK, gin.H{
"status": msg,
Expand Down
8 changes: 5 additions & 3 deletions pkg/wrapper/kratos/settings/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ type SubmitSettingsWithPasswordBody struct {
}

type Traits struct {
Email string `json:"email"`
Name string `json:"name"`
PhoneNumber string `json:"phone_number"`
Password string `json:"password"`
ImgURL string `json:"img_url,omitempty"`
Email string `json:"email"`
Role string `json:"role"`
PhoneNumber string `json:"phone_number"`
InviteStatus string `json:"invite_status"`
Verified bool `json:"verified"`
Role string `json:"role"`
Created_At string `json:"created_at"`
TOTP_Enabled bool `json:"totp_enabled"`
}

0 comments on commit 6c55932

Please sign in to comment.