Beispiel #1
0
func (user *User) Update() error {

	oldUser := &User{
		UserId: user.UserId,
	}

	if exists, err := oldUser.Get(); err != nil {
		return fmt.Errorf("update user, get old user error(%v)", err)
	} else if !exists {
		return fmt.Errorf("update user, old user not exists(%v)", oldUser)
	}

	// todo 需要合并一些信息
	if user.Password != "" {
		user.Password = util.Md5Hash(user.Password)
	}

	user.Updated = util.Now()

	if _, err := __handle.Update(user); err != nil {
		return fmt.Errorf("update user(%v), error(%v)", user, err)
	}

	return nil
}
func JoinCommunity(communityId int, userId int) error {

	communityUser := &CommunityUser{
		CommunityId: communityId,
		UserId:      userId,
	}

	exists, err := communityUser.Get()
	if err != nil {
		return err
	}

	if !exists {
		return fmt.Errorf("没有申请过这个社区")
	}

	if communityUser.Status != COMMUNITY_USER_STATUS_JOINED {
		communityUser.Status = COMMUNITY_USER_STATUS_JOINED
		communityUser.Joined = util.Now()
		_, err := __handle.Update(communityUser)

		return err
	}

	return nil
}
Beispiel #3
0
func (userAccount *UserAccount) Add() error {

	userAccount.Created = util.Now()
	userAccount.Verified = VERIFIED_CONFIRM

	return __handle.Insert(userAccount)
}
Beispiel #4
0
func (community *Community) Add() error {

	if community.Status == 0 {
		community.Status = COMMUNITY_STATUS_NORMAL
	}

	if community.CategoryId == 0 {
		community.CategoryId = conf.CATE_OTHER
	}

	if community.OwnerUserId == 0 {
		community.OwnerUserId = community.CreatedUserId
	}

	community.Created = util.Now()
	community.Activated = community.Created
	community.Status = COMMUNITY_STATUS_NORMAL

	if err := __handle.Insert(community); err != nil {
		return err
	}

	// 将创建人加入到该关系中
	communityUser := &CommunityUser{
		CommunityId: community.CommunityId,
		UserId:      community.OwnerUserId,
		Status:      COMMUNITY_USER_STATUS_JOINED,
		Role:        COMMUNITY_ROLE_ADMIN,
		Joined:      util.Now(),
	}

	if err := communityUser.Add(); err != nil {
		return err
	}

	return nil
}
Beispiel #5
0
func (user *User) Add() error {

	if user.Status == 0 {
		user.Status = USER_STATUS_NORMAL
	}

	if user.Created == "" {
		user.Created = util.Now()
	}

	// 密码调整为md5编码
	user.Password = util.Md5Hash(user.Password)

	return __handle.Insert(user)
}
func (communityUser *CommunityUser) Add() error {

	if communityUser.CommunityId == 0 || communityUser.UserId == 0 {
		return fmt.Errorf("社区关系添加错误,用户或者社区有误")
	}

	if communityUser.Status == 0 {
		communityUser.Status = COMMUNITY_USER_STATUS_APPLY
	}

	if communityUser.Role == 0 {
		communityUser.Role = COMMUNITY_ROLE_MEMBER
	}

	communityUser.CommunityUserId = generateCommunityUserId(communityUser.CommunityId, communityUser.UserId)
	communityUser.Created = util.Now()

	return __handle.Insert(communityUser)
}
Beispiel #7
0
func (community *Community) Update() error {

	oldCommunity := &Community{
		CommunityId: community.CommunityId,
	}

	if exists, err := oldCommunity.Get(); err != nil {
		return fmt.Errorf("update community(%v), get old community error(%v)", community, err)
	} else if !exists {
		return fmt.Errorf("update community(%v), community not exists", community)
	}

	community.Updated = util.Now()

	if _, err := __handle.Update(community); err != nil {
		return fmt.Errorf("update community(%v), db error(%v)", community, err)
	}

	return nil
}
Beispiel #8
0
func (community *Community) Delete() error {

	oldCommunity := &Community{
		CommunityId: community.CommunityId,
	}

	if exists, err := oldCommunity.Get(); err != nil {
		return fmt.Errorf("delete community(%v), get old community error(%v)", community, err)
	} else if !exists {
		return fmt.Errorf("delete community(%v), community not exists", community)
	}

	community.Deleted = util.Now()
	community.Status = COMMUNITY_STATUS_DELETED

	if _, err := __handle.Update(community); err != nil {
		return fmt.Errorf("delete community(%v), db error(%v)", community, err)
	}

	return nil
}