summaryrefslogtreecommitdiff
path: root/activate.go
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-30 15:11:50 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-30 15:11:50 +0200
commit3a501d85a560b2e2c5c5ded47cc431e4f1315d21 (patch)
tree4a339c9c992645d69b22e592b12ccb3e051a0d40 /activate.go
parentbf1207d7f3a4e95124c5f1498f96fad298e496a6 (diff)
downloadmailremind-3a501d85a560b2e2c5c5ded47cc431e4f1315d21.tar.gz
mailremind-3a501d85a560b2e2c5c5ded47cc431e4f1315d21.tar.bz2
mailremind-3a501d85a560b2e2c5c5ded47cc431e4f1315d21.zip
Defined own handler type to reduce repetive jobs.
Diffstat (limited to 'activate.go')
-rw-r--r--activate.go26
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
}