mirror of https://gitee.com/answerdev/answer.git
update captcha
This commit is contained in:
parent
5a348fd66d
commit
ded980b676
|
@ -25,7 +25,7 @@ func NewCaptchaRepo(data *data.Data) action.CaptchaRepo {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *captchaRepo) SetActionType(ctx context.Context, ip, actionType string, amount int) (err error) {
|
func (cr *captchaRepo) SetActionType(ctx context.Context, ip, actionType string, amount int) (err error) {
|
||||||
cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType)
|
cacheKey := fmt.Sprintf("ActionRecord:%s@", ip)
|
||||||
err = cr.data.Cache.SetInt64(ctx, cacheKey, int64(amount), 6*time.Minute)
|
err = cr.data.Cache.SetInt64(ctx, cacheKey, int64(amount), 6*time.Minute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
|
@ -34,19 +34,16 @@ func (cr *captchaRepo) SetActionType(ctx context.Context, ip, actionType string,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *captchaRepo) GetActionType(ctx context.Context, ip, actionType string) (amount int, err error) {
|
func (cr *captchaRepo) GetActionType(ctx context.Context, ip, actionType string) (amount int, err error) {
|
||||||
//cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType)
|
|
||||||
//Detects behavior based on ip only
|
|
||||||
cacheKey := fmt.Sprintf("ActionRecord:%s@", ip)
|
cacheKey := fmt.Sprintf("ActionRecord:%s@", ip)
|
||||||
res, err := cr.data.Cache.GetInt64(ctx, cacheKey)
|
res, err := cr.data.Cache.GetInt64(ctx, cacheKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
// TODO: cache reflect should return empty when key not found
|
|
||||||
return int(res), nil
|
return int(res), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *captchaRepo) DelActionType(ctx context.Context, ip, actionType string) (err error) {
|
func (cr *captchaRepo) DelActionType(ctx context.Context, ip, actionType string) (err error) {
|
||||||
cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType)
|
cacheKey := fmt.Sprintf("ActionRecord:%s@", ip)
|
||||||
err = cr.data.Cache.Del(ctx, cacheKey)
|
err = cr.data.Cache.Del(ctx, cacheKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
|
@ -56,7 +53,6 @@ func (cr *captchaRepo) DelActionType(ctx context.Context, ip, actionType string)
|
||||||
|
|
||||||
// SetCaptcha set captcha to cache
|
// SetCaptcha set captcha to cache
|
||||||
func (cr *captchaRepo) SetCaptcha(ctx context.Context, key, captcha string) (err error) {
|
func (cr *captchaRepo) SetCaptcha(ctx context.Context, key, captcha string) (err error) {
|
||||||
// TODO make cache time to config
|
|
||||||
err = cr.data.Cache.SetString(ctx, key, captcha, 6*time.Minute)
|
err = cr.data.Cache.SetString(ctx, key, captcha, 6*time.Minute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
|
@ -70,6 +66,5 @@ func (cr *captchaRepo) GetCaptcha(ctx context.Context, key string) (captcha stri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
}
|
}
|
||||||
// TODO: cache reflect should return empty when key not found
|
|
||||||
return captcha, nil
|
return captcha, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue