refactor(model):固化用户类型为枚举。
This commit is contained in:
parent
1c4132e2e7
commit
14ffd0e9fb
|
@ -48,7 +48,7 @@ func login(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
session *model.Session
|
session *model.Session
|
||||||
)
|
)
|
||||||
if loginData.Type == 0 {
|
if loginData.Type == model.USER_TYPE_ENT {
|
||||||
session, err = service.UserService.ProcessEnterpriseUserLogin(loginData.Username, loginData.Password)
|
session, err = service.UserService.ProcessEnterpriseUserLogin(loginData.Username, loginData.Password)
|
||||||
} else {
|
} else {
|
||||||
session, err = service.UserService.ProcessManagementUserLogin(loginData.Username, loginData.Password)
|
session, err = service.UserService.ProcessManagementUserLogin(loginData.Username, loginData.Password)
|
||||||
|
@ -276,7 +276,7 @@ func createEnterpriseAccount(c *gin.Context) {
|
||||||
}
|
}
|
||||||
newUser := new(model.User)
|
newUser := new(model.User)
|
||||||
newUser.Username = creationForm.Username
|
newUser.Username = creationForm.Username
|
||||||
newUser.Type = 0
|
newUser.Type = model.USER_TYPE_ENT
|
||||||
newUser.Enabled = true
|
newUser.Enabled = true
|
||||||
newUserDetail := new(model.UserDetail)
|
newUserDetail := new(model.UserDetail)
|
||||||
newUserDetail.Name = &creationForm.Name
|
newUserDetail.Name = &creationForm.Name
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
|
const (
|
||||||
|
USER_TYPE_ENT int8 = iota
|
||||||
|
USER_TYPE_SUP
|
||||||
|
USER_TYPE_OPS
|
||||||
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Created `xorm:"extends"`
|
Created `xorm:"extends"`
|
||||||
Id string `xorm:"varchar(120) pk not null" json:"id"`
|
Id string `xorm:"varchar(120) pk not null" json:"id"`
|
||||||
|
|
|
@ -45,7 +45,7 @@ func EnterpriseAuthorize(c *gin.Context) {
|
||||||
if !exists || session == nil {
|
if !exists || session == nil {
|
||||||
c.AbortWithStatus(http.StatusForbidden)
|
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.AbortWithStatus(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Next()
|
||||||
|
@ -58,7 +58,7 @@ func ManagementAuthorize(c *gin.Context) {
|
||||||
if !exists || session == nil {
|
if !exists || session == nil {
|
||||||
c.AbortWithStatus(http.StatusForbidden)
|
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.AbortWithStatus(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Next()
|
||||||
|
@ -71,7 +71,7 @@ func OPSAuthorize(c *gin.Context) {
|
||||||
if !exists {
|
if !exists {
|
||||||
c.AbortWithStatus(http.StatusForbidden)
|
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.AbortWithStatus(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user