Ejemplo n.º 1
0
func friendCountHandler(request *http.Request, resp http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account) {
	follows, followers, friends, blacklist := redis.FriendCount(user.Id)
	respData := map[string]int{
		"friend_count":    friends,
		"attention_count": follows,
		"fans_count":      followers,
		"defriend_count":  blacklist,
	}
	writeResponse(request.RequestURI, resp, respData, nil)
}
Ejemplo n.º 2
0
func adminLoginHandler(w http.ResponseWriter, redis *models.RedisLogger, form jsgenLoginForm) {
	user := &models.Account{}

	log.Println(form.Username, form.Password)
	h := md5.New()
	io.WriteString(h, form.Password)
	pwd := fmt.Sprintf("%x", h.Sum(nil))

	find := false
	var err error
	if find, err = user.FindByUserPass(strings.ToLower(form.Username), pwd); !find {
		if err == nil {
			err = AuthError
		} else {
			err = DbError
		}
	}

	if err != nil {
		writeResponse(w, false, nil, nil, err)
		return
	}

	redis.LogLogin(user.Id)

	info := &User{
		Id:          user.Id,
		Name:        user.Nickname,
		Nickname:    user.Nickname,
		Email:       "",
		Locked:      user.TimeLimit != 0,
		Social:      social{},
		Sex:         user.Gender,
		Role:        1,
		Avatar:      user.Profile,
		Desc:        user.About,
		Date:        user.RegTime.Unix() * 1000,
		Score:       user.Score,
		ReadTime:    0,
		LastLogin:   user.LastLogin.Unix() * 1000,
		FollowList:  redis.Friends(models.RelFollowing, user.Id),
		TagsList:    []string{},
		Articles:    user.ArticleCount(),
		Collections: 0,
		MarkList:    []int{},
		Unread:      []string{},
		ReceiveList: []string{},
		SendList:    []string{},
	}
	info.Follow, info.Fans, _, _ = redis.FriendCount(user.Id)

	writeResponse(w, true, info, nil, nil)
}
Ejemplo n.º 3
0
func convertUser(user *models.Account, redis *models.RedisLogger) *userJsonStruct {
	info := &userJsonStruct{
		Userid:   user.Id,
		Nickname: user.Nickname,
		Email:    user.Email,
		Phone:    user.Phone,
		Type:     user.Role,
		About:    user.About,
		Profile:  user.Profile,
		RegTime:  user.RegTime.Unix(),
		Height:   user.Height,
		Weight:   user.Weight,
		Birth:    user.Birth,
		Actor:    user.Actor,
		Location: user.Loc,
		Addr:     user.LocAddr,

		Sign:        user.Sign,
		Emotion:     user.Emotion,
		Profession:  user.Profession,
		Hometown:    user.Hometown,
		OftenAppear: user.Oftenappear,
		Hobby:       user.Hobby,

		//Rank:   userRank(user.Level),
		Online: redis.IsOnline(user.Id),
		Gender: user.Gender,
		//Follows:   len(redis.Follows(user.Id)),
		//Followers: len(redis.Followers(user.Id)),
		Posts: user.ArticleCount(),

		//Props: redis.UserProps(user.Id),
		Props: models.Props{
			Physical: user.Props.Physical,
			Literal:  user.Props.Literal,
			Mental:   user.Props.Mental,
			Wealth:   redis.GetCoins(user.Id),
			Score:    user.Props.Score,
			Level:    user.Level(),
		},

		Photos:     user.Photos,
		CoverImage: user.CoverImage,

		Wallet:  user.Wallet.Addr,
		LastLog: user.LastLogin.Unix(),
		Setinfo: user.Setinfo,
		Ban:     user.TimeLimit,
		Auth:    user.Auth,
	}

	balance, _ := getBalance(user.Wallet.Addrs)
	var wealth int64
	if balance != nil {
		for _, b := range balance.Addrs {
			wealth += (b.Confirmed + b.Unconfirmed)
		}
	}
	info.Props.Wealth = wealth

	info.Follows, info.Followers, _, _ = redis.FriendCount(user.Id)

	/*
		if user.Privilege == 5 {
			info.Actor = "coach"
		} else if user.Privilege == 10 {
			info.Actor = "admin"
		}

			if user.Addr != nil {
				info.Addr = user.Addr.String()
			}
	*/

	if user.Equips != nil {
		info.Equips = *user.Equips
	}

	if info.Auth != nil {
		if info.Auth.IdCard == nil {
			info.Auth.IdCard = info.Auth.IdCardTmp
		}
		if info.Auth.Cert == nil {
			info.Auth.Cert = info.Auth.CertTmp
		}
		if info.Auth.Record == nil {
			info.Auth.Record = info.Auth.RecordTmp
		}
	}

	return info
}