func (c Account) Register(username string, password string) r.Result { userModule := modules.NewUser(c.Db) user, err := userModule.AddNew(username, password) return c.Render(user, err) }
func (c Account) Login(username string, password string) r.Result { if username == "" || password == "" { return c.Render(nil, errors.New("the params error!")) } userModule := modules.NewUser(c.Db) user := userModule.GetUserByName(username) var err error if user.IsDel == 1 { return c.Render(nil, errors.New("Sorry, this account has been deleted!")) } if user.Password == password { response := map[string]interface{}{ "session": c.Sess.Build(&user), "user": &user, } return c.Render(response, nil) } else { err = errors.New("Sorry, username or password is wrong.") return c.Render(nil, err) } }
func (c Account) ChangePassword(sid string, password string) r.Result { session := c.Sess.GetSession(sid) if session.Id == 0 { return c.RenderLogin() } err := modules.NewUser(c.Db).ChangePassword(session.SessionVal.UserId, password) return c.Render(true, err) }
// 获取我的黑名单列表 func (c User) GetBlockedUsers(sid string, page int, limit int) r.Result { session := c.Sess.GetSession(sid) if session.Id == 0 { return c.RenderLogin() } blockedUsers, err := modules.NewUser(c.Db).GetBlockedUsers(session.SessionVal.UserId, page, limit) return c.Render(blockedUsers, err) }
// 拉黑某用户 func (c User) Block(sid string, blocked int64) r.Result { session := c.Sess.GetSession(sid) if session.Id == 0 { return c.RenderLogin() } err := modules.NewUser(c.Db).Block(session.SessionVal.UserId, blocked, c.Sess.IsAdmin()) return c.Render(true, err) }
// 设置用户Profile[TODO]. func (c User) Setting(sid string, gender int, age int, lllness int) r.Result { session := c.Sess.GetSession(sid) if session.Id == 0 { return c.RenderLogin() } res, err := modules.NewUser(c.Db).SettingProfile(session.SessionVal.UserId, gender, age, lllness) return c.Render(res, err) }
func (c User) GetUsers(userId int) r.Result { greeting := "It works!" userModule := modules.NewUser(c.Db) users := userModule.GetUsers() c.Session["user_name"] = greeting return c.RenderJson(users) }
func (c Admin) RemoveUsers(sid string, ids string, withPost bool) r.Result { c.Sess.GetSession(sid) if !c.Sess.IsAdmin() { return c.RenderNoAdmin() } uid := helpers.GetArrayFromString(ids) res, err := modules.NewUser(c.Db).RemoveUsers(uid) if withPost { res, err = modules.NewTopic(c.Db, c.Rc).RemoveUsersTopics(uid) } return c.Render(res, err) }
func (c Admin) GetUserList(sid string, page, limit int, utype string) r.Result { c.Sess.GetSession(sid) if !c.Sess.IsAdmin() { return c.RenderNoAdmin() } userModule := modules.NewUser(c.Db) var list modules.Pager var err error switch utype { case "active": list, err = userModule.GetMostPostUserList(page, limit, 20) case "blocked": list, err = userModule.GetBlockUserList(page, limit, true) case "block": list, err = userModule.GetBlockUserList(page, limit, false) default: return c.Render(nil, errors.New("Sorry, the utype error!")) } return c.Render(list, err) }
func (c User) GetUserByName(name string) r.Result { userModule := modules.NewUser(c.Db) user := userModule.GetUserByName(name) return c.Render(user, nil) }
func (c Admin) GetAllStat(sid string, date string) r.Result { c.Sess.GetSession(sid) if !c.Sess.IsAdmin() { return c.RenderNoAdmin() } if date == "" { return c.Render(nil, errors.New("Sorry, no date.")) } dateInt, err := time.Parse("2006/01/02", date) if err != nil { return c.Render(nil, err) } dateUInt := dateInt.Unix() userModule := modules.NewUser(c.Db) topicModule := modules.NewTopic(c.Db, c.Rc) // get user stat data. userStat, err := userModule.GetStat(dateUInt) if err != nil { return c.Render(nil, err) } // get topic stat data. topicStat, err := topicModule.GetStat(dateUInt) if err != nil { return c.Render(nil, err) } // get comment stat data. commentStat, err := topicModule.GetCommentStat(dateUInt) if err != nil { return c.Render(nil, err) } // get user date news count. userDateNews, err := userModule.GetOneMonthDateNewCnt(dateUInt) if err != nil { return c.Render(nil, err) } // get topic date news count. topicDateNews, err := topicModule.GetOneMonthDateNewCnt(dateUInt) if err != nil { return c.Render(nil, err) } // get comment date news count. commentDateNews, err := topicModule.GetCommOneMonthDateNewCnt(dateUInt) if err != nil { return c.Render(nil, err) } // response format response := map[string]interface{}{ "detail": map[string]interface{}{ "users": userStat, "topics": topicStat, "comments": commentStat, }, "date": map[string]interface{}{ "users": userDateNews, "topics": topicDateNews, "comments": commentDateNews, }, } return c.Render(response, nil) }