MCPcopy Create free account
hub / github.com/diyhi/bbs / CaptchaComponent

Class CaptchaComponent

src/main/java/cms/component/CaptchaComponent.java:18–263  ·  view source on GitHub ↗

验证码组件

Source from the content-addressed store, hash-verified

16 *
17 */
18@Component("captchaComponent")
19public class CaptchaComponent {
20
21 @Resource SettingRepository settingRepository;
22 @Resource SettingCacheManager settingCacheManager;
23
24 @Resource CaptchaCacheManager captchaCacheManager;
25
26
27 /**
28 * 校验验证码
29 * @param captchaKey 验证码键
30 * @param captchaValue 验证码值
31 * @param errors 错误信息
32 * @return
33 */
34 public void validateCaptcha(String captchaKey, String captchaValue, Map<String,String> errors){
35 //验证验证码
36 if(captchaKey != null && !captchaKey.trim().isEmpty()){
37 //增加验证码重试次数
38 //统计每分钟原来提交次数
39 Integer original = settingCacheManager.getSubmitQuantity("captcha", captchaKey.trim());
40 if(original != null){
41 settingCacheManager.addSubmitQuantity("captcha", captchaKey.trim(),original+1);//刷新每分钟原来提交次数
42 }else{
43 settingCacheManager.addSubmitQuantity("captcha", captchaKey.trim(),1);//刷新每分钟原来提交次数
44 }
45
46 String captcha = captchaCacheManager.getCaptcha(captchaKey.trim());
47 if(captchaValue != null && !captchaValue.trim().isEmpty()){
48 if(captcha != null && !captcha.trim().isEmpty()){
49 if(!captcha.equalsIgnoreCase(captchaValue)){
50 errors.put("captchaValue","验证码错误");
51 }
52 }else{
53 errors.put("captchaValue","验证码过期");
54 }
55 }else{
56 errors.put("captchaValue","请输入验证码");
57 }
58 //删除验证码
59 captchaCacheManager.deleteCaptcha(captchaKey.trim());
60 }else{
61 errors.put("captchaValue", "需要输入验证码");
62 }
63 }
64
65
66
67 /**---------------------------------- 话题 ---------------------------------------**/
68 /**
69 * 是否显示验证码
70 * @param userName 用户名称
71 * @return 验证码标记
72 */
73 public boolean topic_isCaptcha(String userName){
74
75 SystemSetting systemSetting = settingRepository.findSystemSetting_cache();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…