Example #1
0
func (c *WptController) AdminUpInfo() {
	bool, username := chackAccount(c.Ctx)
	if bool {
		c.Data["isUser"] = bool
		c.Data["User"] = username
	} else {
		c.Redirect("/admin", 302)
		return
	}
	c.Data["isUser"] = bool
	c.Data["User"] = username
	// beego.Debug("c.Input() :", c.Input())
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminUpInfo Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminUpInfo Post")
		id := c.Input().Get("id")
		title := c.Input().Get("title")
		info := c.Input().Get("info")
		wid := c.Input().Get("wid")
		wrange := c.Input().Get("wrange")
		if len(title) != 0 && len(info) != 0 && len(wid) != 0 && len(wrange) != 0 {
			err := models.UpWptInfo(id, title, info, wid, wrange)
			if err != nil {
				beego.Error(err)
			}
			url := "/wpt/adminhome"
			c.Redirect(url, 302)
			return
		}
	}

	id := c.Input().Get("id")
	obj, err := models.GetOneWpt(id)
	if err != nil {
		beego.Error(err)
	}
	c.Data["Obj"] = obj
	c.TplName = "wptadminupinfo.html"
}
Example #2
0
/**
修改图片
*/
func (c *WptController) AdminUpImg() {
	bool, username := chackAccount(c.Ctx)
	if bool {
		c.Data["isUser"] = bool
		c.Data["User"] = username
	} else {
		c.Redirect("/admin", 302)
		return
	}
	c.Data["isUser"] = bool
	c.Data["User"] = username

	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminUpImg Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminUpImg Post")

		id := c.Input().Get("id")
		originalqrcode := c.Input().Get("originalqrcode")
		qrcode_name := originalqrcode
		if len(id) != 0 {
			// 二维码
			_, fh, err := c.GetFile("image1")
			// beego.Debug("上传图片:", fh)
			if err != nil {
				beego.Error(err)
			}
			var attachment string
			if fh != nil {
				// 保存附件
				attachment = fh.Filename
				t := time.Now().Unix()
				str2 := fmt.Sprintf("%d", t)
				s := []string{attachment, str2}
				h := md5.New()
				h.Write([]byte(strings.Join(s, ""))) // 需要加密的字符串
				qrcode_name = hex.EncodeToString(h.Sum(nil))
				beego.Debug("qrcode_name:", qrcode_name) // 输出加密结果
				err = c.SaveToFile("image1", path.Join("imagehosting", qrcode_name))
				if err != nil {
					beego.Error(err)
					qrcode_name = originalqrcode
				}
			}

			beego.Debug("上传前图片originalqrcode", originalqrcode, "上传后图片qrcode_name", qrcode_name)
			if qrcode_name == originalqrcode {
				beego.Debug("未修改图片")
				c.Redirect("/wpt/adminhome", 302)
				return
			}

			if len(qrcode_name) != 0 {
				err := models.UpWptImg(id, qrcode_name)
				if err != nil {
					beego.Error(err)
				} else {
					c.Redirect("/wpt/adminhome", 302)
					return
				}
			}
		}
	}
	id := c.Input().Get("id")
	obj, err := models.GetOneWpt(id)
	if err != nil {
		beego.Error(err)
	}
	c.Data["Obj"] = obj
	c.TplName = "wptadminupimg.html"
}