diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-30 22:53:59 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-30 22:53:59 +0200 |
commit | d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3 (patch) | |
tree | 1df00e016300304318997e8f04053bf523b8d85e /pwreset.go | |
parent | 11ec26feeabced25281b8637f928a8096690c54b (diff) | |
download | mailremind-d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3.tar.gz mailremind-d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3.tar.bz2 mailremind-d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3.zip |
Password reset implemented
Diffstat (limited to 'pwreset.go')
-rw-r--r-- | pwreset.go | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -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."} +} |