示例#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
}
示例#2
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
}
示例#3
0
文件: manager.go 项目: yonglehou/go2o
// 检查注册信息是否正确
func (this *MemberManagerImpl) CheckPostedRegisterInfo(v *member.Member,
	pro *member.Profile, invitationCode string) (invitationId int, err error) {
	perm := this._valRep.GetRegisterPerm()

	//验证用户名
	v.Usr = strings.TrimSpace(v.Usr)
	if len(v.Usr) < 6 {
		return 0, member.ErrUsrLength
	}
	if !userRegex.MatchString(v.Usr) {
		return 0, member.ErrUsrValidErr
	}
	if this._rep.CheckUsrExist(v.Usr, 0) {
		return 0, member.ErrUsrExist
	}

	//验证密码
	v.Pwd = strings.TrimSpace(v.Pwd)
	if len(v.Pwd) < 6 {
		return 0, member.ErrPwdLength
	}

	//验证手机
	pro.Phone = strings.TrimSpace(pro.Phone)
	l := len(pro.Phone)
	if perm.NeedPhone && l == 0 {
		return 0, member.ErrMissingPhone
	}
	if l > 0 {
		if !phoneRegex.MatchString(pro.Phone) {
			return 0, member.ErrBadPhoneFormat
		}
		if b := this._rep.CheckPhoneBind(pro.Phone, v.Id); b {
			return 0, member.ErrPhoneHasBind
		}
	}

	//验证IM
	pro.Im = strings.TrimSpace(pro.Im)
	if perm.NeedIm && len(pro.Im) == 0 {
		return 0, errors.New(strings.Replace(member.ErrMissingIM.Error(),
			"IM", variable.AliasMemberIM, -1))
	}

	// 检查验证码
	err = this.RegisterPerm(len(invitationCode) > 0)
	if err == nil {
		invitationId, err = this.checkInvitationCode(invitationCode)
	}
	return invitationId, err
}