本文整理匯總了Golang中github.com/easykoo/go-blog/model.User類的典型用法代碼示例。如果您正苦於以下問題:Golang User類的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了User類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LiftUser
func LiftUser(ctx *middleware.Context, params martini.Params) {
id := params["id"]
user := new(model.User)
user.Id = ParseInt(id)
err := user.SetLock(false)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例2: DeleteUsers
func DeleteUsers(ctx *middleware.Context) {
users := ctx.R.FormValue("Users")
var res []int
json.Unmarshal([]byte(users), &res)
user := new(model.User)
err := user.DeleteUsers(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例3: RegisterHandler
func RegisterHandler(ctx *middleware.Context, formErr binding.Errors, user model.UserRegisterForm) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
if !ctx.HasError() {
dbUser := model.User{Username: user.Username, Password: user.Password, Email: user.Email}
if exist, err := dbUser.ExistUsername(); exist {
PanicIf(err)
ctx.AddFieldError("username", Translate(ctx.S.Get("Lang").(string), "message.error.already.exists"))
}
if exist, err := dbUser.ExistEmail(); exist {
PanicIf(err)
ctx.AddFieldError("email", Translate(ctx.S.Get("Lang").(string), "message.error.already.exists"))
}
if !ctx.HasError() {
dbUser.Password = Md5(user.Password)
err := dbUser.Insert()
PanicIf(err)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.register.success"))
} else {
ctx.Set("User", user)
}
ctx.HTML(200, "user/register", ctx)
} else {
ctx.Set("User", user)
ctx.HTML(200, "user/register", ctx)
}
default:
ctx.HTML(200, "user/register", ctx)
}
}
示例4: SetRole
func SetRole(ctx *middleware.Context) {
id := ctx.R.PostFormValue("Id")
roleId := ctx.R.PostFormValue("RoleId")
version := ctx.R.PostFormValue("Version")
user := new(model.User)
user.Id = ParseInt(id)
user.Role.Id = ParseInt(roleId)
user.Version = ParseInt(version)
err := user.SetRole()
PanicIf(err)
ctx.Set("success", true)
Log.Info("User: ", user.Id, " roleId set to ", roleId)
ctx.JSON(200, ctx.Response)
}
示例5: ProfileHandler
func ProfileHandler(ctx *middleware.Context, formErr binding.Errors, user model.User) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
if !ctx.HasError() {
err := user.Update()
PanicIf(err)
dbUser, err := user.GetUserById(user.Id)
PanicIf(err)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
ctx.S.Set("SignedUser", dbUser)
}
ctx.HTML(200, "profile/profile", ctx)
default:
ctx.HTML(200, "profile/profile", ctx)
}
}
示例6: AllUserHandler
func AllUserHandler(ctx *middleware.Context) {
switch ctx.R.Method {
case "POST":
user := new(model.User)
user.SetPageActive(true)
user.SetPageSize(ParseInt(ctx.R.FormValue("iDisplayLength")))
user.SetDisplayStart(ParseInt(ctx.R.FormValue("iDisplayStart")))
columnNum := ctx.R.FormValue("iSortCol_0")
sortColumn := ctx.R.FormValue("mDataProp_" + columnNum)
user.AddSortProperty(sortColumn, ctx.R.FormValue("sSortDir_0"))
users, total, err := user.SearchByPage()
PanicIf(err)
ctx.Set("aaData", users)
ctx.Set("iTotalDisplayRecords", total)
ctx.Set("iTotalRecords", total)
ctx.JSON(200, ctx.Response)
default:
ctx.HTML(200, "user/allUser", ctx)
}
}