本文整理汇总了Golang中GoOnlineJudge/model.UserModel.Privilege方法的典型用法代码示例。如果您正苦于以下问题:Golang UserModel.Privilege方法的具体用法?Golang UserModel.Privilege怎么用?Golang UserModel.Privilege使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GoOnlineJudge/model.UserModel
的用法示例。
在下文中一共展示了UserModel.Privilege方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Privilegeset
func (this *UserController) Privilegeset(w http.ResponseWriter, r *http.Request) {
class.Logger.Debug("User Privilege")
this.Init(w, r)
args := this.ParseURL(r.URL.String())
uid := args["uid"]
privilegeStr := args["type"]
privilege := config.PrivilegeNA
switch privilegeStr {
case "Admin":
privilege = config.PrivilegeAD
case "TC":
privilege = config.PrivilegeTC
case "PU":
privilege = config.PrivilegePU
default:
http.Error(w, "args error", 400)
}
ok := 1
hint := make(map[string]string)
if uid == "" {
ok, hint["uid"] = 0, "Handle should not be empty."
} else if uid == this.Uid {
ok, hint["uid"] = 0, "You cannot delete yourself"
} else {
userModel := model.UserModel{}
_, err := userModel.Detail(uid)
if err == model.NotFoundErr {
ok, hint["uid"] = 0, "This handle does not exist!"
} else if err != nil {
http.Error(w, err.Error(), 400)
return
}
}
if ok == 1 {
userModel := model.UserModel{}
err := userModel.Privilege(uid, privilege)
if err != nil {
http.Error(w, err.Error(), 400)
return
}
w.WriteHeader(200)
} else {
b, err := json.Marshal(&hint)
if err != nil {
http.Error(w, "json error", 500)
return
}
w.WriteHeader(400)
w.Write(b)
}
}
示例2: Privilegeset
// 设置用户权限
//@URL: /admin/privilegeset @method: POST
func (uc *AdminUser) Privilegeset() {
restweb.Logger.Debug("User Privilege")
uid := uc.Input.Get("uid")
privilegeStr := uc.Input.Get("type")
privilege := config.PrivilegeNA
switch privilegeStr {
case "Admin":
privilege = config.PrivilegeAD
case "TC":
privilege = config.PrivilegeTC
case "PU":
privilege = config.PrivilegePU
default:
uc.Error("args error", 400)
}
ok := 1
hint := make(map[string]string)
if uid == "" {
ok, hint["hint"] = 0, "Handle should not be empty."
} else if uid == uc.Uid {
ok, hint["hint"] = 0, "You cannot delete yourself!"
} else {
userModel := model.UserModel{}
_, err := userModel.Detail(uid)
if err == model.NotFoundErr {
ok, hint["hint"] = 0, "uc handle does not exist!"
} else if err != nil {
uc.Error(err.Error(), 400)
return
}
}
if ok == 1 {
userModel := model.UserModel{}
err := userModel.Privilege(uid, privilege)
if err != nil {
uc.Error(err.Error(), 400)
return
}
uc.W.WriteHeader(200)
} else {
b, _ := json.Marshal(&hint)
uc.W.WriteHeader(400)
uc.W.Write(b)
}
}