forked from free-lancers/electricity_bill_calc_service
		
	refactor(model):固化用户类型为枚举。
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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"` | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user