Exemple #1
0
func admin_banUser(ctx *goku.HttpContext) goku.ActionResulter {
	var err error
	var errs string
	var ok = false
	var userId, status int64

	userId, err = strconv.ParseInt(ctx.Get("id"), 10, 64)
	if err == nil {
		status, err = strconv.ParseInt(ctx.Get("status"), 10, 64)
	}
	if err == nil {
		_, err = models.User_Update(userId, map[string]interface{}{"Status": status})
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
Exemple #2
0
		user := ctx.Data["user"].(*models.User)
		f := createBaseInfoForm()
		f.FillByRequest(ctx.Request)

		errorMsgs := make([]string, 0)
		if f.Valid() {
			m := f.CleanValues()
			// 检查用户名是否已经注册
			userExist := false
			if strings.ToLower(m["name"].(string)) != strings.ToLower(user.Name) {
				userExist = models.User_IsUserExist(m["name"].(string))
			}
			if userExist {
				errorMsgs = append(errorMsgs, "用户名已经被注册,请换一个")
			} else {
				_, err := models.User_Update(user.Id, m)
				if err != nil {
					errorMsgs = append(errorMsgs, golink.ERROR_DATABASE)
					goku.Logger().Errorln(err)
				} else {
					user = models.User_GetById(user.Id)
				}
			}
		} else {
			errs := f.Errors()
			for _, v := range errs {
				errorMsgs = append(errorMsgs, v[0]+": "+v[1])
			}
		}

		if len(errorMsgs) < 1 {