This commit is contained in:
@@ -17,20 +17,20 @@ func LoginGetHandler(c *gin.Context) {
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginGetHandler", globals.UserKey, user)
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login.html", gin.H{
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
"content": "Please logout first",
|
||||
"message": "Please logout first",
|
||||
"user": user,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "login.html", gin.H{
|
||||
c.HTML(http.StatusOK, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
"content": "",
|
||||
"message": "",
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
@@ -41,11 +41,11 @@ func LoginPostHandler(c *gin.Context) {
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginPostHandler", "user", user)
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login.html", gin.H{
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
"content": "Please logout first",
|
||||
"message": "Please logout first",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -54,30 +54,30 @@ func LoginPostHandler(c *gin.Context) {
|
||||
password := c.PostForm("password")
|
||||
|
||||
if helpers.EmptyUserPass(username, password) {
|
||||
c.HTML(http.StatusBadRequest, "login.html", gin.H{
|
||||
c.HTML(http.StatusBadRequest, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
"content": "Parameters can't be empty",
|
||||
"message": "Parameters can't be empty",
|
||||
})
|
||||
}
|
||||
|
||||
if !helpers.CheckUserPass(username, password) {
|
||||
c.HTML(http.StatusUnauthorized, "login.html", gin.H{
|
||||
c.HTML(http.StatusUnauthorized, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
"content": "Incorrect username or password",
|
||||
"message": "Incorrect username or password",
|
||||
})
|
||||
}
|
||||
|
||||
session.Set(globals.UserKey, username)
|
||||
if err := session.Save(); err != nil {
|
||||
c.HTML(http.StatusInternalServerError, "login.html", gin.H{
|
||||
c.HTML(http.StatusInternalServerError, "login", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
"content": "Failed to save session",
|
||||
"message": "Failed to save session",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user