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

原文地址:http://my.oschina.net/65304586/blog/168130

[size=large][b]安装[/b][/size]
在config/buildConfig.groovy下plugin配置

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

[size=large][b]配置[/b][/size]
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"
}


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



[size=large][b]修改loginController[/b][/size]
def save() {
boolean captchaValid = simpleCaptchaService.validateCaptcha(params.captcha)
if(!captchaValid) {
flash.message = "验证码错误"
render(view: "login")
return
}
def userInstance = new User(params)

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值