Example #1
0
func (this *UserC) PostRegisterInfo_post(ctx *web.Context) {
	ctx.Request.ParseForm()
	var member member.ValueMember
	web.ParseFormToEntity(ctx.Request.Form, &member)
	if i := strings.Index(ctx.Request.RemoteAddr, ":"); i != -1 {
		member.RegIp = ctx.Request.RemoteAddr[:i]
	}

	var memberId int
	var err error

	if len(member.Usr) == 0 || len(member.Pwd) == 0 {
		err = errors.New("注册信息不完整")
	} else {
		member.Pwd = domain.Md5MemberPwd(member.Usr, member.Pwd)
		memberId, err = dps.MemberService.SaveMember(&member)
		if err == nil {
			invId := dps.MemberService.GetMemberIdByInvitationCode(ctx.Request.FormValue("inviCode"))
			err = dps.MemberService.SaveRelation(memberId, "", invId,
				this.BaseC.GetPartnerId(ctx))
		}
	}

	if err != nil {
		this.BaseC.ResultOutput(ctx, gof.Message{Message: "注册失败!错误:" + err.Error()})
	} else {
		this.BaseC.ResultOutput(ctx, gof.Message{Result: true})
	}
}
Example #2
0
func (this *Member) validate(v *member.ValueMember) error {
	v.Usr = strings.ToLower(strings.TrimSpace(v.Usr)) // 小写并删除空格
	v.Name = strings.TrimSpace(v.Name)
	v.Email = strings.ToLower(strings.TrimSpace(v.Email))
	v.Phone = strings.TrimSpace(v.Phone)

	if len([]rune(v.Usr)) < 6 {
		return member.ErrUserLength
	}
	if !userRegex.MatchString(v.Usr) {
		return member.ErrUserValidErr
	}

	if this.GetAggregateRootId() != 0 && len([]rune(v.Name)) < 2 {
		return member.ErrPersonName
	}

	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.Qq) != 0 && !qqRegex.MatchString(v.Qq) {
		return member.ErrQqValidErr
	}
	return nil
}
Example #3
0
func (this *Partner) RegisterMember(m *jsv.Args, r *jsv.Result) error {

	var err error

	e := member.ValueMember{}

	if err = jsv.UnmarshalMap((*m)["json"], &e); err != nil {
		return err
	}
	var cardId string
	var tgId int
	var partnerId int

	cardId = (*m)["card_id"].(string)
	tgId, _ = strconv.Atoi((*m)["tg_id"].(string))
	partnerId, _ = strconv.Atoi((*m)["partner_id"].(string))

	//如果卡片ID为空时,自动生成
	if cardId == "" {
		cardId = time.Now().Format("200601021504")
	}
	e.RegFrom = "WEB"

	e.Pwd = domain.MemberSha1Pwd(e.Pwd)
	id, err := dps.MemberService.SaveMember(&e)

	if err == nil {
		dps.MemberService.SaveRelation(id, cardId, tgId, partnerId)
		r.Result = true
		return nil
	}
	return err
}
Example #4
0
func (this *UserC) PostRegisterInfo_post(ctx *web.Context) {
	ctx.Request.ParseForm()
	var result gof.Message
	var member member.ValueMember

	web.ParseFormToEntity(ctx.Request.Form, &member)
	code := ctx.Request.FormValue("invi_code")

	if i := strings.Index(ctx.Request.RemoteAddr, ":"); i != -1 {
		member.RegIp = ctx.Request.RemoteAddr[:i]
	}

	var memberId int
	var partnerId int
	var err error

	partnerId = this.GetPartnerId(ctx)
	if len(member.Usr) == 0 || len(member.Pwd) == 0 {
		result.Message = "1000:注册信息不完整"
		ctx.Response.JsonOutput(result)
		return
	}

	if err = dps.PartnerService.CheckRegisterMode(partnerId, code); err != nil {
		result.Message = err.Error()
		ctx.Response.JsonOutput(result)
		return
	}

	var invId int
	if len(code) > 0 {
		invId = dps.MemberService.GetMemberIdByInvitationCode(code)
		if invId <= 0 {
			result.Message = "1011:推荐码不正确"
			ctx.Response.JsonOutput(result)
			return
		}
	}

	member.Pwd = domain.MemberSha1Pwd(member.Pwd)
	memberId, err = dps.MemberService.SaveMember(&member)
	if err == nil {
		err = dps.MemberService.SaveRelation(memberId, "", invId, partnerId)
	}

	if err != nil {
		result.Message = err.Error()
	} else {
		result.Result = true
	}
	ctx.Response.JsonOutput(result)
}
Example #5
0
// 设置值
func (this *Member) SetValue(v *member.ValueMember) error {
	v.Usr = this._value.Usr
	if err := this.validate(v); err != nil {
		return err
	}
	this._value.Address = v.Address
	this._value.Birthday = v.Birthday
	this._value.Qq = v.Qq
	this._value.Email = v.Email
	this._value.LastLoginTime = v.LastLoginTime
	this._value.Phone = v.Phone
	this._value.Pwd = v.Pwd
	this._value.Name = v.Name
	this._value.Sex = v.Sex
	this._value.RegFrom = v.RegFrom
	if v.Avatar != "" {
		this._value.Avatar = v.Avatar
	}
	if len(this._value.InvitationCode) == 0 {
		this._value.InvitationCode = v.InvitationCode
	}

	if len(v.TradePwd) == 0 {
		this._value.TradePwd = v.TradePwd
	}

	if len(this._value.Qq) != 0 && len(this._value.Email) != 0 &&
		len(this._value.Birthday) != 0 && len(this._value.Address) != 0 &&
		len(this._value.Phone) != 0 && len(this._value.Avatar) != 0 &&
		this._value.Sex != 0 {
		this.notifyOnProfileComplete()
	}
	return nil
}
Example #6
0
// 注册
func (this *MemberC) Register(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {
		r := ctx.Request
		var result dto.MessageResult

		var partnerId int = this.GetPartnerId(ctx)
		var invMemberId int // 邀请人
		var usr string = r.FormValue("usr")
		var pwd string = r.FormValue("pwd")
		var registerFrom string = r.FormValue("reg_from")          // 注册来源
		var invitationCode string = r.FormValue("invitation_code") // 推荐码
		var regIp string
		if i := strings.Index(r.RemoteAddr, ":"); i != -1 {
			regIp = r.RemoteAddr[:i]
		}

		fmt.Println(usr, pwd, "REGFROM:", registerFrom, "INVICODE:", invitationCode)

		// 检验
		if len(invitationCode) != 0 {
			invMemberId = dps.MemberService.GetMemberIdByInvitationCode(invitationCode)
			if invMemberId == 0 {
				result.Message = "推荐/邀请人不存在!"
				ctx.Response.JsonOutput(result)
				return
			}
		}

		var member member.ValueMember
		member.Usr = usr
		member.Pwd = domain.MemberSha1Pwd(pwd)
		member.RegIp = regIp
		member.RegFrom = registerFrom

		memberId, err := dps.MemberService.SaveMember(&member)
		if err == nil {
			result.Result = true
			err = dps.MemberService.SaveRelation(memberId, "-", invMemberId, partnerId)
		}

		if err != nil {
			result.Message = err.Error()
		}

		ctx.Response.JsonOutput(result)
	}
}
Example #7
0
func (this *basicC) Profile_post(ctx *web.Context) {
	mm := this.GetMember(ctx)
	r := ctx.Request
	var result gof.Message
	r.ParseForm()
	clientM := new(member.ValueMember)
	web.ParseFormToEntity(r.Form, clientM)
	clientM.Id = mm.Id
	_, err := dps.MemberService.SaveMember(clientM)

	if err != nil {
		result = gof.Message{Result: false, Message: err.Error()}
	} else {
		result = gof.Message{Result: true}
	}
	ctx.Response.JsonOutput(result)
}
Example #8
0
func (this *basicC) Profile_post(ctx *web.Context) {
	mm := this.GetMember(ctx)
	r, w := ctx.Request, ctx.ResponseWriter
	var result gof.Message
	r.ParseForm()
	clientM := new(member.ValueMember)
	web.ParseFormToEntity(r.Form, clientM)
	clientM.Id = mm.Id
	_, err := goclient.Member.SaveMember(clientM, mm.DynamicToken)

	if err != nil {
		result = gof.Message{Result: false, Message: err.Error()}
	} else {
		result = gof.Message{Result: true}
	}
	w.Write(result.Marshal())
}
Example #9
0
func (this *basicC) Profile_post(ctx *web.Context) {
	mm := this.GetMember(ctx)
	r := ctx.Request
	var result gof.Message
	r.ParseForm()
	m := new(member.ValueMember)
	web.ParseFormToEntity(r.Form, m)
	m.Id = mm.Id
	_, err := dps.MemberService.SaveMember(m)

	if err != nil {
		result.Message = err.Error()
	} else {
		result.Result = true
		this.ReCacheMember(ctx, m.Id)
	}
	ctx.Response.JsonOutput(result)
}
Example #10
0
func (this *userC) PostRegisterInfo_post(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	p := this.GetPartner(ctx)
	r.ParseForm()
	var member member.ValueMember
	web.ParseFormToEntity(r.Form, &member)
	if i := strings.Index(r.RemoteAddr, ":"); i != -1 {
		member.RegIp = r.RemoteAddr[:i]
	}
	b, err := goclient.Partner.RegisterMember(&member, p.Id, 0, "")
	if b {
		w.Write([]byte(`{"result":true}`))
	} else {
		if err != nil {
			w.Write([]byte(fmt.Sprintf(`{"result":false,"message":"%s"}`, err.Error())))
		} else {
			w.Write([]byte(`{"result":false}`))
		}

	}
}
Example #11
0
func (this *Member) SaveMember(m *jsv.Args, r *jsv.Result) error {
	memberId, err := Verify(m)
	if err != nil {
		return err
	}

	var e member.ValueMember
	err = jsv.UnmarshalMap((*m)["json"], &e)
	if err != nil {
		return err
	}
	e.Id = memberId
	_, err = dps.MemberService.SaveMember(&e)

	if err != nil {
		jsv.LogErr(err)
		r.Message = err.Error()
	} else {
		r.Result = true
	}
	return nil
}
Example #12
0
// 创建会员
func (this *Member) create(m *member.ValueMember) (int, error) {
	if this.UsrIsExist() {
		return -1, errors.New("用户名已经被使用")
	}
	t := time.Now().Unix()
	m.State = 1
	m.RegTime = t
	m.LastLoginTime = t
	m.Level = 1
	m.Exp = 1
	m.Avatar = "resource/no_avatar.gif"
	m.Birthday = "1970-01-01"
	m.DynamicToken = m.Pwd
	m.Exp = 0

	if len(m.RegFrom) == 0 {
		m.RegFrom = "API-INTERNAL"
	}

	// 如果昵称为空,则跟用户名相同
	if len(m.Name) == 0 {
		m.Name = m.Usr
	}
	m.InvitationCode = this.generateInvitationCode() // 创建一个邀请码

	id, err := this._rep.SaveMember(m)
	if id != 0 {
		this._value.Id = id
	}
	return id, err
}