//获取快捷方式 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) } }
//当前位置 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("") } }
//解锁 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") } }
//退出登陆 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 { if k != "Lang" { delete(c.Session, k) } } } c.Flash.Success("安全退出") c.Flash.Out["url"] = "/User/Login/" return c.Redirect("/Message/") }
//检测登陆 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 }
//设置状态 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) } }
//左侧导航菜单 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") }
//删除公告 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) } }
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") }
//删除栏目 func (c Category) Delete(category *models.Category) 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 category.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) }
//首页 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") }
//删除快捷方式 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) } }
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") }
//清空日志 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) } }
//首页 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") }
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") }
//添加公告 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/") } } }
//添加角色 func (c Role) Add(role *models.Role) revel.Result { if c.Request.Method == "GET" { 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) menu := new(models.Menu) tree := menu.GetMenuTree("", admin_info) c.Render(title, tree) } else { c.Render(title) } return c.RenderTemplate("Setting/Role/Add.html") } else { var rolename string = c.Params.Get("rolename") if len(rolename) > 0 { role.Rolename = rolename } else { c.Flash.Error("请输入角色名称!") c.Flash.Out["url"] = "/Role/Add/" return c.Redirect("/Message/") } var desc string = c.Params.Get("desc") if len(desc) > 0 { role.Desc = desc } else { c.Flash.Error("请输入角色描述!") c.Flash.Out["url"] = "/Role/Add/" return c.Redirect("/Message/") } var data string = c.Params.Get("data") if len(data) > 0 { role.Data = data } else { c.Flash.Error("请选择所属权限!") c.Flash.Out["url"] = "/Role/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) } role.Status = Status } else { c.Flash.Error("请选择是否启用!") c.Flash.Out["url"] = "/Role/Add/" return c.Redirect("/Message/") } if role.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 := "添加角色:" + rolename + "|^|角色管理" logs.Save(admin_info, c.Controller, desc) } //***************************************** c.Flash.Success("添加角色成功") c.Flash.Out["url"] = "/Role/" return c.Redirect("/Message/") } else { c.Flash.Error("添加角色失败") c.Flash.Out["url"] = "/Role/Add/" return c.Redirect("/Message/") } } }
//添加来源 func (c Copyfrom) Add(copyfrom *models.Copyfrom) revel.Result { if c.Request.Method == "GET" { title := "添加来源--GoCMS管理系统" c.Render(title) return c.RenderTemplate("Extend/Copyfrom/Add.html") } else { //接收上传文件 thumb, header, err := c.Request.FormFile("thumb") if err != nil { //来源logo copyfrom.Thumb = "" } else { defer thumb.Close() //判断是否是系统的分隔符 separator := "/" if os.IsPathSeparator('\\') { separator = "\\" } else { separator = "/" } fileData, _ := ioutil.ReadAll(thumb) if len(fileData) >= 1024*1024*2 { c.Flash.Error("你上传大小为" + utils.FileSize(len(fileData)) + ",文件应小于2M!") c.Flash.Out["url"] = "/Copyfrom/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") //允许上传的后缀名 filesuffix, _ := config_conf.String("upload", "upload.filesuffix") //文件类型检测 if !strings.Contains(filesuffix, path.Ext(header.Filename)) { c.Flash.Error("文件只支持图片!") c.Flash.Out["url"] = "/Copyfrom/Add/" return c.Redirect("/Message/") } //文件保存目录 web_save_path := fmt.Sprintf("/%s/copyfrom/%s", upload_dir, time.Now().Format("2006/01/02/")) save_path := fmt.Sprintf("%s/www/%s/copyfrom/%s", basepath, upload_dir, time.Now().Format("2006/01/02/")) //字符串替换 /替换为系统分隔符 save_path = strings.Replace(save_path, "/", separator, -1) //新文件名 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) //创建目录 error := os.MkdirAll(save_path, os.ModePerm) if error != nil { c.Flash.Error(error.Error()) c.Flash.Out["url"] = "/Copyfrom/Add/" return c.Redirect("/Message/") } //保存文件 file_dir := save_path + new_file_name save_url := web_save_path + new_file_name e := ioutil.WriteFile(file_dir, fileData, os.ModePerm) if e != nil { c.Flash.Error(e.Error()) c.Flash.Out["url"] = "/Copyfrom/Add/" return c.Redirect("/Message/") } //来源logo copyfrom.Thumb = save_url } //来源名称 var sitename string = c.Params.Get("sitename") if len(sitename) > 0 { copyfrom.Sitename = sitename } else { c.Flash.Error("请输入来源名称!") c.Flash.Out["url"] = "/Copyfrom/Add/" return c.Redirect("/Message/") } //来源链接 var siteurl string = c.Params.Get("siteurl") if len(siteurl) > 0 { copyfrom.Siteurl = siteurl } else { c.Flash.Error("请输入来源链接!") c.Flash.Out["url"] = "/Copyfrom/Add/" return c.Redirect("/Message/") } if copyfrom.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 := "添加来源:" + sitename + "|^|来源管理" logs.Save(admin_info, c.Controller, desc) } //***************************************** c.Flash.Success("添加来源成功!") c.Flash.Out["url"] = "/Copyfrom/" return c.Redirect("/Message/") } else { c.Flash.Error("添加来源失败") c.Flash.Out["url"] = "/Copyfrom/Add/" return c.Redirect("/Message/") } } }
//添加管理员 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 ip := c.Request.Header.Get("X-Forwarded-For"); ip != "" { ips := strings.Split(ip, ",") if len(ips) > 0 && ips[0] != "" { rip := strings.Split(ips[0], ":") admin.Lastloginip = rip[0] } } else { ip := strings.Split(c.Request.RemoteAddr, ":") if len(ip) > 0 { if ip[0] != "[" { admin.Lastloginip = ip[0] } } } if admin.Save() { //****************************************** //管理员日志 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 := "添加管理员:" + username + "|^|管理员管理" logs.Save(admin_info, c.Controller, desc) } //***************************************** 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/") } } }
//编辑管理员 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) { //****************************************** //管理员日志 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 := "编辑管理员:" + username + "|^|管理员管理" logs.Save(admin_info, c.Controller, desc) } //***************************************** 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/") } } }
//修改密码 func (c *User) EditPwd(admin *models.Admin) revel.Result { if c.Request.Method == "GET" { 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) c.Render(title, admin_info) } else { c.Render(title) } return c.RenderTemplate("User/EditPwd.html") } else { 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) var old_password string = c.Params.Get("old_password") if len(old_password) > 0 { if admin_info.Password != utils.Md5(old_password) { c.Flash.Error("旧密码不正确!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } } else { return c.Redirect("/User/EditPwd/") } var new_password string = c.Params.Get("new_password") if len(new_password) > 0 { } else { c.Flash.Error("新密码不能为空!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } var new_pwdconfirm string = c.Params.Get("new_pwdconfirm") if len(new_pwdconfirm) > 0 { if new_pwdconfirm != new_password { c.Flash.Error("两次输入密码入不一致!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } else { admin.Password = new_pwdconfirm } } else { c.Flash.Error("请输入重复新密码!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } if admin.EditPwd(UserID) { //****************************************** //管理员日志 logs := new(models.Logs) desc := "个人设置|^|修改密码" logs.Save(admin_info, c.Controller, desc) //***************************************** c.Flash.Success("修改成功!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } else { c.Flash.Error("修改失败!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } } else { c.Flash.Error("未登陆,请先登陆!") c.Flash.Out["url"] = "/" return c.Redirect("/Message/") } } }
//个人信息 func (c *User) EditInfo(admin *models.Admin) revel.Result { if c.Request.Method == "GET" { 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) c.Render(title, admin_info) } else { c.Render(title) } return c.RenderTemplate("User/EditInfo.html") } else { var realname string = c.Params.Get("realname") if len(realname) > 0 { admin.Realname = realname } else { c.Flash.Error("请输入真实姓名!") c.Flash.Out["url"] = "/EditInfo/" return c.Redirect("/Message/") } var email string = c.Params.Get("email") if len(email) > 0 { admin.Email = email } else { c.Flash.Error("请输入电子邮件!") c.Flash.Out["url"] = "/EditInfo/" 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"] = "/EditInfo/" return c.Redirect("/Message/") } if UserID, ok := c.Session["UserID"]; ok { UserID, err := strconv.ParseInt(UserID, 10, 64) if err != nil { revel.WARN.Println(err) } if admin.EditInfo(UserID) { //****************************************** //管理员日志 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) c.Session["Lang"] = admin_info.Lang logs := new(models.Logs) desc := "个人设置|^|个人信息" logs.Save(admin_info, c.Controller, desc) } if LANG, ok := c.Session["Lang"]; ok { //设置语言 c.Request.Locale = LANG } else { //设置默认语言 c.Request.Locale = "zh" } c.Flash.Success(c.Message("operation_success")) c.Flash.Out["url"] = "/EditInfo/" return c.Redirect("/Message/") } else { c.Flash.Error(c.Message("operation_failure")) c.Flash.Out["url"] = "/EditInfo/" return c.Redirect("/Message/") } } else { c.Flash.Error(c.Message("not_login")) c.Flash.Out["url"] = "/" return c.Redirect("/Message/") } } }
//添加菜单 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/") } } }
//添加栏目 func (c Category) Add(category *models.Category) 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) } //返回菜单Option的HTML categorys := category.GetCateGoryOptionHtml(Id) c.Render(title, categorys, Id) } else { //返回菜单Option的HTML categorys := category.GetCateGoryOptionHtml(0) c.Render(title, categorys) } return c.RenderTemplate("Content/Category/Add.html") } else { //栏目类型 var cate_type string = c.Params.Get("type") if len(cate_type) > 0 { Type, err := strconv.ParseInt(cate_type, 10, 64) if err != nil { revel.WARN.Println(err) } category.Type = Type } else { c.Flash.Error("请选择栏目类型!") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } //上级栏目 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) } category.Pid = Pid } else { c.Flash.Error("请选择父栏目!") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } //栏目名称 var name string = c.Params.Get("name") if len(name) > 0 { category.Name = name } else { c.Flash.Error("请输入栏目名称!") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } var enname string = c.Params.Get("enname") if len(enname) > 0 { category.Enname = enname } else { c.Flash.Error("请输入英文栏目名称!") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } //栏目地址 var url string = c.Params.Get("url") if len(url) > 0 { category.Url = url } else { c.Flash.Error("请输入栏目地址!") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } //描述 var desc string = c.Params.Get("desc") if len(desc) > 0 { category.Desc = desc } else { c.Flash.Error("请输入描述!") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } //是否在导航显示 var ismenu string = c.Params.Get("ismenu") if len(ismenu) > 0 { IsMenu, err := strconv.ParseInt(ismenu, 10, 64) if err != nil { revel.WARN.Println(err) } category.Ismenu = IsMenu } else { c.Flash.Error("请选择是否在导航显示!") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } Setting := make(map[string]interface{}) //栏目生成Html var ishtml string = c.Params.Get("ishtml") Setting["ishtml"] = ishtml var content_ishtml string = c.Params.Get("content_ishtml") Setting["content_ishtml"] = content_ishtml var meta_title string = c.Params.Get("meta_title") Setting["meta_title"] = meta_title var meta_keywords string = c.Params.Get("meta_keywords") Setting["meta_keywords"] = meta_keywords var meta_desc string = c.Params.Get("meta_desc") Setting["meta_desc"] = meta_desc //栏目设置 Setting_Text, err := json.Marshal(Setting) if err != nil { revel.WARN.Println(err) } category.SettingText = Setting category.Setting = string(Setting_Text) if category.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"] = "/Category/" return c.Redirect("/Message/") } else { c.Flash.Error("添加栏目失败") c.Flash.Out["url"] = "/Category/Add/" return c.Redirect("/Message/") } } }