Beispiel #1
0
Datei: user.go Projekt: ruoL/code
// 删除用户
func (this *UserController) Delete() {
	//计算用户数量,必须保留一个
	count, err := models.GetUserCount()
	if err != nil {
		this.Abort("404")
	}
	if count == 1 {
		this.Data["json"] = map[string]string{"code": "error", "info": "必须保留一个用户!"}
		this.ServeJson()
		return
	}

	id, err := this.GetInt64("id")
	if err != nil {
		this.Data["json"] = map[string]string{"code": "error", "info": err.Error()}
		this.ServeJson()
		return
	}

	err = models.DelUser(id)
	if err != nil {
		this.Data["json"] = map[string]string{"code": "error", "info": err.Error()}
	} else {
		this.Data["json"] = map[string]string{"code": "success", "info": "用户删除成功!"}
	}
	this.ServeJson()
	return
}
Beispiel #2
0
//显示后台首页
func (this *WelcomeController) Get() {
	var err error
	this.Data["ArticleCount"], err = models.GetArticleCount([]int{0, 1})
	if err != nil {
		beego.Error(err)
	}
	this.Data["CategoryCount"], err = models.GetCategoryCount()
	if err != nil {
		beego.Error(err)
	}
	this.Data["UserCount"], err = models.GetUserCount()
	if err != nil {
		beego.Error(err)
	}
	this.Data["Title"] = "梵响 - 后台首页"
	this.Layout = "manager/layout.html"
	this.TplNames = "manager/index.html"
}
Beispiel #3
0
Datei: user.go Projekt: ruoL/code
//显示用户首页
func (this *UserController) Get() {
	//处理分页
	pageSize, err := beego.AppConfig.Int("pagesize")
	if err != nil {
		pageSize = 10
	}
	count, err := models.GetUserCount()
	if err != nil {
		this.Abort("404")
	}
	paginator := pagination.NewPaginator(this.Ctx.Request, pageSize, count)
	this.Data["paginator"] = paginator
	//获取用户列表
	this.Data["Users"], err = models.GetUsers(paginator.Offset(), pageSize)
	if err != nil {
		this.Abort("404")
	}
	this.Data["Title"] = "管理后台 - 用户列表"
	this.Layout = "manager/layout.html"
	this.TplNames = "manager/user_index.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = "manager/user_index_heade.html"
	return
}