func (this *UserController) EditPost() { cnname := strings.TrimSpace(this.GetString("cnname", "")) email := strings.TrimSpace(this.GetString("email", "")) phone := strings.TrimSpace(this.GetString("phone", "")) im := strings.TrimSpace(this.GetString("im", "")) qq := strings.TrimSpace(this.GetString("qq", "")) if utils.HasDangerousCharacters(cnname) { this.ServeErrJson("cnname is invalid") return } if utils.HasDangerousCharacters(email) { this.ServeErrJson("email is invalid") return } if utils.HasDangerousCharacters(phone) { this.ServeErrJson("phone is invalid") return } if utils.HasDangerousCharacters(im) { this.ServeErrJson("im is invalid") return } if utils.HasDangerousCharacters(qq) { this.ServeErrJson("qq is invalid") return } targetUser := this.Ctx.Input.GetData("TargetUser").(*User) if targetUser.Name == "root" { this.ServeErrJson("no privilege") return } targetUser.Cnname = cnname targetUser.Email = email targetUser.Phone = phone targetUser.IM = im targetUser.QQ = qq _, err := targetUser.Update() if err != nil { this.ServeErrJson("occur error " + err.Error()) return } this.ServeOKJson() }
func (this *UserController) Users() { query := strings.TrimSpace(this.GetString("query", "")) if utils.HasDangerousCharacters(query) { this.ServeErrJson("query is invalid") return } per := this.MustGetInt("per", 20) users := QueryUsers(query) total, err := users.Count() if err != nil { this.ServeErrJson("occur error " + err.Error()) return } pager := this.SetPaginator(per, total) users = users.Limit(per, pager.Offset()) var us []User _, err = users.All(&us) if err != nil { this.ServeErrJson("occur error " + err.Error()) return } me := this.Ctx.Input.GetData("CurrentUser").(*User) this.Data["Users"] = us this.Data["Query"] = query this.Data["Me"] = me this.Data["IamRoot"] = me.Name == "root" this.Data["Shortcut"] = g.Config().Shortcut this.TplName = "user/list.html" }
func (this *TeamController) EditPost() { targetTeam := this.Ctx.Input.GetData("TargetTeam").(*Team) resume := this.MustGetString("resume", "") userIdstr := this.MustGetString("users", "") if utils.HasDangerousCharacters(resume) || utils.HasDangerousCharacters(userIdstr) { this.ServeErrJson("parameter resume or users is invalid") return } if targetTeam.Resume != resume { targetTeam.Resume = resume targetTeam.Update() } this.AutoServeError(targetTeam.UpdateUsers(userIdstr)) }
func (this *TeamController) CreateTeamPost() { name := strings.TrimSpace(this.GetString("name", "")) if name == "" { this.ServeErrJson("name is blank") return } if utils.HasDangerousCharacters(name) { this.ServeErrJson("name is invalid") return } resume := strings.TrimSpace(this.GetString("resume", "")) if utils.HasDangerousCharacters(resume) { this.ServeErrJson("resume is invalid") return } t := ReadTeamByName(name) if t != nil { this.ServeErrJson("name is already existent") return } me := this.Ctx.Input.GetData("CurrentUser").(*User) lastId, err := SaveTeamAttrs(name, resume, me.Id) if err != nil { this.ServeErrJson("occur error " + err.Error()) return } uids := strings.TrimSpace(this.GetString("users", "")) if utils.HasDangerousCharacters(uids) { this.ServeErrJson("uids is invalid") return } err = PutUsersInTeam(lastId, uids) if err != nil { this.ServeErrJson("occur error " + err.Error()) } else { this.ServeOKJson() } }
// 更新个人信息 func (this *UserController) ProfilePost() { cnname := strings.TrimSpace(this.GetString("cnname", "")) email := strings.TrimSpace(this.GetString("email", "")) phone := strings.TrimSpace(this.GetString("phone", "")) im := strings.TrimSpace(this.GetString("im", "")) qq := strings.TrimSpace(this.GetString("qq", "")) if utils.HasDangerousCharacters(cnname) { this.ServeErrJson("cnname is invalid") return } if utils.HasDangerousCharacters(email) { this.ServeErrJson("email is invalid") return } if utils.HasDangerousCharacters(phone) { this.ServeErrJson("phone is invalid") return } if utils.HasDangerousCharacters(im) { this.ServeErrJson("im is invalid") return } if utils.HasDangerousCharacters(qq) { this.ServeErrJson("qq is invalid") return } me := this.Ctx.Input.GetData("CurrentUser").(*User) me.Cnname = cnname me.Email = email me.Phone = phone me.IM = im me.QQ = qq me.Update() this.ServeOKJson() }
func (this *UserController) Query() { query := strings.TrimSpace(this.GetString("query", "")) limit := this.MustGetInt("limit", 10) if utils.HasDangerousCharacters(query) { this.ServeErrJson("query is invalid") return } var users []User QueryUsers(query).Limit(limit).All(&users, "Id", "Name", "Cnname", "Email") this.Data["json"] = map[string]interface{}{"users": users} this.ServeJSON() }
func (this *TeamController) Teams() { query := strings.TrimSpace(this.GetString("query", "")) if utils.HasDangerousCharacters(query) { this.ServeErrJson("query is invalid") return } per := this.MustGetInt("per", 10) me := this.Ctx.Input.GetData("CurrentUser").(*User) teams, err := QueryMineTeams(query, me.Id) if err != nil { this.ServeErrJson("occur error " + err.Error()) return } total, err := teams.Count() if err != nil { this.ServeErrJson("occur error " + err.Error()) return } pager := this.SetPaginator(per, total) teams = teams.Limit(per, pager.Offset()) var ts []Team _, err = teams.All(&ts) if err != nil { this.ServeErrJson("occur error " + err.Error()) return } this.Data["Teams"] = ts this.Data["Query"] = query this.Data["Me"] = me this.Data["IamRoot"] = me.Name == "root" this.Data["Shortcut"] = g.Config().Shortcut this.TplName = "team/list.html" }
func (this *UserController) CreateUserPost() { name := strings.TrimSpace(this.GetString("name", "")) password := strings.TrimSpace(this.GetString("password", "")) cnname := strings.TrimSpace(this.GetString("cnname", "")) email := strings.TrimSpace(this.GetString("email", "")) phone := strings.TrimSpace(this.GetString("phone", "")) im := strings.TrimSpace(this.GetString("im", "")) qq := strings.TrimSpace(this.GetString("qq", "")) if !utils.IsUsernameValid(name) { this.ServeErrJson("name pattern is invalid") return } if ReadUserIdByName(name) > 0 { this.ServeErrJson("name is already existent") return } if password == "" { this.ServeErrJson("password is blank") return } if utils.HasDangerousCharacters(cnname) { this.ServeErrJson("cnname is invalid") return } if utils.HasDangerousCharacters(email) { this.ServeErrJson("email is invalid") return } if utils.HasDangerousCharacters(phone) { this.ServeErrJson("phone is invalid") return } if utils.HasDangerousCharacters(im) { this.ServeErrJson("im is invalid") return } if utils.HasDangerousCharacters(qq) { this.ServeErrJson("qq is invalid") return } lastId, err := InsertRegisterUser(name, str.Md5Encode(g.Config().Salt+password)) if err != nil { this.ServeErrJson("insert user fail " + err.Error()) return } targetUser := ReadUserById(lastId) targetUser.Cnname = cnname targetUser.Email = email targetUser.Phone = phone targetUser.IM = im targetUser.QQ = qq if _, err := targetUser.Update(); err != nil { this.ServeErrJson("occur error " + err.Error()) return } this.ServeOKJson() }