Example #1
0
/* 根据话题id判断是否为其管理员 */
func (this *GameController) isManagerById(contro *beego.Controller) (bool, *models.Topic, *models.Game, *models.Member) {
	//实例化话题
	topic := &models.Topic{}
	ok := topic.FindById(contro.GetString("id"))
	if !ok { //不存在此话题
		return false, nil, nil, nil
	}
	//获取游戏信息
	game := &models.Game{}
	ok = game.FindPath(topic.Game)
	if ok { //存在此游戏
		//获取用户信息
		member := &models.Member{}
		if session := contro.GetSession("WOKUID"); session != nil {
			if ok := member.FindOne(session.(string)); ok {
				//如果是游戏管理员
				if member.Id == game.Manager {
					return true, topic, game, member
				} else {
					return false, topic, game, member
				}
			}
		}
	}
	return false, nil, nil, nil
}
Example #2
0
func parseAccount(ctx *beego.Controller, account *models.Account) error {
	email := ctx.GetString("email")
	password := ctx.GetString("password")
	password2 := ctx.GetString("password2")
	name := ctx.GetString("name")
	showemail := ctx.GetString("showemail")

	var err error
	err = nil
	if email == "" {
		err = errors.New("email miss")
		return err
	}

	if password == "" || password != password2 {
		err = errors.New("password")
		return err
	}

	if name == "" {
		err = errors.New("name miss")
		return err
	}

	if showemail != "show" && showemail != "hide" {
		err = errors.New("showemail miss")
		return err
	}

	account.EMail = email
	account.Password = password
	account.DisplayName = name
	account.CreateTime = time.Now()
	account.LastLoginTime = time.Now()
	if showemail == "show" {
		account.ShowEmail = true
	} else {
		account.ShowEmail = false
	}
	account.Level = 0

	return err
}
Example #3
0
/* 判断用户是否是游戏管理员 */
func (this *GameController) isManager(contro *beego.Controller) (bool, *models.Game, *models.Member) {
	//获取游戏信息
	game := &models.Game{}
	ok := game.FindPath(contro.GetString("category"))
	if !ok {
		return false, nil, nil
	}
	//获取用户信息
	member := &models.Member{}
	if session := contro.GetSession("WOKUID"); session != nil {
		if ok := member.FindOne(session.(string)); ok {
			//如果不是这个游戏的管理员则无权限
			if member.Id != game.Manager {
				return false, nil, nil
			} else {
				return true, game, member
			}
		} else {
			return false, nil, nil
		}
	} else {
		return false, nil, nil
	}
}
Example #4
0
/* 后台操作数据表 */
func Restful(this BaseInterface, contro *beego.Controller) {
	ok, data := func() (bool, interface{}) {
		switch contro.GetString("type") {
		case "add": //增
			if err := contro.ParseForm(this); err != nil {
				return false, err.Error()
			}

			//数据验证
			valid := validation.Validation{}
			b, err := valid.Valid(this)
			if err != nil {
				return false, "验证参数解析失败"
			}

			if !b { //验证失败
				for _, err := range valid.Errors {
					return false, err.Key + " " + err.Message
				}
			}

			// 额外解析数组参数
			if _ok, _data := this.BaseFormStrings(contro); !_ok {
				return false, _data
			}

			if err := this.BaseInsert(); err != nil {
				return false, err.Error()
			}

			return true, "" // 插入成功
		case "delete": //删
			if _ok, _data := this.BaseSetId(contro.GetString("_id")); !_ok {
				return false, _data
			}

			err := this.BaseDelete()

			if err != nil {
				return false, err
			}

			return true, nil
		case "update": //改
			//根据id查询对象
			if _ok, _data := this.BaseFind(contro.GetString("_id")); !_ok {
				return false, _data
			}

			//解析请求参数->对象
			if err := contro.ParseForm(this); err != nil {
				return false, err.Error()
			}

			// 额外解析数组参数
			if _ok, _data := this.BaseFormStrings(contro); !_ok {
				return false, _data
			}

			//验证
			valid := validation.Validation{}
			b, err := valid.Valid(this)
			if err != nil {
				return false, "验证参数解析失败"
			}

			if !b { //验证失败
				for _, err := range valid.Errors {
					return false, err.Key + " " + err.Message
				}
			}

			if err := this.BaseUpdate(); err != nil {
				return false, err.Error()
			}
			return true, nil
		case "get": //查
			from, _ := contro.GetInt("from")
			number, _ := contro.GetInt("number")

			if number > 100 {
				return false, "最多查询100条"
			}

			if contro.GetString("like") != "" && contro.GetString("likeKey") != "" { // 模糊搜索
				var result []BaseInterface
				var count int

				if contro.GetString("likeMethod") == "like" {
					result = this.BaseSelectLike(from, number, contro.GetString("sort"), contro.GetString("likeKey"), contro.GetString("like"))
					count = this.BaseLikeCount(contro.GetString("likeKey"), contro.GetString("like"))
				} else if contro.GetString("likeMethod") == "accuracy" {
					result = this.BaseSelectAccuracy(from, number, contro.GetString("sort"), contro.GetString("likeKey"), contro.GetString("like"))
					count = this.BaseAccuracyCount(contro.GetString("likeKey"), contro.GetString("like"))
				}

				return true, map[string]interface{}{
					"lists": result,
					"count": count,
				}
			} else { // 普通查询
				if contro.GetString("filter") != "" {
					filter, _ := contro.GetInt("filter")
					count := this.BaseFilterCount(contro.GetString("filterKey"), filter)
					result := this.BaseFilterSelect(from, number, contro.GetString("sort"), contro.GetString("filterKey"), filter)

					return true, map[string]interface{}{
						"lists": result,
						"count": count,
					}
				} else {
					count := this.BaseCount()
					result := this.BaseSelect(from, number, contro.GetString("sort"))

					return true, map[string]interface{}{
						"lists": result,
						"count": count,
					}
				}
			}
		}
		return true, nil
	}()

	contro.Data["json"] = map[string]interface{}{
		"ok":   ok,
		"data": data,
	}
	contro.ServeJson()
}
Example #5
0
//获取广告内容
func GetAdsDetail(c *beego.Controller) string {
	str := ""
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	tid, _ := strconv.ParseInt(c.GetString("Tid"), 10, 64)
	switch tid {
	case 0: //代码
		script := &models.ScriptAds{}
		script.Content = c.GetString("txtScript")
		if script.Content == "" {
			tip.Message = "代码不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(script)
		str = string(arrstr)
	case 1: //文字
		text := &models.TextAds{}
		text.Txt = c.GetString("txt_Txt")
		text.Link = c.GetString("txt_Txt")
		text.Style = c.GetString("txt_Style")
		if text.Txt == "" {
			tip.Message = "文字内容不能为空!"
			EchoTip(c, tip)
		}
		if text.Link == "" {
			tip.Message = "文字链接不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(text)
		str = string(arrstr)
	case 2: //图片类
		img := &models.ImgAds{}
		img.Img = c.GetString("img_Img")
		img.Alt = c.GetString("img_Alt")
		img.Link = c.GetString("img_Link")
		img.Height, _ = strconv.ParseInt(c.GetString("img_Height"), 10, 64)
		img.Width, _ = strconv.ParseInt(c.GetString("img_Width"), 10, 64)
		if img.Img == "" {
			tip.Message = "图片地址不能为空!"
			EchoTip(c, tip)
		}
		if img.Link == "" {
			tip.Message = "图片链接不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(img)
		str = string(arrstr)
	case 3: //Flash
		flash := &models.FlashAds{}
		flash.Swf = c.GetString("flash_Swf")
		flash.Height, _ = strconv.ParseInt(c.GetString("flash_Height"), 10, 64)
		flash.Width, _ = strconv.ParseInt(c.GetString("flash_Width"), 10, 64)
		if flash.Swf == "" {
			tip.Message = "Flash 地址不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(flash)
		str = string(arrstr)
	case 4: //幻灯片
		sw, _ := strconv.ParseInt(c.GetString("slide_Width"), 10, 64)
		sh, _ := strconv.ParseInt(c.GetString("slide_Height"), 10, 64)
		SImg := c.GetStrings("slide_Img")
		SLink := c.GetStrings("slide_Link")
		SAlt := c.GetStrings("slide_Alt")
		if len(SImg) <= 0 {
			tip.Message = "幻灯片图片不能为空!"
			EchoTip(c, tip)
		}
		if len(SLink) <= 0 {
			tip.Message = "幻灯片图片链接不能为空!"
			EchoTip(c, tip)
		}
		length := len(SImg)
		listImg := []*models.ImgAds{}
		for i := 0; i < length; i++ {
			tmp := models.ImgAds{}
			if SImg[i] != "" && SLink[i] != "" {
				tmp.Img = SImg[i]
				tmp.Link = SLink[i]
				tmp.Alt = SAlt[i]
				tmp.Height = sh
				tmp.Width = sw
				listImg = append(listImg, &tmp)
			}
		}
		if listImg == nil || len(listImg) <= 0 {
			tip.Message = "幻灯片请最少设置一个图片!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(listImg)
		str = string(arrstr)
	}
	return str
}