Ejemplo n.º 1
0
/*
文章显示,每浏览一次浏览量增加1
*/
func (this *IndexController) New() {
	uid := this.GetSession("sessionuid")

	/*
		输出文章信息
	*/
	article1, _ := models.Articleread(uid, 0)
	this.Data["article1"] = article1

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand

	articleid1 := this.Input().Get("articleid")
	articleid, _ := strconv.Atoi(articleid1)
	// this.Data["test"] = articleid
	// this.TplNames = "article/testarticle.html"
	// return
	//浏览量加1
	err := models.Articleviewsadd(articleid)
	if err != nil {
		return
	}
	article, _ := models.Articlefindwithaid(articleid1)
	userid := this.GetSession("sessionuid")
	var userinfo *models.User
	userinfo, err = models.Userinfowithuid(userid)
	if err != nil {
		return
	}
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	this.Data["userinfo"] = userinfo
	this.Data["article"] = article
	this.TplNames = "blog/news.html"
}
Ejemplo n.º 2
0
/*
分类显示
*/
func (this *IndexController) Category() {
	//获取分类
	category := this.GetString("tags")
	//输出文章,显示在左侧
	article1, err := models.Articlecategory(category)
	if err != nil {
		return
	}
	this.Data["article1"] = article1
	this.Data["tags"] = category

	this.Data["status"] = false
	/*
		输出文章信息,用于右侧显示
	*/
	uid := this.GetSession("sessionuid")
	article, _ := models.Articleread(uid, 0)
	this.Data["article"] = article

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand

	userinfo, err := models.Userinfowithuid(uid)
	if err != nil {
		return
	}
	this.Data["userinfo"] = userinfo
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	this.TplNames = "blog/learn.html"

}
Ejemplo n.º 3
0
func (this *IndexController) Riji() {
	uid := this.GetSession("sessionuid")
	/*
		输出文章信息
	*/
	article, _ := models.Articleread(uid, 0)
	this.Data["article"] = article

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand

	//获取用户信息
	userinfo, _ := models.Userinfowithuid(uid)
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	//获取日记信息
	diary, _, count := models.Dirayfindwithuserid(uid)
	if count == 0 {
		this.Data["nodiary"] = true
	} else {
		this.Data["nodiary"] = false
	}
	this.Data["diary"] = diary
	this.Data["userinfo"] = userinfo
	this.TplNames = "blog/riji.html"
}
Ejemplo n.º 4
0
/*
学无止境
*/
func (this *IndexController) Xuewuzhijing() {
	/*
		输出文章信息
	*/
	uid := this.GetSession("sessionuid")
	article, _ := models.Articleread(uid, 0)
	this.Data["article"] = article

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand
	this.Data["status"] = true
	userinfo, err := models.Userinfowithuid(uid)
	if err != nil {
		return
	}
	this.Data["userinfo"] = userinfo
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	this.TplNames = "blog/learn.html"
}
Ejemplo n.º 5
0
func (this *IndexController) Get() {
	//获取cookie和session值
	cookieaccount := this.Ctx.GetCookie("cookieaccount")
	uid := this.GetSession("sessionuid")
	/*
		如果存在cookie,判断session是否存在,不存在就创建session
	*/
	if len(cookieaccount) > 0 {
		if uid == nil {
			//获取用户账号account
			account := DecodeCookie(cookieaccount)
			//获取用户uid
			userinfo, _ := models.Userinfo(account)
			uid = userinfo.Id
			this.SetSession("sessionuid", uid)
		}
		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		this.TplNames = "blog/index.html"
		return
	} else if uid != nil {

		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		/*
			随机文章信息
		*/
		articlerand, _ := models.Articlerand()
		this.Data["articlerand"] = articlerand

		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		this.TplNames = "blog/index.html"
		return
	} else {
		this.Redirect("/", 301)
	}

}
Ejemplo n.º 6
0
func (this *IndexController) About() {
	//获取user表中的introduce字段值
	uid := this.GetSession("sessionuid")
	cookieaccount := this.Ctx.GetCookie("cookieaccount")
	if len(cookieaccount) > 0 {
		if uid == nil {
			//获取用户账号account
			account := DecodeCookie(cookieaccount)
			//获取用户uid
			userinfo, _ := models.Userinfo(account)
			uid = userinfo.Id
			this.SetSession("sessionuid", uid)
		}

		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		/*
			随机文章信息
		*/
		articlerand, _ := models.Articlerand()
		this.Data["articlerand"] = articlerand

		//读取数据
		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		if userinfo.Introduce != "" {
			this.Data["introduce"] = userinfo.Introduce
			this.TplNames = "blog/about.html"
		} else {
			this.Data["introduce"] = "暂无内容!"
			this.TplNames = "blog/about.html"
		}
	} else if uid != nil {

		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		/*
			随机文章信息
		*/
		articlerand, _ := models.Articlerand()
		this.Data["articlerand"] = articlerand

		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		if userinfo.Introduce != "" {
			this.Data["introduce"] = userinfo.Introduce
			this.TplNames = "blog/about.html"
		} else {
			this.Data["introduce"] = "暂无内容!"
			this.TplNames = "blog/about.html"
		}
	} else {
		this.Redirect("/", 301)
	}

}