diff --git a/controller/user.go b/controller/user.go index f17af0a..1cd8e80 100644 --- a/controller/user.go +++ b/controller/user.go @@ -48,7 +48,7 @@ func login(c *gin.Context) { var ( session *model.Session ) - if loginData.Type == 0 { + if loginData.Type == model.USER_TYPE_ENT { session, err = service.UserService.ProcessEnterpriseUserLogin(loginData.Username, loginData.Password) } else { session, err = service.UserService.ProcessManagementUserLogin(loginData.Username, loginData.Password) @@ -276,7 +276,7 @@ func createEnterpriseAccount(c *gin.Context) { } newUser := new(model.User) newUser.Username = creationForm.Username - newUser.Type = 0 + newUser.Type = model.USER_TYPE_ENT newUser.Enabled = true newUserDetail := new(model.UserDetail) newUserDetail.Name = &creationForm.Name diff --git a/model/user.go b/model/user.go index 9a25efd..4e6944f 100644 --- a/model/user.go +++ b/model/user.go @@ -1,5 +1,11 @@ package model +const ( + USER_TYPE_ENT int8 = iota + USER_TYPE_SUP + USER_TYPE_OPS +) + type User struct { Created `xorm:"extends"` Id string `xorm:"varchar(120) pk not null" json:"id"` diff --git a/security/security.go b/security/security.go index 9179ea7..7682c3f 100644 --- a/security/security.go +++ b/security/security.go @@ -45,7 +45,7 @@ func EnterpriseAuthorize(c *gin.Context) { if !exists || session == nil { c.AbortWithStatus(http.StatusForbidden) } - if sess, ok := session.(*model.Session); !ok || sess.Type != 0 { + if sess, ok := session.(*model.Session); !ok || sess.Type != model.USER_TYPE_ENT { c.AbortWithStatus(http.StatusForbidden) } c.Next() @@ -58,7 +58,7 @@ func ManagementAuthorize(c *gin.Context) { if !exists || session == nil { c.AbortWithStatus(http.StatusForbidden) } - if sess, ok := session.(*model.Session); !ok || (sess.Type != 1 && sess.Type != 2) { + if sess, ok := session.(*model.Session); !ok || (sess.Type != model.USER_TYPE_SUP && sess.Type != model.USER_TYPE_OPS) { c.AbortWithStatus(http.StatusForbidden) } c.Next() @@ -71,7 +71,7 @@ func OPSAuthorize(c *gin.Context) { if !exists { c.AbortWithStatus(http.StatusForbidden) } - if sess, ok := session.(*model.Session); !ok || sess.Type != 2 { + if sess, ok := session.(*model.Session); !ok || sess.Type != model.USER_TYPE_OPS { c.AbortWithStatus(http.StatusForbidden) } c.Next()