本文整理汇总了Golang中GoOnlineJudge/model.UserModel.Login方法的典型用法代码示例。如果您正苦于以下问题:Golang UserModel.Login方法的具体用法?Golang UserModel.Login怎么用?Golang UserModel.Login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GoOnlineJudge/model.UserModel
的用法示例。
在下文中一共展示了UserModel.Login方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
}
示例2: 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)
}
示例3: 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)
}
示例4: 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
}