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 } }
//@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") }
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 } }
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) } }