Created
January 18, 2022 14:32
-
-
Save fulviodenza/7df2efb38f2464d0838c391e3b9a8b94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (a *App) ForgotPassword(c echo.Context) (err error) { | |
u := new(UserForgot) | |
if err = c.Bind(u); err != nil { | |
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) | |
} | |
if err = c.Validate(u); err != nil { | |
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) | |
} | |
secretHash := computeSecretHash(a.AppClientSecret, u.Username, a.AppClientID) | |
cognitoUser := &cognito.ForgotPasswordInput{ | |
SecretHash: aws.String(secretHash), | |
ClientId: aws.String(a.AppClientID), | |
Username: &u.Username, | |
} | |
cognitoUser.Validate() | |
forgotPasswordOutput, err := a.CognitoClient.ForgotPassword(cognitoUser) | |
if err != nil { | |
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) | |
} | |
return echo.NewHTTPError(http.StatusOK, forgotPasswordOutput) | |
} | |
func (a *App) ConfirmForgotPassword(c echo.Context, v validator.Validate) (err error) { | |
u := new(UserConfirmationCode) | |
if err = c.Bind(u); err != nil { | |
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) | |
} | |
if err = c.Validate(u); err != nil { | |
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) | |
} | |
if err = v.Struct(u.User); err != nil { | |
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) | |
} | |
secretHash := computeSecretHash(a.AppClientSecret, u.User.Username, a.AppClientID) | |
cognitoUser := &cognito.ConfirmForgotPasswordInput{ | |
SecretHash: aws.String(secretHash), | |
ClientId: aws.String(a.AppClientID), | |
Username: &u.User.Username, | |
ConfirmationCode: &u.ConfirmationCode, | |
Password: &u.User.Password, | |
} | |
resp, err := a.CognitoClient.ConfirmForgotPassword(cognitoUser) | |
if err != nil { | |
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) | |
} | |
return echo.NewHTTPError(http.StatusOK, resp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment