示例#1
0
// 注册
func (this *MemberC) Register(ctx *echo.Context) error {
	r := ctx.Request()
	var result dto.MessageResult
	var err error
	var merchantId int = getMerchantId(ctx)
	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]
	}

	m := &member.Member{}
	pro := &member.Profile{}
	m.Usr = usr
	m.Pwd = domain.MemberSha1Pwd(pwd)
	m.RegIp = regIp
	m.RegFrom = registerFrom

	pro.Phone = phone
	pro.Name = m.Usr

	_, err = dps.MemberService.RegisterMember(merchantId, m, pro, "", invitationCode)
	if err == nil {
		result.Result = true
	} else {
		result.Message = err.Error()
	}
	return ctx.JSON(http.StatusOK, result)
}
示例#2
0
// 登陆
func (this *MemberC) Login(ctx *echo.Context) error {
	r := ctx.Request()
	var usr, pwd string = r.FormValue("usr"), r.FormValue("pwd")
	//merchantId := getMerchantId(ctx)
	var result dto.MemberLoginResult

	pwd = strings.TrimSpace(pwd)

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

		if err == nil {
			// 生成令牌
			e.DynamicToken = util.SetMemberApiToken(sto, e.Id, e.Pwd)
			mm := dps.MemberService.GetMemberSummary(e.Id)
			result.Member = mm
			result.Result = true
		} else {
			result.Message = err.Error()
			result.Result = false
		}
	}
	return ctx.JSON(http.StatusOK, result)

}
示例#3
0
// 修改交易密码,旧密码可为空
func (this *profileManagerImpl) ModifyTradePassword(newPwd, oldPwd string) error {
	var err error
	if newPwd == oldPwd {
		return domain.ErrPwdCannotSame
	}
	if b, err := dm.ChkPwdRight(newPwd); !b {
		return err
	}
	// 已经设置过旧密码
	if len(this._member._value.TradePwd) != 0 &&
		this._member._value.TradePwd != dm.MemberSha1Pwd(oldPwd) {
		return domain.ErrPwdOldPwdNotRight
	}
	this._member._value.TradePwd = dm.MemberSha1Pwd(newPwd)
	_, err = this._member.Save()
	return err
}
示例#4
0
func (this *merchantRep) doSomething() {
	ms := []*member.Member{}
	orm := this.Connector.GetOrm()
	orm.Select(&ms, "1=1")

	for _, v := range ms {
		v.Pwd = domain.MemberSha1Pwd("123456")
		orm.Save(v.Id, v)
	}
}
示例#5
0
// 重置密码
func (this *memberService) ResetPassword(memberId int) string {
	m := this._rep.GetMember(memberId)
	if m != nil {
		newPwd := domain.GenerateRandomIntPwd(6)
		newEncPwd := domain.MemberSha1Pwd(newPwd)
		if m.Profile().ModifyPassword(newEncPwd, "") == nil {
			return newPwd
		}
	}
	return ""
}