Ejemplo n.º 1
0
func (this *UserController) List(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin Privilege User List")
	this.Init(w, r)

	if this.Privilege != config.PrivilegeAD {
		class.Logger.Info(r.RemoteAddr + " " + this.Uid + " try to visit Admin page")
		this.Data["Title"] = "Warning"
		this.Data["Info"] = "You are not admin!"
		err := this.Execute(w, "view/layout.tpl", "view/400.tpl")
		if err != nil {
			http.Error(w, "tpl error", 500)
			return
		}
		return
	}
	userModel := model.UserModel{}
	userlist, err := userModel.List(nil)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	this.Data["User"] = userlist
	this.Data["Title"] = "Privilege User List"
	this.Data["IsUser"] = true
	this.Data["IsList"] = true

	err = this.Execute(w, "view/admin/layout.tpl", "view/admin/user_list.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
Ejemplo n.º 2
0
//显示具有特殊权限的用户
//@URL: /admin/users/ @method: GET
func (uc *AdminUser) List() {
	restweb.Logger.Debug("Admin Privilege User List")

	if uc.Privilege != config.PrivilegeAD {
		restweb.Logger.Info(uc.Uid + " try to visit Admin page")
		uc.Output["Title"] = "Warning"
		uc.Output["Info"] = "You are not admin!"
		uc.RenderTemplate("view/layout.tpl", "view/400.tpl")
		return
	}

	userModel := model.UserModel{}
	userlist, err := userModel.List(nil)
	if err != nil {
		uc.Error(err.Error(), 500)
		return
	}

	uc.Output["User"] = userlist
	uc.Output["Title"] = "Privilege User List"
	uc.Output["IsUser"] = true
	uc.Output["IsList"] = true
	uc.RenderTemplate("view/admin/layout.tpl", "view/admin/user_list.tpl")
}
Ejemplo n.º 3
0
//@URL: /ranklist @method: GET
func (rc *RanklistController) Index() {
	restweb.Logger.Debug("Ranklist")

	// Page

	if _, ok := rc.Input["page"]; !ok {
		rc.Input.Set("page", "1")
	}

	userModel := model.UserModel{}
	userList, err := userModel.List(nil)
	if err != nil {
		http.Error(rc.W, err.Error(), 400)
		return
	}

	var count int
	count = 1
	for _, one := range userList {
		if one.Status == config.StatusAvailable {
			count += 1
		}
	}

	var pageCount = (count-1)/config.UserPerPage + 1
	page, err := strconv.Atoi(rc.Input.Get("page"))
	if err != nil {
		rc.Error("args error", 400)
		return
	}
	if page > pageCount {
		rc.Error("args error", 400)
		return
	}

	pageData := rc.GetPage(page, pageCount)
	for k, v := range pageData {
		rc.Output[k] = v
	}

	qry := make(map[string]string)
	qry["offset"] = strconv.Itoa((page - 1) * config.UserPerPage)
	qry["limit"] = strconv.Itoa(config.UserPerPage)
	userList, err = userModel.List(qry)
	if err != nil {

	}

	list := make([]rank, len(userList), len(userList))
	count = 1
	for i, one := range userList {
		list[i].User = *one
		if one.Status == config.StatusAvailable {
			list[count-1].Index = count + (page-1)*config.UserPerPage
			count += 1
		}
	}
	rc.Output["URL"] = "/ranklist?"
	rc.Output["User"] = list
	rc.Output["Title"] = "Ranklist"
	rc.Output["IsRanklist"] = true
	rc.RenderTemplate("view/layout.tpl", "view/ranklist.tpl")
}
Ejemplo n.º 4
0
func (this *UserController) Register(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Register")
	this.Init(w, r)

	var one model.User
	userModel := model.UserModel{}

	uid := r.FormValue("user[handle]")
	nick := r.FormValue("user[nick]")
	pwd := r.FormValue("user[password]")
	pwdConfirm := r.FormValue("user[confirmPassword]")
	one.Mail = r.FormValue("user[mail]")
	one.School = r.FormValue("user[school]")
	one.Motto = r.FormValue("user[motto]")

	ok := 1
	hint := make(map[string]string)

	if uid == "" {
		ok, hint["uid"] = 0, "Handle should not be empty."
	} else {
		qry := make(map[string]string)
		qry["uid"] = uid
		ret, err := userModel.List(qry)
		if err != nil {
			http.Error(w, err.Error(), 500)
		} else if len(ret) > 0 {
			ok, hint["uid"] = 0, "This handle is currently in use."
		}
	}
	if nick == "" {
		ok, hint["nick"] = 0, "Nick should not be empty."
	}
	if len(pwd) < 6 {
		ok, hint["pwd"] = 0, "Password should contain at least six characters."
	}
	if pwd != pwdConfirm {
		ok, hint["pwdConfirm"] = 0, "Confirmation mismatched."
	}
	if ok == 1 {
		one.Uid = uid
		one.Nick = nick
		one.Pwd = pwd
		//one.Privilege = config.PrivilegePU
		one.Privilege = config.PrivilegeAD

		err := userModel.Insert(one)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}

		this.SetSession(w, r, "Uid", uid)
		this.SetSession(w, r, "Privilege", "1")
		w.WriteHeader(200)
	} else {
		b, err := json.Marshal(&hint)
		if err != nil {
			http.Error(w, "json error", 500)
			return
		}

		w.WriteHeader(400)
		w.Write(b)
	}
}
Ejemplo n.º 5
0
func (this *RanklistController) Index(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Ranklist")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	this.Data["URL"] = "/ranklist"

	// Page
	if _, ok := args["page"]; !ok {
		args["page"] = "1"
	}

	userModel := model.UserModel{}
	userList, err := userModel.List(nil)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	var count int
	count = 1
	for _, one := range userList {
		if one.Status == config.StatusAvailable {
			count += 1
		}
	}

	var pageCount = (count-1)/config.UserPerPage + 1
	page, err := strconv.Atoi(args["page"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}
	if page > pageCount {
		http.Error(w, "args error", 400)
		return
	}

	pageData := this.GetPage(page, pageCount)
	for k, v := range pageData {
		this.Data[k] = v
	}

	qry := make(map[string]string)
	qry["offset"] = strconv.Itoa((page - 1) * config.UserPerPage)
	qry["limit"] = strconv.Itoa(config.UserPerPage)
	userList, err = userModel.List(qry)
	if err != nil {

	}

	list := make([]rank, len(userList), len(userList))
	count = 1
	for i, one := range userList {
		list[i].User = *one
		if one.Status == config.StatusAvailable {
			list[count-1].Index = count
			count += 1
		}
	}
	this.Data["User"] = list
	this.Data["Title"] = "Ranklist"
	this.Data["IsRanklist"] = true
	err = this.Execute(w, "view/layout.tpl", "view/ranklist.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}