Esempio n. 1
0
// 创建会员
func (this *memberImpl) create(m *member.Member, pro *member.Profile) (int, error) {
	//todo: 获取推荐人编号
	//todo: 检测是否有注册权限
	//if err := this._manager.RegisterPerm(this._relation.RefereesId);err != nil{
	//	return -1,err
	//}
	if this.usrIsExist(m.Usr) {
		return -1, member.ErrUsrExist
	}

	t := time.Now().Unix()
	m.State = 1
	m.RegTime = t
	m.LastLoginTime = t
	m.Level = 1
	m.Exp = 1
	m.DynamicToken = m.Pwd
	m.Exp = 0
	if len(m.RegFrom) == 0 {
		m.RegFrom = "API-INTERNAL"
	}
	m.InvitationCode = this.generateInvitationCode() // 创建一个邀请码
	id, err := this._rep.SaveMember(m)
	if id != 0 {
		this._value.Id = id
	}
	return id, err
}
Esempio n. 2
0
// 检查注册信息是否正确
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
}
Esempio n. 3
0
// 设置值
func (this *memberImpl) SetValue(v *member.Member) error {
	v.Usr = this._value.Usr
	if len(this._value.InvitationCode) == 0 {
		this._value.InvitationCode = v.InvitationCode
	}
	if v.Exp != 0 {
		this._value.Exp = v.Exp
	}
	if v.Level > 0 {
		this._value.Level = v.Level
	}
	if len(v.TradePwd) == 0 {
		this._value.TradePwd = v.TradePwd
	}
	return nil
}
Esempio n. 4
0
func (this *MemberRep) createMember(v *member.Member) (int, error) {
	var id int64
	_, id, err := this.Connector.GetOrm().Save(nil, v)
	if err != nil {
		return -1, err
	}
	v.Id = int(id)
	this.initMember(v)

	rc := core.GetRedisConn()
	defer rc.Close()
	rc.Do("RPUSH", variable.KvMemberUpdateQueue,
		fmt.Sprintf("%d-create", v.Id)) // push to queue

	// 更新会员数 todo: 考虑去掉
	var total = 0
	this.Connector.ExecScalar("SELECT COUNT(0) FROM mm_member", &total)
	gof.CurrentApp.Storage().Set(variable.KvTotalMembers, total)

	return v.Id, err
}