Exemplo n.º 1
0
/*
主页面输出
*/
func (this *AdminController) Main() {
	/*
		获取session和cookie,管理员和用户的session和cookie都要获取,并进行分类处理输出对应模板
	*/
	//普通用户
	sessionuid := this.GetSession("sessionuid")
	cookieaccount := this.Ctx.GetCookie("cookieaccount")
	//管理员
	sessionaid := this.GetSession("sessionaid")
	cookieadmin := this.Ctx.GetCookie("cookieadmin")

	//判断用户类型
	if len(cookieadmin) > 0 {
		//管理员
		this.Data["hostname"], _ = os.Hostname()
		this.Data["goversion"] = runtime.Version()
		this.Data["os"] = runtime.GOOS
		this.Data["cpunum"] = runtime.NumCPU()
		this.Data["arch"] = runtime.GOARCH

		this.Data["admin"] = true
		this.TplNames = "layout.html"
		return
	} else if sessionaid != nil {
		//管理员
		this.Data["hostname"], _ = os.Hostname()
		this.Data["goversion"] = runtime.Version()
		this.Data["os"] = runtime.GOOS
		this.Data["cpunum"] = runtime.NumCPU()
		this.Data["arch"] = runtime.GOARCH

		//输出网站内容统计信息
		article0, _ := models.Articletypesumwithstatus(0)
		article1, _ := models.Articletypesumwithstatus(1)
		article2, _ := models.Articletypesumwithstatus(2)

		diary0, _ := models.Diarytypesumwithstatic(0)
		diary1, _ := models.Diarytypesumwithstatic(1)
		diary2, _ := models.Diarytypesumwithstatic(2)

		shuo, _ := models.Shuosumwithall()

		picture0, _ := models.Imagereadcountwithstatic(0)
		picture1, _ := models.Imagereadcountwithstatic(1)

		usersum, _ := models.Usersum()

		this.Data["article0"] = article0
		this.Data["article1"] = article1
		this.Data["article2"] = article2

		this.Data["diary0"] = diary0
		this.Data["diary1"] = diary1
		this.Data["diary2"] = diary2

		this.Data["shuo"] = shuo

		this.Data["picture0"] = picture0
		this.Data["picture1"] = picture1

		this.Data["usersum"] = usersum

		this.Data["admin"] = true
		this.TplNames = "layout.html"
	} else if len(cookieaccount) > 0 {
		//普通用户
		account := DecodeCookie(cookieaccount)
		userinfo, _ := models.Userinfo(account)

		//输出文章数量,日记数量,碎言碎语数量,照片数量
		userid := userinfo.Id
		article0, _ := models.Articletypesum(userid, 0)
		article1, _ := models.Articletypesum(userid, 1)
		article2, _ := models.Articletypesum(userid, 2)

		diary0, _ := models.Diarytypesum(userid, 0)
		diary1, _ := models.Diarytypesum(userid, 1)
		diary2, _ := models.Diarytypesum(userid, 2)

		shuo, _ := models.Shuosum(userid)

		picture0, _ := models.Imagereadcount(userid, 0)
		picture1, _ := models.Imagereadcount(userid, 1)

		this.Data["article0"] = article0
		this.Data["article1"] = article1
		this.Data["article2"] = article2

		this.Data["diary0"] = diary0
		this.Data["diary1"] = diary1
		this.Data["diary2"] = diary2

		this.Data["shuo"] = shuo

		this.Data["picture0"] = picture0
		this.Data["picture1"] = picture1
		this.Data["admin"] = false
		this.TplNames = "layout.html"
	} else if sessionuid != nil {
		//普通用户,读取用户uid
		userinfo, _ := models.Userinfowithuid(sessionuid)

		//输出文章数量,日记数量,碎言碎语数量,照片数量
		userid := userinfo.Id
		article0, _ := models.Articletypesum(userid, 0)
		article1, _ := models.Articletypesum(userid, 1)
		article2, _ := models.Articletypesum(userid, 2)

		diary0, _ := models.Diarytypesum(userid, 0)
		diary1, _ := models.Diarytypesum(userid, 1)
		diary2, _ := models.Diarytypesum(userid, 2)

		shuo, _ := models.Shuosum(userid)

		picture0, _ := models.Imagereadcount(userid, 0)
		picture1, _ := models.Imagereadcount(userid, 1)

		this.Data["article0"] = article0
		this.Data["article1"] = article1
		this.Data["article2"] = article2

		this.Data["diary0"] = diary0
		this.Data["diary1"] = diary1
		this.Data["diary2"] = diary2

		this.Data["shuo"] = shuo

		this.Data["picture0"] = picture0
		this.Data["picture1"] = picture1

		this.Data["admin"] = false
		this.TplNames = "layout.html"
	} else {
		//返回登录界面
		this.Redirect("/", 301)
	}
}
Exemplo n.º 2
0
/*
日记列表页面
*/
func (this *DiaryController) Diarylist() {
	keyword := this.GetString("keyword")
	searchtype := this.GetString("searchtype")
	uid := this.GetSession("sessionuid")
	//判断点击状态,分别是已发布,草稿箱,回收站
	var status int = 0
	status, _ = this.GetInt("status")
	diarysum1, _ := models.Diarytypesum(uid, 0)
	diarysum2, _ := models.Diarytypesum(uid, 1)
	diarysum3, _ := models.Diarytypesum(uid, 2)
	//用于显示关键字类型
	this.Data["searchtype"] = "false"
	//判断状态
	if status == 0 {
		statusid := 0
		var err error
		var diarylist []*models.Diary
		//判断是否关键字搜索,并分类处理
		if len(keyword) > 0 {
			if searchtype == "title" {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 0)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
			} else if searchtype == "author" {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 1)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "author"
			} else {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 2)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "tag"

			}
		} else {
			diarylist, err = models.Diaryread(uid, statusid)
		}
		if err != nil {
			return
		}

		this.TplNames = "user/list.html"
		this.Data["diary"] = diarylist
		this.Data["yifabu"] = true
		this.Data["diarysum1"] = diarysum1
		this.Data["diarysum2"] = diarysum2
		this.Data["diarysum3"] = diarysum3
		return
	} else if status == 1 {
		//草稿箱
		statusid := 1
		var err error
		var diarylist []*models.Diary
		//判断是否关键字搜索,并分类处理
		if len(keyword) > 0 {
			if searchtype == "title" {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 0)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
			} else if searchtype == "author" {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 1)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "author"
			} else {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 2)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "tag"
			}
		} else {
			diarylist, err = models.Diaryread(uid, statusid)
		}
		if err != nil {
			return
		}
		this.TplNames = "user/list.html"
		this.Data["diary"] = diarylist
		this.Data["caogaoxiang"] = true
		this.Data["diarysum1"] = diarysum1
		this.Data["diarysum2"] = diarysum2
		this.Data["diarysum3"] = diarysum3
		return
	} else {
		statusid := 2
		var err error
		var diarylist []*models.Diary
		//判断是否关键字搜索,并分类处理
		if len(keyword) > 0 {
			if searchtype == "title" {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 0)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
			} else if searchtype == "author" {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 1)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "author"
			} else {
				diarylist, err = models.Diaryreadwithkeyword(uid, statusid, keyword, 2)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "tag"
			}
		} else {
			diarylist, err = models.Diaryread(uid, statusid)
		}
		if err != nil {
			return
		}
		this.TplNames = "user/list.html"
		this.Data["diary"] = diarylist
		this.Data["huishouzhan"] = true
		this.Data["diarysum1"] = diarysum1
		this.Data["diarysum2"] = diarysum2
		this.Data["diarysum3"] = diarysum3
		return
	}

}