Skip to content

Commit 41affac

Browse files
committed
Merge branch 'develop'
2 parents afd4f2d + 810133d commit 41affac

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

assets/buildinfo.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
BuildVersion=latest v1.0.1 2024-03-08 22:18:44
1+
BuildVersion=latest v1.0.1 2024-05-17 13:55:23
22
ReleaseVersion=v1.0.1
3-
BuildTime=2024-03-08 22:18:44
3+
BuildTime=2024-05-17 13:55:23
44
BuildName=teamsacs
5-
CommitID=91e6fe7f72395b71c27ca63fc139cd279036c65e
6-
CommitDate=Sat, 24 Jun 2023 10:52:35 +0800
5+
CommitID=b88275d9e89e5495f6df8a71dc55156812804588
6+
CommitDate=Fri, 8 Mar 2024 22:19:02 +0800
77
8-
CommitSubject= :
8+
CommitSubject= : release publish

controllers/index/index.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package index
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"net/http"
67
"strings"
78
"time"
@@ -16,14 +17,24 @@ import (
1617
"github.com/labstack/echo/v4"
1718
)
1819

20+
const (
21+
LoginPasswdErr = "wrong password"
22+
LoginUserErr = "user does not exist"
23+
LoginDbErr = "database connection failed"
24+
LoginInputErr = "username and password cannot be empty"
25+
LoginExpired = "User not logged in or login expired"
26+
)
27+
28+
var LoginErrors = []string{LoginPasswdErr, LoginUserErr, LoginDbErr, LoginInputErr, LoginExpired}
29+
1930
func InitRouter() {
2031

2132
// 系统首页
2233
webserver.GET("/", func(c echo.Context) error {
2334
sess, _ := session.Get(webserver.UserSession, c)
2435
username := sess.Values[webserver.UserSessionName]
2536
if username == nil || username == "" {
26-
return c.Redirect(http.StatusTemporaryRedirect, "/login?errmsg=User not logged in or login expired")
37+
return c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("/login?errmsg=%s", LoginExpired))
2738
}
2839
return c.Render(http.StatusOK, "index", map[string]interface{}{})
2940
})
@@ -73,6 +84,10 @@ func InitRouter() {
7384
// 登录页面
7485
webserver.GET("/login", func(c echo.Context) error {
7586
errmsg := c.QueryParam("errmsg")
87+
// errmsg must in LoginErrors
88+
if !common.InSlice(errmsg, LoginErrors) {
89+
errmsg = ""
90+
}
7691
return c.Render(http.StatusOK, "login", map[string]interface{}{
7792
"errmsg": errmsg,
7893
"LoginLogo": "/static/images/login-logo.png",
@@ -102,19 +117,19 @@ func InitRouter() {
102117
username := c.FormValue("username")
103118
password := c.FormValue("password")
104119
if username == "" || password == "" {
105-
return c.Redirect(http.StatusMovedPermanently, "/login?errmsg=Username and password cannot be empty")
120+
return c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/login?errmsg=%s", LoginInputErr))
106121
}
107122
var user models.SysOpr
108123
err := app.GDB().Where("username=?", username).First(&user).Error
109124
if err != nil {
110125
if strings.Contains(err.Error(), "dial error") {
111-
return c.Redirect(http.StatusMovedPermanently, "/login?errmsg=Database connection failed")
126+
return c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/login?errmsg=%s", LoginDbErr))
112127
}
113-
return c.Redirect(http.StatusMovedPermanently, "/login?errmsg=User does not exist")
128+
return c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/login?errmsg=%s", LoginUserErr))
114129
}
115130

116131
if common.Sha256HashWithSalt(password, common.SecretSalt) != user.Password {
117-
return c.Redirect(http.StatusMovedPermanently, "/login?errmsg=wrong password")
132+
return c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/login?errmsg=%s", LoginPasswdErr))
118133
}
119134

120135
sess, _ := session.Get(webserver.UserSession, c)

0 commit comments

Comments
 (0)