Unify the user's status. fix #9.
This commit is contained in:
@ -50,7 +50,7 @@ func (this *BaseController) HandleRoutes(writer http.ResponseWriter, request *ht
|
||||
}
|
||||
|
||||
//需要进行登录验证的wrap包装
|
||||
func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *http.Request) *WebResult, role string) func(w http.ResponseWriter, r *http.Request) {
|
||||
func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *http.Request) *WebResult, qualifiedRole string) func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
|
||||
@ -59,13 +59,20 @@ func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *htt
|
||||
var webResult *WebResult = nil
|
||||
|
||||
//只有游客接口不需要登录
|
||||
if role != USER_ROLE_GUEST {
|
||||
if qualifiedRole != USER_ROLE_GUEST {
|
||||
user := this.checkUser(writer, request)
|
||||
if role == USER_ROLE_ADMINISTRATOR && user.Role != USER_ROLE_ADMINISTRATOR {
|
||||
webResult = ConstWebResult(RESULT_CODE_UNAUTHORIZED)
|
||||
|
||||
if user.Status == USER_STATUS_DISABLED {
|
||||
//判断用户是否被禁用。
|
||||
webResult = ConstWebResult(RESULT_CODE_LOGIN_INVALID)
|
||||
} else {
|
||||
webResult = f(writer, request)
|
||||
if qualifiedRole == USER_ROLE_ADMINISTRATOR && user.Role != USER_ROLE_ADMINISTRATOR {
|
||||
webResult = ConstWebResult(RESULT_CODE_UNAUTHORIZED)
|
||||
} else {
|
||||
webResult = f(writer, request)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
webResult = f(writer, request)
|
||||
}
|
||||
|
@ -240,6 +240,7 @@ func (this *UserController) Page(writer http.ResponseWriter, request *http.Reque
|
||||
username := request.FormValue("username")
|
||||
email := request.FormValue("email")
|
||||
phone := request.FormValue("phone")
|
||||
status := request.FormValue("status")
|
||||
orderLastTime := request.FormValue("orderLastTime")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
|
||||
@ -267,7 +268,7 @@ func (this *UserController) Page(writer http.ResponseWriter, request *http.Reque
|
||||
},
|
||||
}
|
||||
|
||||
pager := this.userDao.Page(page, pageSize, username, email, phone, sortArray)
|
||||
pager := this.userDao.Page(page, pageSize, username, email, phone, status, sortArray)
|
||||
|
||||
return this.Success(pager)
|
||||
}
|
||||
@ -279,6 +280,11 @@ func (this *UserController) Disable(writer http.ResponseWriter, request *http.Re
|
||||
|
||||
user := this.userDao.CheckByUuid(uuid)
|
||||
|
||||
loginUser := this.checkUser(writer, request)
|
||||
if uuid == loginUser.Uuid {
|
||||
return this.Error("你不能操作自己的状态。")
|
||||
}
|
||||
|
||||
if user.Status == USER_STATUS_DISABLED {
|
||||
return this.Error("用户已经被禁用,操作无效。")
|
||||
}
|
||||
@ -297,6 +303,10 @@ func (this *UserController) Enable(writer http.ResponseWriter, request *http.Req
|
||||
uuid := request.FormValue("uuid")
|
||||
|
||||
user := this.userDao.CheckByUuid(uuid)
|
||||
loginUser := this.checkUser(writer, request)
|
||||
if uuid == loginUser.Uuid {
|
||||
return this.Error("你不能操作自己的状态。")
|
||||
}
|
||||
|
||||
if user.Status == USER_STATUS_OK {
|
||||
return this.Error("用户已经是正常状态,操作无效。")
|
||||
|
@ -64,7 +64,7 @@ func (this *UserDao) FindByEmail(email string) *User {
|
||||
}
|
||||
|
||||
//显示用户列表。
|
||||
func (this *UserDao) Page(page int, pageSize int, username string, email string, phone string, sortArray []OrderPair) *Pager {
|
||||
func (this *UserDao) Page(page int, pageSize int, username string, email string, phone string, status string, sortArray []OrderPair) *Pager {
|
||||
|
||||
var wp = &WherePair{}
|
||||
|
||||
@ -80,6 +80,10 @@ func (this *UserDao) Page(page int, pageSize int, username string, email string,
|
||||
wp = wp.And(&WherePair{Query: "phone = ?", Args: []interface{}{phone}})
|
||||
}
|
||||
|
||||
if status != "" {
|
||||
wp = wp.And(&WherePair{Query: "status = ?", Args: []interface{}{status}})
|
||||
}
|
||||
|
||||
count := 0
|
||||
db := this.context.DB.Model(&User{}).Where(wp.Query, wp.Args...).Count(&count)
|
||||
this.PanicError(db.Error)
|
||||
|
@ -20,7 +20,9 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
//正常状态
|
||||
USER_STATUS_OK = "OK"
|
||||
//被禁用
|
||||
USER_STATUS_DISABLED = "DISABLED"
|
||||
)
|
||||
|
||||
|
@ -82,7 +82,7 @@ func ConstWebResult(code int) *WebResult {
|
||||
|
||||
//该登录用户不是有效用户
|
||||
case RESULT_CODE_LOGIN_INVALID:
|
||||
wr.Msg = "该登录用户不是有效用户"
|
||||
wr.Msg = "该登录用户不是有效用户或者用户已被禁用"
|
||||
|
||||
//提交的表单验证不通过
|
||||
case RESULT_CODE_FORM_INVALID:
|
||||
|
Reference in New Issue
Block a user