当前位置: 首页>>代码示例>>Golang>>正文


Golang model.UserModel类代码示例

本文整理汇总了Golang中GoOnlineJudge/model.UserModel的典型用法代码示例。如果您正苦于以下问题:Golang UserModel类的具体用法?Golang UserModel怎么用?Golang UserModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Update

//@URL: /profile @method: POST
func (uc *UserController) Update() {
	restweb.Logger.Debug("User Update")

	var one model.User
	one.Nick = uc.Input.Get("user[nick]")
	one.Mail = uc.Input.Get("user[mail]")
	one.School = uc.Input.Get("user[school]")
	one.Motto = uc.Input.Get("user[motto]")
	one.ShareCode, _ = strconv.ParseBool(uc.Input.Get("user[share_code]"))
	restweb.Logger.Debug(uc.Input.Get("user[share_code]"))
	restweb.Logger.Debug(one.ShareCode)

	if one.Nick == "" {
		hint := make(map[string]string)
		hint["nick"] = "Nick should not be empty."
		uc.W.WriteHeader(400)
		b, _ := json.Marshal(&hint)
		uc.W.Write(b)
	} else {
		userModel := model.UserModel{}
		err := userModel.Update(uc.Uid, one)
		if err != nil {
			http.Error(uc.W, err.Error(), 500)
			return
		}
		uc.W.WriteHeader(200)
	}
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:29,代码来源:user.go

示例2: Post

//@URL: /sess @method: POST
func (s *SessController) Post() {
	restweb.Logger.Debug("User Login")

	uid := s.Input.Get("user[handle]")
	pwd := s.Input.Get("user[password]")

	userModel := model.UserModel{}
	ret, err := userModel.Login(uid, pwd)
	if err != nil {
		restweb.Logger.Debug(err)
		s.Error(err.Error(), 500)
		return
	}

	if ret.Uid == "" {
		s.W.WriteHeader(400)
	} else {
		s.SetSession("Uid", uid)
		s.SetSession("Privilege", strconv.Itoa(ret.Privilege))
		s.W.WriteHeader(201)

		// remoteAddr := s.R.Header.Get("X-Real-IP")           // if you set niginx as reverse proxy
		remoteAddr := strings.Split(s.R.RemoteAddr, ":")[0] // otherwise
		userModel.RecordIP(uid, remoteAddr, time.Now().Unix())
	}
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:27,代码来源:sess.go

示例3: Detail

func (this *UserController) Detail(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Detail")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	uid := args["uid"]
	userModel := model.UserModel{}
	one, err := userModel.Detail(uid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	this.Data["Detail"] = one

	solutionModle := model.SolutionModel{}
	solvedList, err := solutionModle.Achieve(uid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	this.Data["List"] = solvedList
	//class.Logger.Debug(solvedList)
	this.Data["Title"] = "User Detail"
	if uid != "" && uid == this.Uid {
		this.Data["IsSettings"] = true
		this.Data["IsSettingsDetail"] = true
	}

	err = this.Execute(w, "view/layout.tpl", "view/user_detail.tpl")
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:35,代码来源:user.go

示例4: Edit

func (this *UserController) Edit(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Edit")
	this.Init(w, r)

	if this.Privilege == config.PrivilegeNA {
		this.Data["Title"] = "Warning"
		this.Data["Info"] = "You must login!"
		err := this.Execute(w, "view/layout.tpl", "view/400.tpl")
		if err != nil {
			http.Error(w, "tpl error", 500)
			return
		}
		return
	}

	uid := this.Uid
	userModel := model.UserModel{}
	one, err := userModel.Detail(uid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	this.Data["Detail"] = one

	this.Data["Title"] = "User Edit"
	this.Data["IsSettings"] = true
	this.Data["IsSettingsEdit"] = true

	err = this.Execute(w, "view/layout.tpl", "view/user_edit.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:34,代码来源:user.go

示例5: List

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
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:33,代码来源:user.go

示例6: Register

//@URL: /users @method:POST
func (uc *UserController) Register() {
	restweb.Logger.Debug("User Register")

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

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

	valid := restweb.Validation{}
	valid.MinSize(uid, 4, "uid")
	valid.Match(uid, "\\w+", "uid")

	if !valid.HasError {
		_, err := userModel.Detail(uid)
		if err != nil && err != model.NotFoundErr {
			http.Error(uc.W, err.Error(), 500)
			return
		} else if err == nil {
			valid.AppendError("uid", "Handle is currently in use.")
		}
	}

	valid.Required(nick, "nick")
	valid.MinSize(pwd, 6, "pwd")
	valid.Equal(pwd, pwdConfirm, "pwdConfirm")
	valid.Mail(one.Mail, "mail")

	if !valid.HasError {
		one.Uid = uid
		one.Nick = nick
		one.Pwd = pwd
		one.Privilege = config.PrivilegePU

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

		uc.W.Header().Add("Location", "/users/"+uid)
		uc.W.WriteHeader(201)
	} else {
		hint := valid.RenderErrMap()
		b, _ := json.Marshal(&hint)
		uc.W.WriteHeader(400)
		uc.W.Write(b)
	}
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:55,代码来源:user.go

示例7: Password

func (this *UserController) Password(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Password")
	this.Init(w, r)

	ok := 1
	hint := make(map[string]string)
	hint["uid"] = this.Uid

	data := make(map[string]string)
	data["oldPassword"] = r.FormValue("user[oldPassword]")
	data["newPassword"] = r.FormValue("user[newPassword]")
	data["confirmPassword"] = r.FormValue("user[confirmPassword]")

	uid := this.Uid
	pwd := data["oldPassword"]

	userModel := model.UserModel{}
	ret, err := userModel.Login(uid, pwd)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if ret.Uid == "" {
		ok, hint["oldPassword"] = 0, "Old Password is Incorrect."
	}
	if len(data["newPassword"]) < 6 {
		ok, hint["newPassword"] = 0, "Password should contain at least six characters."
	}
	if data["newPassword"] != data["confirmPassword"] {
		ok, hint["confirmPassword"] = 0, "Confirmation mismatched."
	}

	if ok == 1 {
		pwd = data["newPassword"]
		err := userModel.Password(uid, pwd)
		if err != nil {
			http.Error(w, err.Error(), 400)
			return
		}

		w.WriteHeader(200)
	} else {
		w.WriteHeader(400)
	}
	b, err := json.Marshal(&hint)
	if err != nil {
		http.Error(w, "json error", 400)
		return
	}

	w.Write(b)
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:53,代码来源:user.go

示例8: Edit

//@URL: /profile @method: GET
func (uc *UserController) Edit() {
	restweb.Logger.Debug("User Edit")

	uid := uc.Uid
	userModel := model.UserModel{}
	one, err := userModel.Detail(uid)
	if err != nil {
		uc.Error(err.Error(), 400)
		return
	}
	uc.Output["Detail"] = one

	uc.Output["Title"] = "User Edit"
	uc.Output["IsSettings"] = true
	uc.Output["IsSettingsEdit"] = true

	uc.RenderTemplate("view/layout.tpl", "view/user_edit.tpl")
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:19,代码来源:user.go

示例9: Detail

//@URL: /users/(.+) @method: GET
func (uc *UserController) Detail(uid string) {
	restweb.Logger.Debug("User Detail", uid)

	userModel := model.UserModel{}
	one, err := userModel.Detail(uid)
	if err != nil {
		uc.Error(err.Error(), 400)
		return
	}
	uc.Output["Detail"] = one

	solutionModle := model.SolutionModel{}
	solvedList, err := solutionModle.Achieve(uid, config.ModuleP, config.ModuleP)
	if err != nil {
		uc.Error(err.Error(), 400)
		return
	}

	type IPs struct {
		Time int64
		IP   string
	}
	var ips []IPs
	ipo := IPs{}

	for i, lenth := 0, len(one.IPRecord); i < lenth; i++ {
		ipo.Time = one.TimeRecord[i]
		ipo.IP = one.IPRecord[i]
		ips = append(ips, ipo)
	}

	achieveList := sort.IntSlice(solvedList)
	achieveList.Sort()
	uc.Output["List"] = achieveList
	uc.Output["IpList"] = ips
	uc.Output["Title"] = "User Detail"
	if uid != "" && uid == uc.Uid {
		uc.Output["IsSettings"] = true
		uc.Output["IsSettingsDetail"] = true
	}

	uc.RenderTemplate("view/layout.tpl", "view/user_detail.tpl")
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:44,代码来源:user.go

示例10: Settings

func (this *UserController) Settings(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Settings")
	this.Init(w, r)

	if this.Privilege == config.PrivilegeNA {
		this.Data["Title"] = "Warning"
		this.Data["Info"] = "You must login!"
		err := this.Execute(w, "view/layout.tpl", "view/400.tpl")
		if err != nil {
			http.Error(w, "tpl error", 500)
			return
		}
		return
	}

	userModel := model.UserModel{}

	one, err := userModel.Detail(this.Uid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	this.Data["Detail"] = one

	solutionModel := model.SolutionModel{}
	solvedList, err := solutionModel.Achieve(this.Uid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	this.Data["List"] = solvedList

	this.Data["Title"] = "User Settings"
	this.Data["IsSettings"] = true
	this.Data["IsSettingsDetail"] = true

	err = this.Execute(w, "view/layout.tpl", "view/user_detail.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:42,代码来源:user.go

示例11: Password

//@URL: /account @method: POST
func (uc *UserController) Password() {
	restweb.Logger.Debug("User Password")

	valid := restweb.Validation{}

	uid := uc.Uid
	// valid.AppendError("uid", uid)

	oldPwd := uc.Input.Get("user[oldPassword]")
	newPwd := uc.Input.Get("user[newPassword]")
	confirmPwd := uc.Input.Get("user[confirmPassword]")

	userModel := model.UserModel{}
	ret, err := userModel.Login(uid, oldPwd)
	if err != nil {
		uc.Error(err.Error(), 500)
		return
	}

	if ret.Uid == "" {
		valid.AppendError("oldPassword", "Old Password is Incorrect.")
	}
	valid.MinSize(newPwd, 6, "newPassword")
	valid.Equal(newPwd, confirmPwd, "confirmPassword")

	if !valid.HasError {
		err := userModel.Password(uid, newPwd)
		if err != nil {
			uc.Error(err.Error(), 400)
			return
		}

		uc.W.WriteHeader(200)
	} else {
		uc.W.WriteHeader(400)
	}
	hint := valid.RenderErrMap()
	b, _ := json.Marshal(&hint)
	uc.W.Write(b)
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:41,代码来源:user.go

示例12: UpdateRecord

func (this *solution) UpdateRecord() {
	if this.Module != config.ModuleP {
		return
	}

	solutionModel := model.SolutionModel{}
	qry := make(map[string]string)
	qry["module"] = strconv.Itoa(config.ModuleP)
	qry["action"] = "submit"
	qry["pid"] = strconv.Itoa(this.Pid)

	submit, _ := solutionModel.Count(qry)

	qry["action"] = "solve"
	solve, _ := solutionModel.Count(qry)

	proModel := model.ProblemModel{}
	err := proModel.Record(this.Pid, solve, submit)
	if err != nil {
		logger.Println(err)
	}

	qry["action"] = "submit"
	qry["uid"] = this.Uid
	delete(qry, "pid")
	delete(qry, "module")
	submit, _ = solutionModel.Count(qry)

	solvelist, err := solutionModel.Achieve(this.Uid, config.ModuleP, config.ModuleP)
	if err != nil {
		logger.Println(err)
	}
	solve = len(solvelist)

	userModel := model.UserModel{}
	err = userModel.Record(this.Uid, solve, submit)
	if err != nil {
		logger.Println(err)
	}
}
开发者ID:B88000005,项目名称:RunServer,代码行数:40,代码来源:judge.go

示例13: Privilegeset

func (this *UserController) Privilegeset(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Privilege")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	uid := args["uid"]
	privilegeStr := args["type"]

	privilege := config.PrivilegeNA
	switch privilegeStr {
	case "Admin":
		privilege = config.PrivilegeAD
	case "TC":
		privilege = config.PrivilegeTC
	case "PU":
		privilege = config.PrivilegePU
	default:
		http.Error(w, "args error", 400)
	}

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

	if uid == "" {
		ok, hint["uid"] = 0, "Handle should not be empty."
	} else if uid == this.Uid {
		ok, hint["uid"] = 0, "You cannot delete yourself"
	} else {
		userModel := model.UserModel{}
		_, err := userModel.Detail(uid)
		if err == model.NotFoundErr {
			ok, hint["uid"] = 0, "This handle does not exist!"
		} else if err != nil {
			http.Error(w, err.Error(), 400)
			return
		}
	}

	if ok == 1 {
		userModel := model.UserModel{}
		err := userModel.Privilege(uid, privilege)
		if err != nil {
			http.Error(w, err.Error(), 400)
			return
		}

		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)
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:58,代码来源:user.go

示例14: Update

func (this *UserController) Update(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Update")
	this.Init(w, r)

	ok := 1
	hint := make(map[string]string)
	hint["uid"] = this.Uid

	var one model.User
	one.Nick = r.FormValue("user[nick]")
	one.Mail = r.FormValue("user[mail]")
	one.School = r.FormValue("user[school]")
	one.Motto = r.FormValue("user[motto]")

	if one.Nick == "" {
		ok, hint["nick"] = 0, "Nick should not be empty."
	}

	if ok == 1 {
		userModel := model.UserModel{}
		err := userModel.Update(this.Uid, one)
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}
		w.WriteHeader(200)
	} else {
		w.WriteHeader(400)
	}

	b, err := json.Marshal(&hint)
	if err != nil {
		http.Error(w, "json error", 400)
		return
	}
	w.Write(b)
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:37,代码来源:user.go

示例15: Login

func (this *UserController) Login(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("User Login")
	this.Init(w, r)

	uid := r.FormValue("user[handle]")
	pwd := r.FormValue("user[password]")

	userModel := model.UserModel{}
	ret, err := userModel.Login(uid, pwd)
	if err != nil {
		class.Logger.Debug(err)
		http.Error(w, err.Error(), 500)
		return
	}

	if ret.Uid == "" {
		w.WriteHeader(400)
	} else {
		this.SetSession(w, r, "Uid", uid)
		this.SetSession(w, r, "Privilege", strconv.Itoa(ret.Privilege))
		w.WriteHeader(200)
	}
	return
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:24,代码来源:user.go


注:本文中的GoOnlineJudge/model.UserModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。