diff --git a/controller/register/student_register.go b/controller/register/student_register.go index 6af5714..7953f58 100644 --- a/controller/register/student_register.go +++ b/controller/register/student_register.go @@ -36,6 +36,13 @@ func StudentRegister(context *gin.Context) { return } + var user model.Person + result := global.DB.Where("identity = ? Or tel = ?", postData.ID, postData.Contact.Tel).Take(&user) + if result.RowsAffected != 0 { + utility.ResponseError(context, "您已经注册过了,请到登录页面登录") + return + } + person := model.Person{ OpenId: jwtData.OpenID, Name: postData.Name, @@ -55,7 +62,7 @@ func StudentRegister(context *gin.Context) { Type: 1, } - result := global.DB.Create(&person) + result = global.DB.Create(&person) if result.RowsAffected == 0 { utility.ResponseError(context, "报名失败,请重试") } else { diff --git a/controller/register/teacher_register.go b/controller/register/teacher_register.go index a696875..8f6285a 100644 --- a/controller/register/teacher_register.go +++ b/controller/register/teacher_register.go @@ -34,6 +34,13 @@ func TeacherRegister(context *gin.Context) { return } + var user model.Person + result := global.DB.Where("identity = ? Or tel = ?", postData.ID, postData.Contact.Tel).Take(&user) + if result.RowsAffected != 0 { + utility.ResponseError(context, "您已经注册过了,请到登录页面登录") + return + } + person := model.Person{ OpenId: jwtData.OpenID, StuId: postData.StuID, @@ -51,7 +58,7 @@ func TeacherRegister(context *gin.Context) { Type: 2, } - result := global.DB.Create(&person) + result = global.DB.Create(&person) if result.RowsAffected == 0 { utility.ResponseError(context, "报名失败,请重试") } else { diff --git a/controller/team/submit_team.go b/controller/team/submit_team.go index 6d28847..5058524 100644 --- a/controller/team/submit_team.go +++ b/controller/team/submit_team.go @@ -59,6 +59,10 @@ func SubmitTeam(context *gin.Context) { } if person.Type == 1 { + if team.Submit != true { + utility.ResponseError(context, "队伍提交失败,等待后续补报") + return + } teamID := strconv.Itoa(int(team.ID)) dailyRoute := utility.GetCurrentDate()*10 + team.Route dailyRouteKey := strconv.Itoa(int(dailyRoute)) diff --git a/middleware/intercept.go b/middleware/intercept.go new file mode 100644 index 0000000..f2be52c --- /dev/null +++ b/middleware/intercept.go @@ -0,0 +1,12 @@ +package middleware + +import ( + "github.com/gin-gonic/gin" + "walk-server/utility" +) + +func Intercept(context *gin.Context) { + utility.ResponseError(context, "该操作不允许") + context.Abort() + return +} diff --git a/router/routes.go b/router/routes.go index 88034f7..87b0ceb 100644 --- a/router/routes.go +++ b/router/routes.go @@ -14,7 +14,7 @@ import ( ) func MountRoutes(router *gin.Engine) { - router.POST("/api/v1/redis2mysql", middleware.TokenRateLimiter, team.RedisToMysql) // 从 Redis 中导入数据到 MySQL + router.POST("/api/v1/redis2mysql", middleware.TokenRateLimiter, middleware.Intercept, team.RedisToMysql) // 从 Redis 中导入数据到 MySQL api := router.Group("/api/v1", middleware.TokenRateLimiter) { if !gin.IsDebugging() { @@ -46,19 +46,19 @@ func MountRoutes(router *gin.Engine) { if gin.IsDebugging() { teamApi.GET("/submit", team.SubmitTeam) // 提交团队 } else { - teamApi.GET("/submit", middleware.IsExpired, middleware.CanSubmit, team.SubmitTeam) // 提交团队 + teamApi.GET("/submit", middleware.IsExpired, team.SubmitTeam) // 提交团队 } - teamApi.GET("/info", team.GetTeamInfo) // 获取团队信息 - teamApi.POST("/random-list", team.GetRandomList) // 随机获取开放随机组队的团队列表 - teamApi.POST("/random-join", middleware.IsExpired, team.RandomJoin) // 通过随机列表加入团队 - teamApi.POST("/create", middleware.IsExpired, team.CreateTeam) // 创建团队 - teamApi.POST("/update", middleware.IsExpired, team.UpdateTeam) // 修改队伍信息 - teamApi.POST("/join", middleware.IsExpired, team.JoinTeam) // 加入团队 - teamApi.GET("/leave", middleware.IsExpired, team.LeaveTeam) // 离开团队 - teamApi.GET("/remove", middleware.IsExpired, team.RemoveMember) // 移除队员 - teamApi.GET("/disband", middleware.IsExpired, team.DisbandTeam) // 解散团队 - teamApi.GET("/rollback", middleware.IsExpired, team.RollBackTeam) // 撤销提交 + teamApi.GET("/info", team.GetTeamInfo) // 获取团队信息 + teamApi.POST("/random-list", team.GetRandomList) // 随机获取开放随机组队的团队列表 + teamApi.POST("/random-join", middleware.IsExpired, team.RandomJoin) // 通过随机列表加入团队 + teamApi.POST("/create", middleware.IsExpired, middleware.Intercept, team.CreateTeam) // 创建团队 + teamApi.POST("/update", middleware.IsExpired, middleware.Intercept, team.UpdateTeam) // 修改队伍信息 + teamApi.POST("/join", middleware.IsExpired, team.JoinTeam) // 加入团队 + teamApi.GET("/leave", middleware.IsExpired, team.LeaveTeam) // 离开团队 + teamApi.GET("/remove", middleware.IsExpired, team.RemoveMember) // 移除队员 + teamApi.GET("/disband", middleware.IsExpired, middleware.Intercept, team.DisbandTeam) // 解散团队 + teamApi.GET("/rollback", middleware.IsExpired, team.RollBackTeam) // 撤销提交 } // 事件相关的 API