Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 6ac0fb6

Browse files
committed
added reset password functions
1 parent 0568995 commit 6ac0fb6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

account.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package backend
22

3+
import (
4+
"fmt"
5+
"net/url"
6+
"strings"
7+
)
8+
39
type AccountParams struct {
410
Email string `json:"email"`
511
Password string `json:"password"`
@@ -50,6 +56,37 @@ func SetPassword(token, email, oldPassword, newPassword string) error {
5056
return nil
5157
}
5258

59+
func GetPasswordResetCode(token, email string) (string, error) {
60+
qs := url.Values{}
61+
qs.Add("e", email)
62+
63+
var code string
64+
path := fmt.Sprintf("/password/resetcode?%s", qs.Encode())
65+
if err := Get(token, path, &code); err != nil {
66+
return "", err
67+
}
68+
return code, nil
69+
}
70+
71+
func ResetPassword(email, code, password string) error {
72+
var body = new(struct {
73+
Email string `json:"email"`
74+
Code string `json:"code"`
75+
Password string `json:"password"`
76+
})
77+
body.Email = strings.ToLower(email)
78+
body.Code = code
79+
body.Password = password
80+
81+
var status bool
82+
if err := Post("", "/password/reset", body, &status); err != nil {
83+
return err
84+
} else if !status {
85+
return fmt.Errorf("unable to reset password")
86+
}
87+
return nil
88+
}
89+
5390
// SudoGetToken returns a token from an AccountID
5491
// This is useful when performing creation that documents needs
5592
// to be attached to a specific account id and therefor the SudoCreate

0 commit comments

Comments
 (0)