Example #1
0
//新增图片
func (this *Image) Create() {

	//Get方法
	if this.methodGet {
		id, err := this.getParamsInt64(":id")
		if err != nil {
			this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams")))
			return
		}
		this.Data["articleid"] = id
		this.Data["token"] = this.token()
		this.TplNames = this.getTplFileName("create")
		this.Render()
		return
	}
	//Post方法
	//签名错误,返回重复提交错误
	if this.invalidToken() {
		this.renderLoseToken()
		return
	}
	//数据模型
	m := new(models.Images)

	models.Extend(m, this.xm)

	m.Articleid, _ = this.GetInt("articleid")
	m.Title = this.GetString("title")
	m.Url = this.GetString("url")

	if this.GetString("status") == "on" {
		m.Status = 1
	} else {
		m.Status = 0
	}

	files, err := this.upload("file")
	if err == nil {
		m.Path = files[0].Path
		m.Ext = files[0].Ext
		m.Srcfilename = files[0].Name
		m.Size = files[0].Size
	}

	//数据合法性检验
	if data, inv := this.invalidModel(m); inv {
		this.renderJson(data)
		return
	}
	//提交DDL
	var data interface{}
	_, err = images.Add(m)

	if err != nil {
		data = utils.JsonMessage(false, "", err.Error())
	} else {
		data = utils.JsonResult(true, "", files)
	}
	this.renderJson(data)
}
Example #2
0
//新增频道
func (this *Article) Create() {

	//Get方法
	if this.methodGet {
		this.Data["token"] = this.token()
		//所属频道选项
		this.Data["chs"] = channels.GetChannelSelectItems(0 /*, utils.ChNews*/)

		this.TplNames = this.getTplFileName("create")
		this.Render()
		return
	}
	//Post方法
	//签名错误,返回重复提交错误
	if this.invalidToken() {
		this.renderLoseToken()
		return
	}
	//数据模型
	m := new(models.Articles)

	models.Extend(m, this.xm)

	m.Channelid, _ = this.GetInt("channelid")
	m.Title = this.GetString("title")
	m.Subtitle = this.GetString("subtitle")
	m.Intro = this.GetString("intro")
	m.Content = this.GetString("content")
	m.Keywords = this.GetString("keywords")
	m.Description = this.GetString("description")
	m.Author = this.GetString("author")

	if this.GetString("status") == "on" {
		m.Status = 1
	} else {
		m.Status = 0
	}

	if t, err := beego.DateParse(this.GetString("published"), "Y-n-j H:i:s"); err == nil {
		m.Published = utils.Millisecond(t)
	} else {
		m.Published = utils.Millisecond(time.Now())
	}

	//数据合法性检验
	if data, inv := this.invalidModel(m); inv {
		this.renderJson(data)
		return
	}
	//提交DDL
	var data interface{}
	_, err := articles.Add(m)

	if err != nil {
		data = utils.JsonMessage(false, "", err.Error())
	} else {
		data = utils.JsonMessage(true, "", "")
	}
	this.renderJson(data)
}
Example #3
0
//修改账户信息
func (this *Account) Edit() {
	//Get方法
	if this.methodGet {
		this.Data["token"] = this.token()

		id, err := this.getParamsInt64(":id")
		if err != nil {
			this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams")))
			return
		}
		u, err := users.Get(id)

		if err != nil {
			this.errorHandle(utils.JsonMessage(false, "", err.Error()))
			return
		}
		this.Data["user"] = u

		this.TplNames = this.getTplFileName("edit")
		this.Render()
		return
	}
	//Post方法
	//签名错误,返回重复提交错误
	if this.invalidToken() {
		this.renderLoseToken()
		return
	}
	//数据模型
	u := new(models.Users)

	models.Extend(u, this.xm)

	u.Id, _ = this.GetInt("id")
	u.Loginname = this.GetString("loginname")
	u.Relname = this.GetString("relname")

	//数据合法性检验
	// valid := validation.Validation
	// valid.Required(u.Loginname, "loginname")
	// valid.Required(u.Relname, "relname")

	if data, inv := this.invalidModel(u, "Loginname", "Relname"); inv {
		this.renderJson(data)
		return
	}
	//提交DDL
	var data interface{}
	_, err := users.Update(u)

	if err != nil {
		data = utils.JsonMessage(false, "", err.Error())
	} else {
		data = utils.JsonMessage(true, "", "")
	}
	this.renderJson(data)
}
Example #4
0
//新增频道
func (this *Channel) Create() {
	//Get方法
	if this.methodGet {
		this.Data["token"] = this.token()
		//所属频道选项
		this.Data["chs"] = channels.GetChannelSelectItems(0, utils.ChNavigation)
		//频道类型
		this.Data["types"] = channels.GetTypeSelectItems(0)

		this.TplNames = this.getTplFileName("create")
		this.Render()
		return
	}
	//Post方法
	//签名错误,返回重复提交错误
	if this.invalidToken() {
		this.renderLoseToken()
		return
	}
	//数据模型
	m := new(models.Channels)

	models.Extend(m, this.xm)

	m.Pid, _ = this.GetInt("pid")
	m.Name = this.GetString("name")
	m.Enname = this.GetString("enname")
	t, _ := this.GetInt("children")
	m.Children = int(t)
	t, _ = this.GetInt("type")
	m.Type = int8(t)

	if this.GetString("status") == "on" {
		m.Status = 1
	} else {
		m.Status = 0
	}

	//数据合法性检验
	if data, inv := this.invalidModel(m); inv {
		this.renderJson(data)
		return
	}
	//提交DDL
	var data interface{}
	_, err := channels.Add(m)

	if err != nil {
		data = utils.JsonMessage(false, "", err.Error())
	} else {
		data = utils.JsonMessage(true, "", "")
	}
	this.renderJson(data)
}
Example #5
0
//新增账户
func (this *Account) Create() {
	//Get方法
	if this.methodGet {
		this.Data["token"] = this.token()
		this.Data["password"] = beego.AppConfig.String("DefaultPassword")
		this.TplNames = this.getTplFileName("create")
		this.Render()
		return
	}
	//Post方法
	//签名错误,返回重复提交错误
	if this.invalidToken() {
		this.renderLoseToken()
		return
	}
	//数据模型
	u := new(models.Users)

	models.Extend(u, this.xm)

	u.Loginname = this.GetString("loginname")
	u.Password = this.GetString("password")
	u.Relname = this.GetString("relname")
	r, _ := this.GetInt("role")
	u.Role = int8(r)

	//数据合法性检验
	if data, inv := this.invalidModel(u); inv {
		this.renderJson(data)
		return
	}
	//提交DDL
	var data interface{}
	_, err := users.Add(u)

	if err != nil {
		data = utils.JsonMessage(false, "", err.Error())
	} else {
		data = utils.JsonMessage(true, "", "")
	}
	this.renderJson(data)
}