CAPTCHA implementation changed to a new interface. And now composes from BaseCaptcha struct.

This commit is contained in:
Alexander Andreev 2022-07-30 15:33:34 +04:00
parent f7439eb282
commit f35c16f837
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -15,16 +15,16 @@ const (
)
type DwellingCaptcha struct {
captcha.Captcha
captcha.BaseCaptcha
}
func NewDwellingCaptcha(expiry time.Duration) *DwellingCaptcha {
return &DwellingCaptcha{
Captcha: captcha.Captcha{
BaseCaptcha: captcha.BaseCaptcha{
ExpireIn: captcha.ExpiryDate(expiry)}}
}
func (c *DwellingCaptcha) generateImage(style string) *image.Image {
func (c *DwellingCaptcha) Image(style string) image.Image {
isDark := style == "dark"
ctx := gg.NewContext(dwImageWidth, dwImageHeight)
@ -67,14 +67,5 @@ func (c *DwellingCaptcha) generateImage(style string) *image.Image {
ctx.Stroke()
}
c.Image = ctx.Image()
return &c.Image
}
func (c *DwellingCaptcha) GetImage(style string) *image.Image {
if c.Image == nil {
return c.generateImage(style)
}
return &c.Image
return ctx.Image()
}