func SendCaptcha(context context.Context, mobile string, typ CaptchaType) error { if !validation.IsMobile(mobile) { return errors.New("invalid mobile") } switch typ { case RegisterCaptcha: a, e := persistence.GetAccountByMobile(mobile) if e != nil { return ErrServer } if a != nil { return ErrDupMobile } case ResetPasswordCaptcha: a, e := persistence.GetAccountByMobile(mobile) if e != nil { return ErrServer } if a == nil { return ErrNotFound } default: return errors.New("invalid captcha type") } _cache.HSet("captcha", mobile[:6], mobile, time.Minute*5) return nil }
func MobileLogin(c context.Context, mobile string, password string) (*LoginResult, error) { a, err := persistence.GetAccountByMobile(mobile) if err != nil { return nil, ErrServer } if a == nil { return nil, ErrLogin } password = crypt.SHA1(password + fmt.Sprint(a.ID)) if password != a.Password { return nil, ErrLogin } rs := &LoginResult{} rs.Account = &Account{} runtime.CopyFields(rs.Account, a) rs.LoginToken = a.LoginToken rs.Sid = GenerateSessionID(a.ID) log.Info(rs.Account, a) return rs, nil }