Ejemplo n.º 1
0
// 验证数据
func (this *profileManagerImpl) validateProfile(v *member.Profile) error {
	v.Name = strings.TrimSpace(v.Name)
	v.Email = strings.ToLower(strings.TrimSpace(v.Email))
	v.Phone = strings.TrimSpace(v.Phone)

	if len([]rune(v.Name)) < 1 {
		return member.ErrNilNickName
	}

	if len(v.Email) != 0 && !emailRegex.MatchString(v.Email) {
		return member.ErrEmailValidErr
	}
	if len(v.Phone) != 0 && !phoneRegex.MatchString(v.Phone) {
		return member.ErrPhoneValidErr
	}

	if len(v.Phone) > 0 && this.phoneIsExist(v.Phone) {
		return member.ErrPhoneHasBind
	}

	//if len(v.Qq) != 0 && !qqRegex.MatchString(v.Qq) {
	//	return member.ErrQqValidErr
	//}
	return nil
}
Ejemplo n.º 2
0
// 注册会员
func (this *memberService) RegisterMember(merchantId int, v *member.Member,
	pro *member.Profile, cardId string, invitationCode string) (int, error) {
	invitationId, err := this._rep.GetManager().CheckPostedRegisterInfo(v, pro, invitationCode)
	if err == nil {
		m := this._rep.CreateMember(v) //创建会员
		id, err := m.Save()
		if err == nil {
			pro.MemberId = id
			if len(pro.Name) == 0 {
				//如果未设置昵称,则默认为用户名
				pro.Name = "用户" + v.Usr
			}
			if len(pro.Avatar) == 0 {
				pro.Avatar = "res/no_avatar.gif"
			}
			err = m.Profile().SaveProfile(pro)
			if err == nil {
				// 保存关联信息
				rl := m.GetRelation()
				rl.RefereesId = invitationId
				rl.RegisterMerchantId = merchantId
				rl.CardId = cardId
				return id, m.SaveRelation(rl)
			}
		}
	}
	return -1, err
}
Ejemplo n.º 3
0
// 拷贝资料
func (this *profileManagerImpl) copyProfile(v, dst *member.Profile) error {
	v.Address = strings.TrimSpace(v.Address)
	v.Im = strings.TrimSpace(v.Im)
	v.Email = strings.TrimSpace(v.Email)
	v.Phone = strings.TrimSpace(v.Phone)
	v.Name = strings.TrimSpace(v.Name)
	v.Ext1 = strings.TrimSpace(v.Ext1)
	v.Ext2 = strings.TrimSpace(v.Ext2)
	v.Ext3 = strings.TrimSpace(v.Ext3)
	v.Ext4 = strings.TrimSpace(v.Ext4)
	v.Ext5 = strings.TrimSpace(v.Ext5)
	v.Ext6 = strings.TrimSpace(v.Ext6)
	if err := this.validateProfile(v); err != nil {
		return err
	}

	//pro.Avatar = "res/no_avatar.gif"
	//pro.BirthDay = "1970-01-01"
	//
	//// 如果昵称为空,则跟用户名相同
	//if len(pro.Name) == 0 {
	//    pro.Name = m.Usr
	//}
	dst.Province = v.Province
	dst.City = v.City
	dst.District = v.District
	dst.Address = v.Address
	dst.BirthDay = v.BirthDay
	dst.Im = v.Im
	dst.Email = v.Email
	dst.Phone = v.Phone
	dst.Name = v.Name
	dst.Sex = v.Sex
	dst.Remark = v.Remark
	dst.Ext1 = v.Ext1
	dst.Ext2 = v.Ext2
	dst.Ext3 = v.Ext3
	dst.Ext4 = v.Ext4
	dst.Ext5 = v.Ext5
	dst.Ext6 = v.Ext6
	if v.Avatar != "" {
		dst.Avatar = v.Avatar
	}
	return nil
}