예제 #1
0
//编辑管理员
func (this *AccessController) EditAdmin() {
	this.NeedLogin()       //需要登录
	this.GetUrlAuthorith() //URL访问权限控制
	var uid int
	this.Ctx.Input.Bind(&uid, "uid")
	if this.Ctx.Input.IsPost() == true {
		var adminData models.AdminList
		var json JsonOut
		adminData.Id = uid
		pwd1 := this.Ctx.Input.Query("pwd1")
		pwd := this.Ctx.Input.Query("pwd")
		if pwd != "" {
			if pwd != pwd1 {
				this.SendError("两次输入的密码不一致", 1)
				return
			}
		}
		adminData.Pwd = pwd
		adminData.Nickname = this.Ctx.Input.Query("nickname")
		adminData.Remark = this.Ctx.Input.Query("remark")
		var role_id int
		this.Ctx.Input.Bind(&role_id, "role_id")
		if role_id < 1 {
			this.SendError("没有选择角色组", 1)
			return
		}
		adminData.Role_id = role_id
		admin := models.NewAdmniModel()
		if admin.EditOneAdmin(adminData) == true {
			adminLog := models.NewAdminLogModel()
			adminname := this.GetSession("name")
			adminLog.AddLog(adminname.(string), 1, "修改管理员:"+adminData.Nickname, "")
			json.Status = 1
			json.Info = "修改成功"
			json.Url = "/access/index"
		} else {
			json.Status = 0
			json.Info = "修改失败"
		}
		this.Data["json"] = json
		this.ServeJson()

	} else {
		this.init() //实例化控制器

		admin := models.NewAdmniModel()
		adminData := admin.GetOneAdminData(uid)
		this.Data["Info"] = adminData
		this.Data["Role"] = admin.GetRoleSelectHtml(adminData.Role_id, 1)
		this.Data["Title"] = "编辑管理员"
		this.TplNames = "access/adminadd.html"
		//this.Ctx.WriteString("hahahaha")
	}
}
예제 #2
0
//添加管理员
func (this *AccessController) Addadmin() {
	this.NeedLogin()       //需要登录
	this.GetUrlAuthorith() //URL访问权限控制
	if this.Ctx.Input.IsPost() == true {
		var adminData models.AdminList
		//var json JsonOut
		email := this.Ctx.Input.Query("email")
		pwd := this.Ctx.Input.Query("pwd")
		if email == "" {
			this.SendError("请输入邮箱", 1)
			return
		}
		if pwd == "" {
			this.SendError("请输入密码", 1)
			return
		}
		adminData.Pwd = pwd
		adminData.Email = email
		adminData.Nickname = this.Ctx.Input.Query("nickname")
		adminData.Remark = this.Ctx.Input.Query("remark")
		var role_id int
		this.Ctx.Input.Bind(&role_id, "role_id")
		if role_id < 1 {
			this.SendError("没有选择角色组", 1)
			return
		}
		adminData.Role_id = role_id
		admin := models.NewAdmniModel()
		json := admin.AddOneAdmin(adminData)
		if json.Status == 1 {
			adminLog := models.NewAdminLogModel()
			adminname := this.GetSession("name")
			adminLog.AddLog(adminname.(string), 1, "添加管理员:"+adminData.Nickname, "")

			json.Url = "/access/index"
		}
		this.Data["json"] = json
		this.ServeJson()

	} else {
		this.init() //实例化控制器

		admin := models.NewAdmniModel()
		//adminData := admin.GetOneAdminData(uid)
		this.Data["Info"] = &models.AdminList{}
		this.Data["Role"] = admin.GetRoleSelectHtml(0, 1)
		this.Data["Title"] = "添加管理员"
		this.TplNames = "access/adminadd.html"
	}
}