本文整理汇总了Golang中github.com/blackmady/NoneCMS/app/models.Role类的典型用法代码示例。如果您正苦于以下问题:Golang Role类的具体用法?Golang Role怎么用?Golang Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Role类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Delete
//删除角色
func (c Role) Delete(role *models.Role) 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 role.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)
}
}
示例2: SetStatus
//设置状态
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)
}
}
示例3: Index
//首页
func (c Role) Index(role *models.Role) revel.Result {
title := "角色管理--GoCMS管理系统"
var page string = c.Params.Get("page")
if len(page) > 0 {
Page, err := strconv.ParseInt(page, 10, 64)
if err != nil {
revel.WARN.Println(err)
}
role_list, pages := role.GetByAll(Page, 10)
c.Render(title, role_list, pages)
} else {
role_list, pages := role.GetByAll(1, 10)
c.Render(title, role_list, pages)
}
return c.RenderTemplate("Setting/Role/Index.html")
}
示例4: Add
//添加角色
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/")
}
}
}
示例5: Add
//添加管理员
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 {
//.........这里部分代码省略.........
示例6: Edit
//编辑管理员
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")
//.........这里部分代码省略.........