Skip to content

Commit

Permalink
Fixes verify trait not changing after verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryan51203 committed Jan 28, 2024
1 parent 3475687 commit c2d55ca
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions api/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ func HandleGetSettingsFlow(c *gin.Context) {
break
}
}

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().(map[string]interface{})

if identity.VerifiableAddresses[0].Verified && traits["verified"] == false {
traits["verified"] = true

_, err = settings.SubmitSettingsFlowProfileMethod(flow_cookie, session_cookie, flowID, csrf_token, traits)
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
}
}

c.JSON(http.StatusOK, gin.H{
"flowID": flowID,
"csrf_token": csrf_token,
Expand Down Expand Up @@ -140,6 +170,25 @@ func HandleUpdateProfile(c *gin.Context) {
return
}

//Checking if email is changed then verified will be false
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{})

if profile["email"] != traitsinterface["email"] {
traitsinterface["verified"] = false
}

msg, err := settings.SubmitSettingsFlowProfileMethod(flow_cookie, session_cookie, req_body.FlowID, req_body.CsrfToken, traitsinterface)

if err != nil {
Expand Down

0 comments on commit c2d55ca

Please sign in to comment.