Methods Solve, GetAnswer, IsSolved, and Expiry could be implemented once for a base Captcha struct. But GetImage and generateImage methods should be implemented by all structs that compose with base Captcha struct.

This commit is contained in:
Alexander Andreev 2022-06-26 22:02:38 +04:00
parent 9658bbd755
commit 96e8cf0c97
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
2 changed files with 17 additions and 17 deletions

View File

@ -34,6 +34,23 @@ type Captcha struct {
ExpireIn time.Time
}
func (c *Captcha) Solve(answer Answer) bool {
c.Solved = c.Answer == answer
return c.Solved
}
func (c *Captcha) GetAnswer() Answer {
return c.Answer
}
func (c *Captcha) IsSolved() bool {
return c.Solved
}
func (c *Captcha) Expiry() time.Time {
return c.ExpireIn
}
func GenerateAnswer() Answer {
ans, _ := rand.Int(rand.Reader, big.NewInt(maxAnswer))
return (Answer(ans.String()))

View File

@ -72,20 +72,3 @@ func (c *DwellingCaptcha) GetImage() *image.Image {
return &c.Image
}
func (c *DwellingCaptcha) Solve(answer Answer) bool {
c.Solved = c.Answer == answer
return c.Solved
}
func (c *DwellingCaptcha) GetAnswer() Answer {
return c.Answer
}
func (c *DwellingCaptcha) IsSolved() bool {
return c.Solved
}
func (c *DwellingCaptcha) Expiry() time.Time {
return c.ExpireIn
}