summaryrefslogtreecommitdiff
path: root/pwreset.go
diff options
context:
space:
mode:
Diffstat (limited to 'pwreset.go')
-rw-r--r--pwreset.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/pwreset.go b/pwreset.go
index 92bbbc4..b428918 100644
--- a/pwreset.go
+++ b/pwreset.go
@@ -75,3 +75,39 @@ func pwreset(user model.User, sess *sessions.Session, req *http.Request) interfa
outdata.Success = "Password was changed"
return outdata
}
+
+type forgotpwTpldata struct {
+ Error, Success string
+}
+
+func forgotpw(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+ if req.Method != "POST" {
+ return &forgotpwTpldata{}
+ }
+
+ if err := req.ParseForm(); err != nil {
+ return &forgotpwTpldata{Error: "Could not understand formdata."}
+ }
+
+ email := req.FormValue("Mail")
+ if email == "" {
+ return &forgotpwTpldata{Error: "E-Mail must not be empty."}
+ }
+
+ user, err := dbcon.UserByMail(email)
+ if err != nil {
+ return &forgotpwTpldata{Error: "E-Mail not found."}
+ }
+
+ key := genAcCode()
+ if err := user.SetActivationCode(key); err != nil {
+ log.Printf("Could not store pwreset key: %s", err)
+ return &forgotpwTpldata{Error: "Could not store keyword reset code. If this happens again, please contact support."}
+ }
+
+ if !SendPwresetLink(user.Email(), key, user.ID()) {
+ return &forgotpwTpldata{Error: "Could not send reset E-Mail. If this happens again, please contact support."}
+ }
+
+ return &forgotpwTpldata{Success: "We sent you an E-Mail with further instructions."}
+}