diff options
Diffstat (limited to 'activate.go')
-rw-r--r-- | activate.go | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/activate.go b/activate.go index ae392d1..56ef897 100644 --- a/activate.go +++ b/activate.go @@ -1,18 +1,14 @@ package main import ( + "github.com/gorilla/sessions" "kch42.de/gostuff/mailremind/model" "log" "net/http" ) -func activate(rw http.ResponseWriter, req *http.Request) { +func activate(user model.User, sess *sessions.Session, req *http.Request) interface{} { outdata := &msgTpldata{Title: "Activate Account", Class: "error"} - defer func() { - if err := tplMsg.Execute(rw, outdata); err != nil { - log.Printf("Could not execute template in activate: %s", err) - } - }() req.ParseForm() @@ -21,44 +17,44 @@ func activate(rw http.ResponseWriter, req *http.Request) { if (_userid == "") || (code == "") { outdata.Msg = "User or code invalid. Check, if the activation link was correctly copied from the mail." - return + return outdata } userid, err := db.ParseDBID(_userid) if err != nil { outdata.Msg = "User or code invalid. Check, if the activation link was correctly copied from the mail." - return + return outdata } - user, err := dbcon.UserByID(userid) - switch err { + switch user, err = dbcon.UserByID(userid); err { case nil: case model.NotFound: outdata.Msg = "User not found." - return + return outdata default: log.Printf("Error while getting user by ID <%s>: %s", userid, err) outdata.Msg = "An error occurred while loading user data. Send a message to the support, if this happens again." - return + return outdata } if user.ActivationCode() != code { outdata.Msg = "Wrong activation code." - return + return outdata } if err := user.SetActivationCode(""); err != nil { log.Printf("Error while resetting activation code: %s", err) outdata.Msg = "An error occurred while activating the user. Send a message to the support, if this happens again." - return + return outdata } if err := user.SetActive(true); err != nil { log.Printf("Error while resetting activation code: %s", err) outdata.Msg = "An error occurred while activating the user. Send a message to the support, if this happens again." - return + return outdata } outdata.Class = "success" outdata.Msg = "Account activated!" + return outdata } |