|
@ -21,6 +21,7 @@ type CaptchaSol struct { |
|
|
ImgsSolution []string `json:"imgssolution"` |
|
|
ImgsSolution []string `json:"imgssolution"` |
|
|
Question string `json:"question"` //select all X
|
|
|
Question string `json:"question"` //select all X
|
|
|
Date int64 `json:"date"` |
|
|
Date int64 `json:"date"` |
|
|
|
|
|
Ip string `json:"ip"` |
|
|
} |
|
|
} |
|
|
type CaptchaAnswer struct { |
|
|
type CaptchaAnswer struct { |
|
|
CaptchaId string `json:"captchaid"` |
|
|
CaptchaId string `json:"captchaid"` |
|
@ -47,7 +48,7 @@ func generateQuestionFromCategoriesArray(imgs []string) string { |
|
|
n := generateRandInt(0, len(imgs)) |
|
|
n := generateRandInt(0, len(imgs)) |
|
|
return imgs[n] |
|
|
return imgs[n] |
|
|
} |
|
|
} |
|
|
func generateCaptcha(count int) Captcha { |
|
|
|
|
|
|
|
|
func generateCaptcha(count int, ip string) Captcha { |
|
|
var captcha Captcha |
|
|
var captcha Captcha |
|
|
var captchaSol CaptchaSol |
|
|
var captchaSol CaptchaSol |
|
|
|
|
|
|
|
@ -71,11 +72,12 @@ func generateCaptcha(count int) Captcha { |
|
|
captcha.Question = question |
|
|
captcha.Question = question |
|
|
captchaSol.Question = question |
|
|
captchaSol.Question = question |
|
|
captchaSol.Date = time.Now().Unix() |
|
|
captchaSol.Date = time.Now().Unix() |
|
|
|
|
|
captchaSol.Ip = ip |
|
|
err := captchaSolCollection.Insert(captchaSol) |
|
|
err := captchaSolCollection.Insert(captchaSol) |
|
|
check(err) |
|
|
check(err) |
|
|
return captcha |
|
|
return captcha |
|
|
} |
|
|
} |
|
|
func validateCaptcha(captchaAnswer CaptchaAnswer) bool { |
|
|
|
|
|
|
|
|
func validateCaptcha(captchaAnswer CaptchaAnswer, ip string) bool { |
|
|
var solved bool |
|
|
var solved bool |
|
|
solved = true |
|
|
solved = true |
|
|
captchaSol := CaptchaSol{} |
|
|
captchaSol := CaptchaSol{} |
|
@ -108,5 +110,9 @@ func validateCaptcha(captchaAnswer CaptchaAnswer) bool { |
|
|
if elapsed.Seconds() > 60 { |
|
|
if elapsed.Seconds() > 60 { |
|
|
solved = false |
|
|
solved = false |
|
|
} |
|
|
} |
|
|
|
|
|
//ip comprovation
|
|
|
|
|
|
if captchaSol.Ip != ip { |
|
|
|
|
|
solved = false |
|
|
|
|
|
} |
|
|
return solved |
|
|
return solved |
|
|
} |
|
|
} |