`
海之恋鱼
  • 浏览: 15367 次
  • 来自: 北京
社区版块
存档分类
最新评论

7、Grails-插件应用-Simple Captcha Plugin-验证码

阅读更多
原文地址:http://my.oschina.net/65304586/blog/168130

安装
在config/buildConfig.groovy下plugin配置

plugins {
        // plugins for the build system only
        compile ":simple-captcha:0.9.4"
}

配置
simpleCaptcha {
    // font size used in CAPTCHA images
    fontSize = 20
    height = 150
    width = 200

    // number of characters in CAPTCHA text
    length = 6

    // amount of space between the bottom of the CAPTCHA text and the bottom of the CAPTCHA image
    bottomPadding = 16

    // distance between the diagonal lines used to obfuscate the text
    lineSpacing = 10

    // the charcters shown in the CAPTCHA text must be one of the following
    chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    // this param will be passed as the first argument to this java.awt.Font constructor
    // http://docs.oracle.com/javase/6/docs/api/java/awt/Font.html#Font(java.lang.String,%20int,%20int)
    font = "Serif"
}


修改login.gsp
<input type="text"  name="captcha" class="form-control-Code"/>&nbsp;&nbsp;&nbsp;
<img src="${createLink(controller: 'simpleCaptcha', action: 'captcha')}"/>



修改loginController
def save() {
    boolean captchaValid = simpleCaptchaService.validateCaptcha(params.captcha)
    if(!captchaValid) {
        flash.message = "验证码错误"
        render(view: "login")
        return
    }
    def userInstance = new User(params)
   
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics