summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activate.go18
-rw-r--r--deleteacc.go12
-rw-r--r--handler.go4
-rw-r--r--jobedit.go14
-rw-r--r--jobs.go6
-rw-r--r--login.go26
-rw-r--r--pwreset.go40
-rw-r--r--register.go26
8 files changed, 73 insertions, 73 deletions
diff --git a/activate.go b/activate.go
index 56ef897..59e7eed 100644
--- a/activate.go
+++ b/activate.go
@@ -7,7 +7,7 @@ import (
"net/http"
)
-func activate(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func activate(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
outdata := &msgTpldata{Title: "Activate Account", Class: "error"}
req.ParseForm()
@@ -17,44 +17,44 @@ func activate(user model.User, sess *sessions.Session, req *http.Request) interf
if (_userid == "") || (code == "") {
outdata.Msg = "User or code invalid. Check, if the activation link was correctly copied from the mail."
- return outdata
+ return outdata, user
}
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 outdata
+ return outdata, user
}
switch user, err = dbcon.UserByID(userid); err {
case nil:
case model.NotFound:
outdata.Msg = "User not found."
- return outdata
+ return outdata, user
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 outdata
+ return outdata, user
}
if user.ActivationCode() != code {
outdata.Msg = "Wrong activation code."
- return outdata
+ return outdata, user
}
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 outdata
+ return outdata, user
}
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 outdata
+ return outdata, user
}
outdata.Class = "success"
outdata.Msg = "Account activated!"
- return outdata
+ return outdata, user
}
diff --git a/deleteacc.go b/deleteacc.go
index 641d3c9..826cc1b 100644
--- a/deleteacc.go
+++ b/deleteacc.go
@@ -11,28 +11,28 @@ type reallydeleteTpldata struct {
OK bool
}
-func deleteask(user model.User, sess *sessions.Session, req *http.Request) interface{} {
- return &reallydeleteTpldata{user != nil}
+func deleteask(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
+ return &reallydeleteTpldata{user != nil}, user
}
-func deleteacc(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func deleteacc(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
outdata := &msgTpldata{Title: "Delete Account"}
if user == nil {
outdata.Class = "error"
outdata.Msg = "You need to be logged in to do that"
- return outdata
+ return outdata, user
}
if err := user.Delete(); err != nil {
log.Printf("Error while deleting account: %s", err)
outdata.Class = "error"
outdata.Msg = "An error occurred during deletion. Please contact support, if this happens again."
- return outdata
+ return outdata, user
}
delete(sess.Values, "uid")
outdata.Class = "success"
outdata.Msg = "Account deleted."
- return outdata
+ return outdata, user
}
diff --git a/handler.go b/handler.go
index 9d4bcdf..eb82826 100644
--- a/handler.go
+++ b/handler.go
@@ -8,7 +8,7 @@ import (
"net/http"
)
-type Handler func(user model.User, sess *sessions.Session, req *http.Request) interface{}
+type Handler func(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User)
func getSess(req *http.Request) (*sessions.Session, error) {
sess, err := SessionStorage.Get(req, "mailremind-sess")
@@ -57,7 +57,7 @@ func mkHttpHandler(h Handler, tpl *template.Template) http.HandlerFunc {
}
user := userFromSess(sess)
- outdata := h(user, sess, req)
+ outdata, user := h(user, sess, req)
mail := ""
if user != nil {
mail = user.Email()
diff --git a/jobedit.go b/jobedit.go
index ea3f6c0..5519551 100644
--- a/jobedit.go
+++ b/jobedit.go
@@ -181,9 +181,9 @@ func logfail(what string, err error) bool {
return true
}
-func jobedit(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func jobedit(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
if user == nil {
- return &jobeditTpldata{Error: "You need to be logged in to do that.", Fatal: true}
+ return &jobeditTpldata{Error: "You need to be logged in to do that.", Fatal: true}, user
}
outdata := new(jobeditTpldata)
@@ -194,11 +194,11 @@ func jobedit(user model.User, sess *sessions.Session, req *http.Request) interfa
if _id != "" {
id, err := db.ParseDBID(_id)
if err != nil {
- return &jobeditTpldata{Error: "Job not found", Fatal: true}
+ return &jobeditTpldata{Error: "Job not found", Fatal: true}, user
}
if job, err = user.JobByID(id); err != nil {
- return &jobeditTpldata{Error: "Job not found", Fatal: true}
+ return &jobeditTpldata{Error: "Job not found", Fatal: true}, user
}
}
@@ -210,12 +210,12 @@ func jobedit(user model.User, sess *sessions.Session, req *http.Request) interfa
if (job == nil) && (user.CountJobs() >= jobsLimit) {
outdata.Error = "You have reached the limit of jobs per user."
outdata.Fatal = true
- return outdata
+ return outdata, user
}
if err := req.ParseForm(); err != nil {
outdata.Error = "Could not understand forma data."
- return outdata
+ return outdata, user
}
subject, content, mc, ok := outdata.interpretForm(req.Form, user)
@@ -242,5 +242,5 @@ func jobedit(user model.User, sess *sessions.Session, req *http.Request) interfa
}
}
- return outdata
+ return outdata, user
}
diff --git a/jobs.go b/jobs.go
index d4787fa..d715a04 100644
--- a/jobs.go
+++ b/jobs.go
@@ -30,9 +30,9 @@ type jobsTpldata struct {
Fatal bool
}
-func jobs(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func jobs(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
if user == nil {
- return &jobsTpldata{Error: "You need to be logged in to do that.", Fatal: true}
+ return &jobsTpldata{Error: "You need to be logged in to do that.", Fatal: true}, user
}
outdata := new(jobsTpldata)
@@ -77,5 +77,5 @@ listjobs:
outdata.Jobs[i] = jobToTpldata(job, user)
}
- return outdata
+ return outdata, user
}
diff --git a/login.go b/login.go
index 459d2ff..0f69fe4 100644
--- a/login.go
+++ b/login.go
@@ -16,27 +16,27 @@ type loginFormdata struct {
Mail, Password string
}
-func login(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func login(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
outdata := &loginTpldata{}
if user != nil {
outdata.Success = "You are already logged in"
- return outdata
+ return outdata, user
}
if req.Method != "POST" {
- return outdata
+ return outdata, user
}
if err := req.ParseForm(); err != nil {
outdata.Error = "Data of form could not be understand. If this happens again, please contact support!"
- return outdata
+ return outdata, user
}
indata := new(loginFormdata)
if err := formdec.Decode(indata, req.Form); (err != nil) || (indata.Mail == "") || (indata.Password == "") {
outdata.Error = "Input data wrong or missing. Please fill in all values."
- return outdata
+ return outdata, user
}
user, err := dbcon.UserByMail(indata.Mail)
@@ -44,32 +44,32 @@ func login(user model.User, sess *sessions.Session, req *http.Request) interface
case nil:
case model.NotFound:
outdata.Error = "E-Mail or password was wrong."
- return outdata
+ return outdata, user
default:
log.Printf("Error while loding user data (login): %s", err)
outdata.Error = "User data could not be loaded. Please contact support, if this happens again."
- return outdata
+ return outdata, user
}
if bcrypt.CompareHashAndPassword(user.PWHash(), []byte(indata.Password)) != nil {
outdata.Error = "E-Mail or password was wrong."
- return outdata
+ return outdata, user
}
sess.Values["uid"] = user.ID().String()
outdata.Success = "Login successful"
- return outdata
+ return outdata, user
}
-func logincheck(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func logincheck(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
outdata := &msgTpldata{Msg: "<nil>"}
if user != nil {
outdata.Msg = user.Email()
}
- return outdata
+ return outdata, user
}
-func logout(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func logout(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
delete(sess.Values, "uid")
- return &msgTpldata{Class: "success", Title: "Logout", Msg: "Your are now logged out."}
+ return &msgTpldata{Class: "success", Title: "Logout", Msg: "Your are now logged out."}, nil
}
diff --git a/pwreset.go b/pwreset.go
index b428918..655c45f 100644
--- a/pwreset.go
+++ b/pwreset.go
@@ -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
}
diff --git a/register.go b/register.go
index 38f7b97..5bd4d82 100644
--- a/register.go
+++ b/register.go
@@ -34,37 +34,37 @@ func genAcCode() string {
return string(code)
}
-func register(user model.User, sess *sessions.Session, req *http.Request) interface{} {
+func register(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
outdata := &registerData{Timezones: &timeLocs}
if user != nil {
outdata.Success = "You are already logged in. To register a new account, first log out."
- return outdata
+ return outdata, user
}
if req.Method != "POST" {
- return outdata
+ return outdata, user
}
if err := req.ParseForm(); err != nil {
outdata.Error = "Data of form could not be understand. If this happens again, please contact support!"
- return outdata
+ return outdata, user
}
indata := new(registerFormdata)
if err := formdec.Decode(indata, req.Form); (err != nil) || (indata.Mail == "") || (indata.Timezone.Loc == nil) {
outdata.Error = "Input data wrong or missing. Please fill in all values and make sure to provide a valid E-Mail address."
- return outdata
+ return outdata, user
}
if indata.Password == "" {
outdata.Error = "Empty passwords are not allowed."
- return outdata
+ return outdata, user
}
if indata.Password != indata.RetypePassword {
outdata.Error = "Passwords are not identical."
- return outdata
+ return outdata, user
}
mail := string(indata.Mail)
@@ -72,12 +72,12 @@ func register(user model.User, sess *sessions.Session, req *http.Request) interf
switch _, err := dbcon.UserByMail(mail); err {
case nil:
outdata.Error = "This E-Mail address is already used."
- return outdata
+ return outdata, user
case model.NotFound:
default:
log.Printf("Error while checking, if mail is used: %s", err)
outdata.Error = "Internal error, sorry. If this happens again, please contact support!"
- return outdata
+ return outdata, user
}
acCode := genAcCode()
@@ -85,21 +85,21 @@ func register(user model.User, sess *sessions.Session, req *http.Request) interf
if err != nil {
log.Printf("Error while hashing password: %s", err)
outdata.Error = "Internal error, sorry. If this happens again, please contact support!"
- return outdata
+ return outdata, user
}
user, err = dbcon.AddUser(mail, pwhash, indata.Timezone.Loc, false, acCode)
if err != nil {
log.Printf("Could not create user (%s): %s", indata.Mail, err)
outdata.Error = "Internal error, sorry. If this happens again, please contact support!"
- return outdata
+ return outdata, user
}
if !SendActivationcode(mail, acCode, user.ID()) {
outdata.Error = "We could not send you a mail with your confirmation code."
- return outdata
+ return outdata, user
}
outdata.Success = "Account created successfully! We sent you an E-Mail that contains a link to activate your account."
- return outdata
+ return outdata, user
}