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) }
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) }
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) } }
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: "******" roleId set to ", roleId) ctx.JSON(200, ctx.Response) }
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) } }
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) } }