|
@@ -7,7 +7,7 @@ import (
|
|
|
"git.mmnx.de/Moe/usermanager"
|
|
"git.mmnx.de/Moe/usermanager"
|
|
|
"git.mmnx.de/Moe/databaseutils"
|
|
"git.mmnx.de/Moe/databaseutils"
|
|
|
"git.mmnx.de/Moe/configutils"
|
|
"git.mmnx.de/Moe/configutils"
|
|
|
- "git.mmnx.de/Moe/templatehelpers"
|
|
|
|
|
|
|
+ "git.mmnx.de/Moe/errorhelpers"
|
|
|
|
|
|
|
|
// "errors"
|
|
// "errors"
|
|
|
)
|
|
)
|
|
@@ -63,7 +63,7 @@ func main() {
|
|
|
|
|
|
|
|
iris.Get("/login", templateHandler) // TODO not when logged in
|
|
iris.Get("/login", templateHandler) // TODO not when logged in
|
|
|
iris.Get("/logout", usermanager.AuthHandler, usermanager.LogoutHandler)
|
|
iris.Get("/logout", usermanager.AuthHandler, usermanager.LogoutHandler)
|
|
|
- iris.Get("/register", templateHandler) // TODO not when logged in
|
|
|
|
|
|
|
+ iris.Get("/register", templateHandler)
|
|
|
iris.Get("/", usermanager.AuthHandler, templateHandler)
|
|
iris.Get("/", usermanager.AuthHandler, templateHandler)
|
|
|
iris.Get("/account", usermanager.AuthHandler, templateHandler)
|
|
iris.Get("/account", usermanager.AuthHandler, templateHandler)
|
|
|
iris.Get("/help", usermanager.AuthHandler, templateHandler)
|
|
iris.Get("/help", usermanager.AuthHandler, templateHandler)
|
|
@@ -80,13 +80,9 @@ func loginHandler(ctx *iris.Context) {
|
|
|
|
|
|
|
|
user := usermanager.User{} // new user
|
|
user := usermanager.User{} // new user
|
|
|
tokenString, err := user.Login(username, password) // try to login
|
|
tokenString, err := user.Login(username, password) // try to login
|
|
|
|
|
+ ctx.SetCookieKV("token", tokenString)
|
|
|
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- templatehelpers.ShowError(err.Error(), ctx, "login")
|
|
|
|
|
- } else {
|
|
|
|
|
- ctx.SetCookieKV("token", tokenString)
|
|
|
|
|
- templatehelpers.ShowNotification("Login successfull", ctx, "home")
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ errorhelpers.HandleError(err, ctx, []string{usermanager.SUCCESS_LOGIN, "home"})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func accountUpdateHandler(ctx *iris.Context) {
|
|
func accountUpdateHandler(ctx *iris.Context) {
|
|
@@ -94,17 +90,13 @@ func accountUpdateHandler(ctx *iris.Context) {
|
|
|
password := ctx.FormValueString("password")
|
|
password := ctx.FormValueString("password")
|
|
|
userID := ctx.GetString("userID")
|
|
userID := ctx.GetString("userID")
|
|
|
|
|
|
|
|
- if err := usermanager.UserUpdateProcessor(username, password, userID); err != nil {
|
|
|
|
|
- templatehelpers.ShowError(err.Error(), ctx, "account")
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- templatehelpers.ShowNotification("updated successfull", ctx, "account")
|
|
|
|
|
|
|
+ err := usermanager.UserUpdateProcessor(username, password, userID)
|
|
|
|
|
+ errorhelpers.HandleError(err, ctx, []string{usermanager.SUCCESS_UPDATE, "home"})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func adminPostHandler(ctx *iris.Context) {
|
|
func adminPostHandler(ctx *iris.Context) {
|
|
|
- _ = usermanager.GenerateTokens(5) // generate tokens and store in db, we don't need them now
|
|
|
|
|
- templatehelpers.ShowNotification("tokens generated", ctx, "admin")
|
|
|
|
|
|
|
+ _, err := usermanager.GenerateTokens(5) // generate tokens and store in db, we don't need them now, TODO error handling?
|
|
|
|
|
+ errorhelpers.HandleError(err, ctx, []string{usermanager.SUCCESS_TOKENS_GENERATED, "home"})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func templateHandler(ctx *iris.Context) {
|
|
func templateHandler(ctx *iris.Context) {
|