1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package router
- import (
- "exam_system/entity"
- "exam_system/result"
- "exam_system/service"
- "exam_system/vo"
- "github.com/gin-gonic/gin"
- )
- func Auth(router *RouterPlus) {
- authGroup := router.Group("/auth")
- {
-
-
-
- authGroup.POST("/login", Login)
- }
- }
- func Register(context *gin.Context) *result.Result {
- var body struct {
- entity.User
- UserType string `json:"user_type,omitempty"`
- }
- if err := context.ShouldBindJSON(&body); err != nil {
- return result.PASSWORD_ERROR
- }
- if body.Username == "" || body.Password == "" || body.Sid == "" {
- return result.PASSWORD_ERROR
- }
- status :=entity.UNDER_REVIEW
- body.Status = &status
- return service.AddUser(&body.User, body.UserType)
- }
- func Login(context *gin.Context) *result.Result {
- var user vo.UserVo
- if err := context.ShouldBindJSON(&user); err != nil {
- return result.PASSWORD_ERROR
- }
- if user.RoleName == nil {
- return result.PARAM_ERROR
- }
- return service.Login(&user)
- }
|