Example #1
0
//检测登陆
func CheckLogin(c *revel.Controller) revel.Result {

	//登陆页面,CSS, JS, Ajax, 验证码页面 都不进行登陆验证
	if c.Name == "User" && c.MethodName == "Login" || c.Name == "Ajax" || c.Name == "Static" || c.Name == "Captcha" || c.Name == "Kindeditor" {

		if LANG, ok := c.Session["Lang"]; ok {
			//设置语言
			c.RenderArgs["currentLocale"] = LANG
		} else {
			//设置默认语言
			c.RenderArgs["currentLocale"] = "zh"
		}

		return nil
	} else {

		UserID := utils.GetSession("UserID", c.Session)

		if len(UserID) > 0 {
			UserID, err := strconv.ParseInt(UserID, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
				return c.Redirect("/Login/")
			}

			admin := new(models.Admin)
			admin_info := admin.GetById(UserID)
			if admin_info.Id <= 0 {
				return c.Redirect("/Login/")
			}

			//控制器
			c.RenderArgs["Controller"] = c.Name
			//动作
			c.RenderArgs["action"] = c.Action
			//模型
			c.RenderArgs["Model"] = c.MethodName

			//登陆信息
			c.RenderArgs["admin_info"] = admin_info

			//设置语言
			c.RenderArgs["currentLocale"] = admin_info.Lang
		} else {

			//控制器
			c.RenderArgs["Controller"] = c.Name
			//动作
			c.RenderArgs["action"] = c.Action
			//模型
			c.RenderArgs["Model"] = c.MethodName

			return c.Redirect("/Login/")
		}
	}

	return nil
}
Example #2
0
//删除公告
func (c Announce) Delete(announce *models.Announce) revel.Result {

	var id string = c.Params.Get("id")

	data := make(map[string]string)

	if len(id) > 0 {
		Id, err := strconv.ParseInt(id, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		if announce.DelByID(Id) {

			//******************************************
			//管理员日志
			UserID := utils.GetSession("UserID", c.Session)
			if len(UserID) > 0 {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				logs := new(models.Logs)
				desc := "删除公告|^|ID:" + id
				logs.Save(admin_info, c.Controller, desc)
			}
			//*****************************************

			data["status"] = "1"
			data["message"] = "删除成功!"
			return c.RenderJson(data)
		} else {
			data["status"] = "0"
			data["message"] = "删除失败!"
			return c.RenderJson(data)
		}
	} else {
		data["status"] = "0"
		data["message"] = "删除失败!"
		return c.RenderJson(data)
	}
}
Example #3
0
func (c Category) Index(category *models.Category) revel.Result {
	title := "栏目管理--GoCMS管理系统"

	UserID := utils.GetSession("UserID", c.Session)

	if len(UserID) > 0 {

		UserID, err := strconv.ParseInt(UserID, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}
		admin := new(models.Admin)
		admin_info := admin.GetById(UserID)

		categorys := category.GetCateGoryHtml(admin_info)

		c.Render(title, categorys)
	} else {
		c.Render(title)
	}

	return c.RenderTemplate("Content/Category/Index.html")
}
Example #4
0
//首页
func (c App) Index(admin *models.Admin) revel.Result {
	title := "首页--GoCMS管理系统"

	UserID := utils.GetSession("UserID", c.Session)

	if len(UserID) > 0 {
		UserID, err := strconv.ParseInt(UserID, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		admin_info := admin.GetById(UserID)
		if admin_info.Id <= 0 {
			return c.Redirect("/User/Login")
		}

		//导航菜单
		menu := new(models.Menu)
		c.RenderArgs["menus"] = menu.GetAdminMenu(0, admin_info)

		//登陆用户信息
		c.RenderArgs["admin_info"] = admin_info

		//是否锁屏
		if c.Session["lock_screen"] == "" || c.Session["lock_screen"] == "0" {
			c.RenderArgs["lock_screen"] = "0"
		} else {
			c.RenderArgs["lock_screen"] = "1"
		}
	} else {
		return c.Redirect("/User/Login/")
	}

	c.Render(title)
	return c.RenderTemplate("App/Index.html")
}
Example #5
0
func (c App) Main(admin *models.Admin) revel.Result {

	title := "首页--GoCMS管理系统"

	UserID := utils.GetSession("UserID", c.Session)

	if len(UserID) > 0 {
		UserID, err := strconv.ParseInt(UserID, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		admin_info := admin.GetById(UserID)

		//判断是否是系统的分隔符
		separator := "/"
		if os.IsPathSeparator('\\') {
			separator = "\\"
		} else {
			separator = "/"
		}

		config_file := (revel.BasePath + "/conf/config.conf")
		config_file = strings.Replace(config_file, "/", separator, -1)
		config_conf, _ := config.ReadDefault(config_file)

		system_info := make(map[string]string)

		//版本
		version, _ := config_conf.String("website", "website.version")
		system_info["version"] = version

		//前台网站地址
		sitedomain, _ := config_conf.String("website", "website.sitedomain")
		system_info["sitedomain"] = sitedomain

		//操作系统
		system_info["os"] = strings.ToUpper(runtime.GOOS + " " + runtime.GOARCH)

		//Go版本
		system_info["go_varsion"] = strings.ToUpper(runtime.Version())

		//Revel版本
		system_info["revel_varsion"] = strings.ToUpper("Revel 0.11")

		//MySQL版本
		system_info["mysql_varsion"] = admin.GetMysqlVer()

		//服务器监控
		memory_info, _ := gopsutil.VirtualMemory()
		system_info["main_server_total_memory"] = utils.FileSize(int(memory_info.Total))
		system_info["main_server_free_memory"] = utils.FileSize(int(memory_info.Free))
		system_info["main_server_available_memory"] = utils.FileSize(int(memory_info.Available))
		system_info["main_server_UsedPercent_memory"] = fmt.Sprintf("%10.2f%%", memory_info.UsedPercent)

		host, _ := gopsutil.HostInfo()
		system_info["main_server_Hostname"] = host.Hostname
		system_info["main_server_OS"] = host.OS
		system_info["main_server_Platform"] = host.Platform
		system_info["main_server_PlatformVersion"] = host.PlatformVersion
		system_info["main_server_PlatformFamily"] = host.PlatformFamily

		//快捷面板
		admin_panel := new(models.Admin_Panel)
		panel_list := admin_panel.GetPanelList(admin_info)

		c.Render(title, admin_info, system_info, panel_list)
	} else {
		c.Render(title)
	}

	return c.RenderTemplate("App/Main.html")
}
Example #6
0
//添加焦点图
func (c Focus) Add(focus *models.Focus) revel.Result {

	if c.Request.Method == "GET" {

		title := "添加焦点图--GoCMS管理系统"

		FocusCate := new(models.FocusCate)
		Cate_list := FocusCate.GetCateList()

		c.Render(title, Cate_list)
		return c.RenderTemplate("Content/Focus/Add.html")

	} else {

		var cid string = c.Params.Get("cid")
		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			focus.Cid = Cid

			focusCate := new(models.FocusCate)
			focusCate_info := focusCate.GetById(Cid)

			if focusCate_info.Id <= 0 {
				c.Flash.Error("焦点图分类错误!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//****************************************
			//图片

			//判断是否是系统的分隔符
			separator := "/"
			if os.IsPathSeparator('\\') {
				separator = "\\"
			} else {
				separator = "/"
			}

			//接收上传文件
			imgFile, header, err := c.Request.FormFile("img")
			if err != nil {
				c.Flash.Error("图片上传错误!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}
			defer imgFile.Close()

			//读取文件数据
			fileData, _ := ioutil.ReadAll(imgFile)

			if len(fileData) >= 1024*1024*2 {
				c.Flash.Error("你上传大小为" + utils.FileSize(len(fileData)) + ",文件应小于2M!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			basepath, _ := filepath.Abs("")
			config_file := (revel.BasePath + "/conf/config.conf")
			config_file = strings.Replace(config_file, "/", separator, -1)
			config_conf, _ := config.ReadDefault(config_file)

			//上传文件目录
			upload_dir, _ := config_conf.String("upload", "upload.dir")
			//允许上传的后缀名
			titlesuffix, _ := config_conf.String("upload", "upload.titlesuffix")

			//文件类型检测
			if !strings.Contains(titlesuffix, path.Ext(header.Filename)) {
				c.Flash.Error("文件只支持图片!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//前台网站调用目录
			web_save_path := fmt.Sprintf("/%s/focus/%s", upload_dir, time.Now().Format("2006/01/02/"))

			//文件保存目录
			save_path := fmt.Sprintf("%s/www/%s/focus/%s", basepath, upload_dir, time.Now().Format("2006/01/02/"))
			//字符串替换 /替换为系统分隔符
			save_path = strings.Replace(save_path, "/", separator, -1)

			//创建目录
			err = os.MkdirAll(save_path, os.ModePerm)
			if err != nil {
				c.Flash.Error("创建目录失败!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//新文件名
			rand.Seed(time.Now().UnixNano())
			rand_num := rand.Intn(99999)

			//原图
			new_file_name := time.Now().Format("20060102150404") + strconv.Itoa(rand_num) + path.Ext(header.Filename)

			//保存文件
			old_img := save_path + new_file_name

			err = ioutil.WriteFile(old_img, fileData, os.ModePerm)
			if err != nil {
				revel.WARN.Println(err)
				c.Flash.Error("保存图片失败!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			thumb_name := time.Now().Format("20060102150404") + strconv.Itoa(rand_num) + "_thumb" + path.Ext(header.Filename)

			//内容显示图片
			web_url_img := web_save_path + thumb_name

			//400宽度图片生成
			thumb := save_path + thumb_name
			thumb_width := strconv.Itoa(int(focusCate_info.Width)) + "x" + strconv.Itoa(int(focusCate_info.Height))
			utils.Resize(old_img, thumb, thumb_width, "center", "white")

			focus.Img = web_url_img

			//***************************************

		} else {
			c.Flash.Error("请选择所属分类!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		UserID := utils.GetSession("UserID", c.Session)

		if len(UserID) > 0 {
			UserID, err := strconv.ParseInt(UserID, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			focus.Aid = UserID
		}

		var title string = c.Params.Get("title")
		if len(title) > 0 {
			focus.Title = title
		} else {
			c.Flash.Error("请输入标题!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		var url string = c.Params.Get("url")
		if len(url) > 0 {
			focus.Url = url
		} else {
			c.Flash.Error("请输入地址!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			focus.Content = content
		} else {
			c.Flash.Error("请输入摘要!")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}

		var order string = c.Params.Get("order")
		if len(order) > 0 {

			Order, err := strconv.ParseInt(order, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			focus.Order = Order
		} else {
			focus.Order = 0
		}

		var status string = c.Params.Get("status")
		Status, err := strconv.ParseInt(status, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		focus.Status = Status

		if focus.Save() {
			c.Flash.Success("添加焦点图成功")
			c.Flash.Out["url"] = "/Focus/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加焦点图失败")
			c.Flash.Out["url"] = "/Focus/Add/"
			return c.Redirect("/Message/")
		}
	}
}
Example #7
0
//单页面 添加内容
func (c Content) AddContent(article *models.Article) revel.Result {
	if c.Request.Method == "GET" {
		title := "内容--GoCMS添加内容"

		var cid string = c.Params.Get("cid")

		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			//栏目信息
			category := new(models.Category)
			category_info := category.GetById(Cid)

			//内容
			article_info := article.GetByCid(Cid)

			c.Render(title, cid, category_info, article_info)
			return c.RenderTemplate("Content/Manage/AddContent.html")
		} else {
			c.Render(title, cid)
			return c.RenderTemplate("Content/Manage/AddContent.html")
		}
	} else {

		var cid string = c.Params.Get("cid")

		if len(cid) < 0 {
			c.Flash.Error("请选择栏目!")
			c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
			return c.Redirect("/Message/")
		}

		UserID := utils.GetSession("UserID", c.Session)

		if len(UserID) > 0 {
			UserID, err := strconv.ParseInt(UserID, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			article.Aid = UserID
		}

		var title string = c.Params.Get("title")
		if len(title) > 0 {
			article.Title = title
		} else {
			c.Flash.Error("请输入标题!")
			c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
			return c.Redirect("/Message/")
		}

		var style_color string = c.Params.Get("style_color")
		article.Color = style_color
		var style_font_weight string = c.Params.Get("style_font_weight")
		article.Font = style_font_weight

		var keywords string = c.Params.Get("keywords")
		if len(keywords) > 0 {
			article.Keywords = keywords
		} else {
			article.Keywords = ""
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			article.Content = content
		} else {
			c.Flash.Error("请输入内容!")
			c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
			return c.Redirect("/Message/")
		}

		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Cid = Cid

			//内容
			article_info := article.GetByCid(Cid)

			if article_info.Id > 0 {
				if article.Edit(article_info.Id) {
					c.Flash.Success("编辑内容成功!")
					c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
					return c.Redirect("/Message/")
				} else {
					c.Flash.Success("编辑内容成功!")
					c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
					return c.Redirect("/Message/")
				}
			} else {
				if article.Save() {
					c.Flash.Success("添加内容成功!")
					c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
					return c.Redirect("/Message/")
				} else {
					c.Flash.Error("添加内容失败")
					c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
					return c.Redirect("/Message/")
				}
			}
		} else {
			c.Flash.Error("请选择栏目!")
			c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
			return c.Redirect("/Message/")
		}
	}
}
Example #8
0
//添加公告
func (c Announce) Add(announce *models.Announce) revel.Result {

	if c.Request.Method == "GET" {
		title := "添加公告--GoCMS管理系统"

		c.Render(title)
		return c.RenderTemplate("Module/Announce/Add.html")
	} else {
		var title string = c.Params.Get("title")
		if len(title) > 0 {
			announce.Title = title
		} else {
			c.Flash.Error("请输入公告标题!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var starttime string = c.Params.Get("starttime")
		if len(starttime) > 0 {
			announce.Starttime = starttime
		} else {
			c.Flash.Error("请输入起始日期!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var endtime string = c.Params.Get("endtime")
		if len(endtime) > 0 {
			announce.Endtime = endtime
		} else {
			c.Flash.Error("请输入截止日期!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			announce.Content = content
		} else {
			c.Flash.Error("请输入公告内容!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var status string = c.Params.Get("status")
		if len(status) > 0 {
			Status, err := strconv.ParseInt(status, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			announce.Status = Status
		} else {
			c.Flash.Error("请选择是否启用!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		if announce.Save() {

			//******************************************
			//管理员日志
			UserID := utils.GetSession("UserID", c.Session)

			if len(UserID) > 0 {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				logs := new(models.Logs)
				desc := "添加公告:" + title
				logs.Save(admin_info, c.Controller, desc)
			}
			//*****************************************

			c.Flash.Success("添加公告成功!")
			c.Flash.Out["url"] = "/Announce/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加公告失败!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}
	}
}