diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-09-05 21:50:44 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-09-05 21:50:44 +0200 |
commit | 6f4d4569a5227e1962f5f7a81e1a63b6046cfb6c (patch) | |
tree | 0e0a49b15f67de1816c756de04eb8f0f4a9a2288 /pwreset.go | |
parent | 0829fda06733674abdc340ec17c0fbfb4fd778ae (diff) | |
download | mailremind-6f4d4569a5227e1962f5f7a81e1a63b6046cfb6c.tar.gz mailremind-6f4d4569a5227e1962f5f7a81e1a63b6046cfb6c.tar.bz2 mailremind-6f4d4569a5227e1962f5f7a81e1a63b6046cfb6c.zip |
Menu options change drectly on Login/Logout
Diffstat (limited to 'pwreset.go')
-rw-r--r-- | pwreset.go | 40 |
1 files changed, 20 insertions, 20 deletions
@@ -12,9 +12,9 @@ type pwresetTpldata struct { Error, Success, Code, UID string } -func pwreset(user model.User, sess *sessions.Session, req *http.Request) interface{} { +func pwreset(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) { if err := req.ParseForm(); err != nil { - return &pwresetTpldata{Error: "Could not understand formdata."} + return &pwresetTpldata{Error: "Could not understand formdata."}, user } code := req.FormValue("Code") @@ -23,49 +23,49 @@ func pwreset(user model.User, sess *sessions.Session, req *http.Request) interfa pw2 := req.FormValue("PasswordAgain") if code == "" { - return &pwresetTpldata{Error: "Wrong password reset code"} + return &pwresetTpldata{Error: "Wrong password reset code"}, user } uid, err := db.ParseDBID(_uid) if err != nil { - return &pwresetTpldata{Error: "Invalid user ID"} + return &pwresetTpldata{Error: "Invalid user ID"}, user } if user, err = dbcon.UserByID(uid); err != nil { - return &pwresetTpldata{Error: "User not found"} + return &pwresetTpldata{Error: "User not found"}, user } if user.ActivationCode() != code { - return &pwresetTpldata{Error: "Wrong activation code"} + return &pwresetTpldata{Error: "Wrong activation code"}, user } outdata := &pwresetTpldata{UID: _uid, Code: code} if req.Method != "POST" { - return outdata + return outdata, user } if pw1 == "" { outdata.Error = "Password must not be empty." - return outdata + return outdata, user } if pw1 != pw2 { outdata.Error = "Passwords are not identical." - return outdata + return outdata, user } hash, err := bcrypt.GenerateFromPassword([]byte(pw1), bcrypt.DefaultCost) if err != nil { log.Printf("Could not has password: %s", err) outdata.Error = "Failed hashing you password. If this happens again, please contact support." - return outdata + return outdata, user } if err := user.SetPWHash(hash); err != nil { log.Printf("Error while storing new password: %s", err) outdata.Error = "Could not store password. If this happens again, please contact support." - return outdata + return outdata, user } if err := user.SetActivationCode(""); err != nil { @@ -73,41 +73,41 @@ func pwreset(user model.User, sess *sessions.Session, req *http.Request) interfa } outdata.Success = "Password was changed" - return outdata + return outdata, user } type forgotpwTpldata struct { Error, Success string } -func forgotpw(user model.User, sess *sessions.Session, req *http.Request) interface{} { +func forgotpw(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) { if req.Method != "POST" { - return &forgotpwTpldata{} + return &forgotpwTpldata{}, user } if err := req.ParseForm(); err != nil { - return &forgotpwTpldata{Error: "Could not understand formdata."} + return &forgotpwTpldata{Error: "Could not understand formdata."}, user } email := req.FormValue("Mail") if email == "" { - return &forgotpwTpldata{Error: "E-Mail must not be empty."} + return &forgotpwTpldata{Error: "E-Mail must not be empty."}, user } user, err := dbcon.UserByMail(email) if err != nil { - return &forgotpwTpldata{Error: "E-Mail not found."} + return &forgotpwTpldata{Error: "E-Mail not found."}, user } 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."} + return &forgotpwTpldata{Error: "Could not store keyword reset code. If this happens again, please contact support."}, user } 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{Error: "Could not send reset E-Mail. If this happens again, please contact support."}, user } - return &forgotpwTpldata{Success: "We sent you an E-Mail with further instructions."} + return &forgotpwTpldata{Success: "We sent you an E-Mail with further instructions."}, user } |