Exemple #1
0
//解锁
func (c *Ajax) ScreenUnlock(admin *models.Admin) revel.Result {
	var lock_password string = c.Params.Get("lock_password")

	if lock_password == "" || len(lock_password) <= 0 {
		return c.RenderText("2")
	}

	if UserID, ok := c.Session["UserID"]; ok {

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

		admin_info := admin.GetById(UserID)

		if admin_info.Password != utils.Md5(lock_password) {
			return c.RenderText("3")
		} else {
			c.Session["lock_screen"] = "0"
			return c.RenderText("1")
		}
	} else {
		return c.RenderText("4")
	}
}
Exemple #2
0
//退出登陆
func (c *User) Logout(admin *models.Admin) revel.Result {

	if UserID, ok := c.Session["UserID"]; ok {

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

		admin_info := admin.GetById(UserID)

		//******************************************
		//管理员日志
		logs := new(models.Logs)
		desc := "登陆用户名:" + admin_info.Username + "|^|退出系统!|^|登陆ID:" + fmt.Sprintf("%d", admin_info.Id)
		logs.Save(admin_info, c.Controller, desc)
		//*****************************************

		for k := range c.Session {
			delete(c.Session, k)
		}
	}

	c.Flash.Success("安全退出")
	c.Flash.Out["url"] = "/User/Login/"
	return c.Redirect("/Message/")
}
Exemple #3
0
//当前位置
func (c *Ajax) Pos(menu *models.Menu) revel.Result {
	var id string = c.Params.Get("id")

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

	if UserID, ok := c.Session["UserID"]; ok {

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

		//获取登陆用户信息
		admin := new(models.Admin)
		admin_info := admin.GetById(UserID)

		menu_str := menu.GetPos(Id, admin_info)
		return c.RenderText(menu_str)
	} else {
		return c.RenderText("")
	}
}
Exemple #4
0
//删除管理员
func (c Admin) Delete(admin *models.Admin) 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 admin.DelByID(Id) {
			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)
	}
}
Exemple #5
0
//检测登陆
func CheckLogin(c *Init) revel.Result {
	if c.Name == "User" && c.MethodName == "Login" {
		return c.Render()
	} else {
		if UserID, ok := c.Session["UserID"]; ok {
			UserID, err := strconv.ParseInt(UserID, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
				return c.Redirect(routes.User.Login())
			}

			admin := new(models.Admin)
			admin_info := admin.GetById(UserID)
			if admin_info.Id <= 0 {
				c.Flash.Error("请先登录")
				return c.Redirect(routes.User.Login())
			}
		} else {
			c.Flash.Error("请先登录")
			return c.Redirect(routes.User.Login())
		}
	}

	return nil
}
Exemple #6
0
//获取快捷方式
func (c *Ajax) GetPanel(admin_panel *models.Admin_Panel) revel.Result {
	if UserID, ok := c.Session["UserID"]; ok {

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

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

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

		//获取登陆用户信息
		admin := new(models.Admin)
		admin_info := admin.GetById(UserID)

		panel_info := admin_panel.GetByMid(Mid, admin_info)

		if panel_info.Id > 0 {
			Html := "<span><a target='right' href='/" + panel_info.Url + "/'>" + panel_info.Name + "</a><a class='panel-delete' href='javascript:delete_panel();'></a></span>"
			return c.RenderText(Html)
		} else {
			Html := ""
			return c.RenderText(Html)
		}

	} else {
		Html := "<span><a href='javascript:;'>未登陆</a></span>"
		return c.RenderText(Html)
	}
}
Exemple #7
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
}
Exemple #8
0
//设置状态
func (c Role) SetStatus(role *models.Role) revel.Result {
	var id string = c.Params.Get("id")
	var status string = c.Params.Get("status")

	data := make(map[string]string)

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

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

		role.Status = Status

		if role.SetStatus(Id) {

			//******************************************
			//管理员日志
			if UserID, ok := c.Session["UserID"]; ok {
				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)
				if Status == 1 {
					desc := "角色管理|^|设置状态|^|状态:启用"
					logs.Save(admin_info, c.Controller, desc)
				} else {
					desc := "角色管理|^|设置状态|^|状态:锁定"
					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)
	}
}
Exemple #9
0
func (c App) Main(admin *models.Admin) revel.Result {

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

	if UserID, ok := c.Session["UserID"]; ok {
		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())

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

		//快捷面板
		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")
}
Exemple #10
0
//后台登陆
func (c *User) LoginPost() revel.Result {

	var username string = c.Params.Get("username")
	var password string = c.Params.Get("password")
	var verify string = c.Params.Get("verify")

	data := make(map[string]string)

	if len(username) <= 0 {
		data["status"] = "0"
		data["url"] = "/"
		data["info"] = "请填写用户名!"
		return c.RenderJson(data)
	}

	if len(password) <= 0 {
		data["status"] = "0"
		data["url"] = "/"
		data["info"] = "请填写密码!"
		return c.RenderJson(data)
	}

	if len(verify) <= 0 {
		data["status"] = "0"
		data["url"] = "/"
		data["info"] = "请填写验证码!"
		return c.RenderJson(data)
	}

	admin := new(models.Admin)

	admin = admin.GetByName(username)

	if admin.Id <= 0 {
		data["status"] = "0"
		data["url"] = "/"
		data["info"] = "用户名错误!"
	} else if username == admin.Username && lib.EncryptPassword(password) == admin.Password {
		c.Session["UserID"] = fmt.Sprintf("%d", admin.Id)

		data["status"] = "1"
		data["url"] = "/"
		data["info"] = "登陆成功!"
	} else {
		data["status"] = "0"
		data["url"] = "/"
		data["info"] = "密码错误!"
	}

	return c.RenderJson(data)
}
Exemple #11
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)
	}
}
Exemple #12
0
//删除
func (c Menu) Delete(menu *models.Menu) revel.Result {
	var id string = c.Params.Get("id")

	data := make(map[string]string)

	if len(id) <= 0 {
		data["status"] = "0"
		data["message"] = "参数错误!"
	}

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

	if menu.DelByID(Id) {

		//******************************************
		//管理员日志
		if UserID, ok := c.Session["UserID"]; ok {
			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"] = "删除成功!"
	} else {
		data["status"] = "0"
		data["message"] = "删除失败!"
	}

	return c.RenderJson(data)
}
Exemple #13
0
func (c Test) Index(admin *models.Admin) revel.Result {
	title := "测试--GoCMS管理系统"

	if UserID, ok := c.Session["UserID"]; ok {

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

		admin_info := admin.GetById(UserID)

		admin_panel := new(models.Admin_Panel)
		admin_panel.IsAdd(18, admin_info)
	}

	c.Render(title)
	return c.RenderTemplate("Public/Test.html")
}
Exemple #14
0
//首页
func (c App) Index(admin *models.Admin) revel.Result {
	title := "首页--GoCMS管理系统"

	if UserID, ok := c.Session["UserID"]; ok {
		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")
		}

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

		//导航菜单
		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")
}
Exemple #15
0
//首页
func (c App) Index(admin *models.Admin) revel.Result {
	title := "首页--GoCMS管理系统"

	if UserID, ok := c.Session["UserID"]; ok {
		UserID, err := strconv.ParseInt(UserID, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		admin := new(models.Admin)
		admin_info := admin.GetById(UserID)
		if admin_info.Id <= 0 {
			c.Flash.Error("请先登录")
			return c.Redirect(routes.User.Login())
		}

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

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

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

	} else {
		c.Flash.Error("请先登录")
		return c.Redirect(routes.User.Login())
	}

	//系统信息
	sys_info := lib.GetSysInfo()

	c.Render(title, sys_info)
	return c.RenderTemplate("App/Index.html")
}
Exemple #16
0
//首页
func (c Menu) Index(menu *models.Menu) revel.Result {
	title := "菜单管理--GoCMS管理系统"

	if UserID, ok := c.Session["UserID"]; ok {

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

		menus := menu.GetMenuHtml(admin_info)

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

	return c.RenderTemplate("Setting/Menu/Index.html")
}
Exemple #17
0
func (c Category) Index(category *models.Category) revel.Result {
	title := "栏目管理--GoCMS管理系统"

	if UserID, ok := c.Session["UserID"]; ok {

		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")
}
Exemple #18
0
//后台地图
func (c *Public) Map(menu *models.Menu) revel.Result {

	title := "后台地图--GoCMS管理系统"

	if UserID, ok := c.Session["UserID"]; ok {
		UserID, err := strconv.ParseInt(UserID, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}
		admin := new(models.Admin)
		admin_info := admin.GetById(UserID)

		//返回后台地图
		map_html := menu.GetMenuMap(admin_info)

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

	return c.RenderTemplate("Public/map.html")
}
Exemple #19
0
//删除快捷方式
func (c *Ajax) DelPanel(admin_panel *models.Admin_Panel) revel.Result {
	if UserID, ok := c.Session["UserID"]; ok {
		var mid string = c.Params.Get("mid")

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

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

		//获取登陆用户信息
		admin := new(models.Admin)
		admin_info := admin.GetById(UserID)

		is_True := admin_panel.DelPanel(Mid, admin_info)

		data := make(map[string]string)

		if is_True {
			data["status"] = "0"
			data["message"] = "取消成功!"
			return c.RenderJson(data)
		} else {
			data["status"] = "2"
			data["message"] = "取消失败!"
			return c.RenderJson(data)
		}
	} else {
		data := make(map[string]string)
		data["status"] = "1"
		data["message"] = "未登陆!"
		return c.RenderJson(data)
	}
}
Exemple #20
0
//成员管理
func (c Role) Member(role *models.Role) revel.Result {
	title := "成员管理--GoCMS管理系统"

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

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

		where := make(map[string]string)

		admin := new(models.Admin)

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

			admin_list, pages := admin.GetByAll(Id, where, Page, 10)

			c.Render(title, admin_list, pages)
		} else {
			admin_list, pages := admin.GetByAll(Id, where, 1, 10)

			c.Render(title, admin_list, pages)
		}

	} else {
		c.Render(title)
	}

	return c.RenderTemplate("Setting/Role/Member.html")
}
Exemple #21
0
//清空日志
func (c Logs) DelAll(logs *models.Logs) revel.Result {

	data := make(map[string]string)

	IsDel := logs.DelAll()

	if IsDel {

		//******************************************
		//管理员日志
		if UserID, ok := c.Session["UserID"]; ok {
			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 := "清空日志|^|日志管理"
			logs.Save(admin_info, c.Controller, desc)
		}

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

		data["status"] = "1"
		data["url"] = "/Message/"
		data["message"] = "清空日志完成!"
		return c.RenderJson(data)
	} else {
		data["status"] = "0"
		data["url"] = "/Message/"
		data["message"] = "清空日志失败!"
		return c.RenderJson(data)
	}
}
Exemple #22
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")
}
Exemple #23
0
//首页
func (c Admin) Index(admin *models.Admin) revel.Result {
	title := "管理员管理--GoCMS管理系统"

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

	where := make(map[string]string)

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

		admin_list, pages := admin.GetByAll(0, where, Page, 10)

		c.Render(title, admin_list, pages)
	} else {
		admin_list, pages := admin.GetByAll(0, where, 1, 10)

		c.Render(title, admin_list, pages)
	}

	return c.RenderTemplate("Setting/Admin/Index.html")
}
Exemple #24
0
//检测是否登陆
//init.go调用
func (c *Module) inject() revel.Result {

	if UserID, ok := c.Session["UserID"]; ok {
		UserID, err := strconv.ParseInt(UserID, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		admin := new(models.Admin)
		admin_info := admin.GetById(UserID)
		if admin_info.Id <= 0 {
			c.Flash.Error("请先登录")
			return c.Redirect(routes.User.Login())
		}

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

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

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

	} else {
		c.Flash.Error("请先登录")
		return c.Redirect(routes.User.Login())
	}

	return nil
}
Exemple #25
0
//左侧导航菜单
func (c *User) Left(menu *models.Menu) revel.Result {

	title := "左侧导航--GoCMS管理系统"

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

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

		if UserID, ok := c.Session["UserID"]; ok {

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

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

			//获取左侧导航菜单
			left_menu := menu.GetLeftMenuHtml(Pid, admin_info)

			c.Render(title, left_menu)
		} else {
			c.Render(title)
		}
	} else {
		//获取左侧导航菜单
		//默认获取 我的面板
		if UserID, ok := c.Session["UserID"]; ok {

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

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

			//获取左侧导航菜单
			left_menu := menu.GetLeftMenuHtml(1, admin_info)

			c.Render(title, left_menu)
		} else {
			c.Render(title)
		}
	}
	return c.RenderTemplate("Public/left.html")
}
Exemple #26
0
//添加管理员
func (c Admin) Add(admin *models.Admin) revel.Result {

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

		role := new(models.Role)
		role_list := role.GetRoleList()

		c.Render(title, role_list)
		return c.RenderTemplate("Setting/Admin/Add.html")
	} else {

		var username string = c.Params.Get("username")
		if len(username) > 0 {
			admin.Username = username
		} else {
			c.Flash.Error("请输入用户名!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		if admin.HasName() {
			c.Flash.Error("用户名“" + username + "”已存在!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var password string = c.Params.Get("password")
		if len(password) > 0 {
			admin.Password = password
		} else {
			c.Flash.Error("请输入密码!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var pwdconfirm string = c.Params.Get("pwdconfirm")
		if len(pwdconfirm) > 0 {
			if password != pwdconfirm {
				c.Flash.Error("两次输入密码不一致!")
				c.Flash.Out["url"] = "/Admin/Add/"
				return c.Redirect("/Message/")
			}
		} else {
			c.Flash.Error("请输入确认密码!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var email string = c.Params.Get("email")
		if len(email) > 0 {
			admin.Email = email
		} else {
			c.Flash.Error("请输入E-mail!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		if admin.HasEmail() {
			c.Flash.Error("E-mail已存在!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var realname string = c.Params.Get("realname")
		if len(realname) > 0 {
			admin.Realname = realname
		} else {
			c.Flash.Error("请输入真实姓名!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var lang string = c.Params.Get("lang")
		if len(lang) > 0 {
			admin.Lang = lang
		} else {
			c.Flash.Error("请选择语言!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

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

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

			admin.Roleid = Roleid
		} else {
			c.Flash.Error("请选择所属角色!")
			c.Flash.Out["url"] = "/Admin/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)
			}
			admin.Status = Status
		} else {
			c.Flash.Error("请选择状态!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		if admin.Save() {
			c.Flash.Success("添加管理员成功!")
			c.Flash.Out["url"] = "/Admin/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加管理员失败!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}
	}
}
Exemple #27
0
//编辑管理员
func (c Admin) Edit(admin *models.Admin) revel.Result {
	if c.Request.Method == "GET" {
		title := "编辑管理员--GoCMS管理系统"

		role := new(models.Role)
		role_list := role.GetRoleList()

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

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

			admin_info := admin.GetById(Id)

			c.Render(title, admin_info, role_list)
		} else {
			c.Render(title, role_list)
		}

		return c.RenderTemplate("Setting/Admin/Edit.html")
	} else {

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

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

			var username string = c.Params.Get("username")
			if len(username) > 0 {
				admin.Username = username
			} else {
				c.Flash.Error("请输入用户名!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var password string = c.Params.Get("password")
			if len(password) > 0 {
				admin.Password = password
			}

			var pwdconfirm string = c.Params.Get("pwdconfirm")
			if len(pwdconfirm) > 0 {
				if password != pwdconfirm {
					c.Flash.Error("两次输入密码不一致!")
					c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
					return c.Redirect("/Message/")
				}
			}

			var email string = c.Params.Get("email")
			if len(email) > 0 {
				admin.Email = email
			} else {
				c.Flash.Error("请输入E-mail!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var realname string = c.Params.Get("realname")
			if len(realname) > 0 {
				admin.Realname = realname
			} else {
				c.Flash.Error("请输入真实姓名!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var lang string = c.Params.Get("lang")
			if len(lang) > 0 {
				admin.Lang = lang
			} else {
				c.Flash.Error("请选择语言!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

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

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

				admin.Roleid = Roleid
			} else {
				c.Flash.Error("请选择所属角色!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				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)
				}
				admin.Status = Status
			} else {
				c.Flash.Error("请选择是否启用!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			if admin.Edit(Id) {
				c.Flash.Success("编辑管理员成功!")
				c.Flash.Out["url"] = "/Admin/"
				return c.Redirect("/Message/")
			} else {
				c.Flash.Error("编辑管理员失败!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}
		} else {
			c.Flash.Error("编辑管理员失败!")
			c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
			return c.Redirect("/Message/")
		}

	}
}
Exemple #28
0
//添加菜单
func (c Menu) Add(menu *models.Menu) revel.Result {

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

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

			if UserID, ok := c.Session["UserID"]; ok {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}
				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				//返回菜单Option的HTML
				menus := menu.GetMenuOptionHtml(Id, admin_info)

				c.Render(title, menus, Id)
			} else {
				c.Render(title, Id)
			}

		} else {

			if UserID, ok := c.Session["UserID"]; ok {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}
				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				//返回菜单Option的HTML
				menus := menu.GetMenuOptionHtml(0, admin_info)
				c.Render(title, menus)
			} else {
				c.Render(title)
			}
		}

		return c.RenderTemplate("Setting/Menu/Add.html")
	} else {

		var pid string = c.Params.Get("pid")
		if len(pid) > 0 {
			Pid, err := strconv.ParseInt(pid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			menu.Pid = Pid
		} else {
			c.Flash.Error("请选择父菜单!")
			c.Flash.Out["url"] = "/Menu/Add/"
			return c.Redirect("/Message/")
		}

		var name string = c.Params.Get("name")
		if len(name) > 0 {
			menu.Name = name
		} else {
			c.Flash.Error("请输入中文语言名称!")
			c.Flash.Out["url"] = "/Menu/Add/"
			return c.Redirect("/Message/")
		}

		var enname string = c.Params.Get("enname")
		if len(enname) > 0 {
			menu.Enname = enname
		} else {
			c.Flash.Error("请输入英文语言名称!")
			c.Flash.Out["url"] = "/Menu/Add/"
			return c.Redirect("/Message/")
		}

		var url string = c.Params.Get("url")
		if len(url) > 0 {
			menu.Url = url
		} else {
			c.Flash.Error("请输入菜单地址!")
			c.Flash.Out["url"] = "/Menu/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)
			}
			menu.Order = Order
		} else {
			c.Flash.Error("请输入排序!")
			c.Flash.Out["url"] = "/Menu/Add/"
			return c.Redirect("/Message/")
		}

		var data string = c.Params.Get("data")
		menu.Data = data

		var display string = c.Params.Get("display")
		if len(display) > 0 {
			Display, err := strconv.ParseInt(display, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			menu.Display = Display
		} else {
			c.Flash.Error("请选择是否显示菜单!")
			c.Flash.Out["url"] = "/Menu/Add/"
			return c.Redirect("/Message/")
		}

		if menu.Save() {

			//******************************************
			//管理员日志
			if UserID, ok := c.Session["UserID"]; ok {
				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 := "添加菜单:" + name + "|^|菜单管理"
				logs.Save(admin_info, c.Controller, desc)
			}

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

			c.Flash.Success("添加菜单成功")
			c.Flash.Out["url"] = "/Menu/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加菜单失败")
			c.Flash.Out["url"] = "/Menu/Add/"
			return c.Redirect("/Message/")
		}
	}
}
Exemple #29
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() {

			//******************************************
			//管理员日志
			if UserID, ok := c.Session["UserID"]; ok {
				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/")
		}
	}
}
Exemple #30
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")
}