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:
parent
9658bbd755
commit
96e8cf0c97
@ -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()))
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user