-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #303 Forgot password for consent bb individuals and not for indiv…
…iduals onboarded from idp
- Loading branch information
1 parent
c8f27e2
commit 91667d7
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package onboard | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/asaskevich/govalidator" | ||
"github.com/bb-consent/api/src/common" | ||
"github.com/bb-consent/api/src/config" | ||
"github.com/bb-consent/api/src/user" | ||
"github.com/bb-consent/api/src/v2/iam" | ||
) | ||
|
||
type forgotPassword struct { | ||
Username string `json:"username" valid:"required,email"` | ||
} | ||
|
||
// OnboardForgotPassword User forgot the password, need to reset the password | ||
func OnboardForgotPassword(w http.ResponseWriter, r *http.Request) { | ||
var fp forgotPassword | ||
|
||
b, _ := ioutil.ReadAll(r.Body) | ||
json.Unmarshal(b, &fp) | ||
|
||
// validating request params | ||
valid, err := govalidator.ValidateStruct(fp) | ||
if !valid { | ||
log.Printf("Invalid request params for forgot password") | ||
common.HandleErrorV2(w, http.StatusBadRequest, err.Error(), err) | ||
return | ||
} | ||
|
||
log.Printf("User: %v forgot password", fp.Username) | ||
|
||
sanitizedUserName := common.Sanitize(fp.Username) | ||
|
||
//Get user details from DB | ||
u, err := user.GetByEmail(sanitizedUserName) | ||
if err != nil { | ||
log.Printf("User with %v doesnt exist", fp.Username) | ||
common.HandleErrorV2(w, http.StatusBadRequest, err.Error(), err) | ||
return | ||
} | ||
err = iam.ForgotPassword(u.IamID) | ||
if err != nil { | ||
m := "Failed to send email" | ||
common.HandleErrorV2(w, http.StatusBadRequest, m, err) | ||
return | ||
} | ||
|
||
w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON) | ||
w.WriteHeader(http.StatusOK) | ||
} |
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
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
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