Ejemplo n.º 1
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
}
Ejemplo n.º 2
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)
	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.MemberSha1Pwd(member.Pwd)
		memberId, err = dps.MemberService.SaveMember(&member)
		if err == nil {
			invId := dps.MemberService.GetMemberIdByInvitationCode(ctx.Request.FormValue("invi_code"))
			err = dps.MemberService.SaveRelation(memberId, "", invId,
				this.BaseC.GetPartnerId(ctx))
		}
	}

	if err != nil {
		result.Message = err.Error()
	} else {
		result.Result = true
	}
	ctx.Response.JsonOutput(result)
}
Ejemplo n.º 3
0
// 登陆
func (this *MemberC) Login(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {

		r := ctx.Request
		var usr, pwd string = r.FormValue("usr"), r.FormValue("pwd")
		partnerId := this.GetPartnerId(ctx)
		var result dto.MemberLoginResult

		if len(usr) == 0 || len(pwd) == 0 {
			result.Message = "会员不存在"
		} else {
			encodePwd := domain.MemberSha1Pwd(pwd)
			b, e, err := dps.MemberService.Login(partnerId, usr, encodePwd)
			result.Result = b

			if b {
				// 生成令牌
				e.DynamicToken = util.SetMemberApiToken(ctx.App.Storage(), e.Id, e.Pwd)
				result.Member = e
			}
			if err != nil {
				result.Message = err.Error()
			}
		}
		ctx.Response.JsonOutput(result)
	}
}
Ejemplo n.º 4
0
// 注册
func (this *MemberC) Register(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {
		r := ctx.Request
		var result dto.MessageResult
		var err error

		var partnerId int = this.GetPartnerId(ctx)
		var invMemberId int // 邀请人
		var usr string = r.FormValue("usr")
		var pwd string = r.FormValue("pwd")
		var phone string = r.FormValue("phone")
		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]
		}

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

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

		// 检验
		if len(invitationCode) != 0 {
			invMemberId = dps.MemberService.GetMemberIdByInvitationCode(invitationCode)
			if invMemberId == 0 {
				result.Message = "1011:推荐码错误"
				ctx.Response.JsonOutput(result)
				return
			}
		}

		var member member.ValueMember
		member.Usr = usr
		member.Pwd = domain.MemberSha1Pwd(pwd)
		member.RegIp = regIp
		member.Phone = phone
		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)
	}
}
Ejemplo n.º 5
0
func (this *partnerRep) doSomething() {
	ms := []*member.ValueMember{}
	orm := this.Connector.GetOrm()
	orm.Select(&ms, "1=1")

	for _, v := range ms {
		v.Pwd = domain.MemberSha1Pwd("123456")
		orm.Save(v.Id, v)
	}
}
Ejemplo n.º 6
0
// 重置密码
func (this *memberService) ResetPassword(memberId int) string {
	m := this._memberRep.GetMember(memberId)
	if m != nil {
		newPwd := domain.GenerateRandomPwd(6)
		newEncPwd := domain.MemberSha1Pwd(newPwd)
		if m.ModifyPassword(newEncPwd, "") == nil {
			return newPwd
		}
	}
	return ""
}
Ejemplo n.º 7
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)
}
Ejemplo n.º 8
0
func main() {
	fmt.Println(crypto.Sha1([]byte("rskd3p")))
	fmt.Println(domain.PartnerSha1Pwd("zs", "gcY!zs1654320s"))

	fmt.Println(domain.NewApiId(105))
	fmt.Println(domain.MemberSha1Pwd("jumy257"))
	fmt.Println(1 << 2)
	fmt.Println(util.IsMobileAgent("Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"))

	tagRegexp := regexp.MustCompile("\\s*([^:\\|]+):([^:\\|]+)\\s*\\|*")
	matches := tagRegexp.FindAllStringSubmatch("G1:10|G2:12|G3:14", -1)
	for i := 0; i < len(matches); i++ {
		fmt.Println(i, "---", matches[i][1], matches[i][2])
	}

	fmt.Println("/main/change_device?device=3&return_url=/main/t/123" +
		url.QueryEscape("?return_url=/app"))
}