示例#1
0
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)
}
示例#2
0
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)
	}
}
示例#3
0
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)
}
示例#4
0
文件: user.go 项目: nangong92t/go_src
// 获取我的黑名单列表
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)
}
示例#5
0
文件: user.go 项目: nangong92t/go_src
// 拉黑某用户
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)
}
示例#6
0
文件: user.go 项目: nangong92t/go_src
// 设置用户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)
}
示例#7
0
文件: user.go 项目: nangong92t/go_src
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)
}
示例#8
0
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)
}
示例#9
0
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)
}
示例#10
0
文件: user.go 项目: nangong92t/go_src
func (c User) GetUserByName(name string) r.Result {
	userModule := modules.NewUser(c.Db)
	user := userModule.GetUserByName(name)

	return c.Render(user, nil)
}
示例#11
0
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)
}