Skip to content

Commit fe3fad5

Browse files
committed
验证码集成完成
1 parent a40aef8 commit fe3fad5

8 files changed

Lines changed: 26 additions & 33 deletions

File tree

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

src/main/java/com/rui/pro1/modules/sys/shiro/CredentialsMatcher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public boolean doCredentialsMatch(AuthenticationToken token,
3939
userLonginLogCache.put(username, loginCount);
4040
}
4141
// 登陆限制
42-
if (loginCount.incrementAndGet() >=SysComm.USER_LOGIN_COUNT) {
43-
throw new CaptchaErrorException();
44-
}
42+
// if (loginCount.incrementAndGet() >=SysComm.USER_LOGIN_COUNT) {
43+
// throw new CaptchaErrorException();
44+
// }
4545
if (loginCount.incrementAndGet() >=SysComm.USER_LOGIN_MAX_COUNT_LOCK) {
4646
throw new ExcessiveAttemptsException();
4747
}

src/main/java/com/rui/pro1/modules/sys/web/UserLoginController.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,26 @@ public void loginPage(HttpServletRequest request, HttpServletResponse response)
212212
// //省略代码-里面是一个新的token 生成
213213
// }
214214

215-
//获取用户信息
215+
//获取用户信息 好像没必要 null?
216216
Subject sbuject=SecurityUtils.getSubject();
217217
Object principal = sbuject.getPrincipal();
218-
//System.out.println(principal);
218+
// System.out.println(principal);
219+
Map<String,String> map=new HashMap<String,String>();
220+
if (principal!=null&&!"".equals(principal))
221+
{
222+
SpringCacheManagerWrapper cacheManager= (SpringCacheManagerWrapper) SysApplicationContext.getBean("cacheManager");
223+
Cache<String, AtomicInteger> cache= cacheManager.getCache(EhCacheKeys.LONGIN_LOG_CACHE);
224+
AtomicInteger loginCount=cache.get(principal.toString());
225+
if(loginCount!=null&&loginCount.get()>=SysComm.USER_LOGIN_COUNT)
226+
{
227+
// rb = new ResultBean(false,MessageCode.PLASS_CAPTCHA,"请输入验证码","");
228+
//是否显示验证码
229+
map.put("isCaptcha", "1");
230+
231+
}
232+
233+
}
219234

220-
Map<String,String> map=new HashMap<String,String>();
221-
SpringCacheManagerWrapper cacheManager= (SpringCacheManagerWrapper) SysApplicationContext.getBean("cacheManager");
222-
Cache<String, AtomicInteger> cache= cacheManager.getCache(EhCacheKeys.LONGIN_LOG_CACHE);
223-
AtomicInteger loginCount=cache.get(principal.toString());
224-
if(loginCount.get()>=SysComm.USER_LOGIN_COUNT)
225-
{
226-
// rb = new ResultBean(false,MessageCode.PLASS_CAPTCHA,"请输入验证码","");
227-
//是否显示验证码
228-
map.put("isCaptcha", "1");
229-
230-
}
231-
232-
233235

234236

235237
if (WebHelp.isAjAxRequest(request))
@@ -324,7 +326,7 @@ private ResultBean capthchaProcess(HttpServletRequest request,String userName,St
324326
SpringCacheManagerWrapper cacheManager= (SpringCacheManagerWrapper) SysApplicationContext.getBean("cacheManager");
325327
Cache<String, AtomicInteger> cache= cacheManager.getCache(EhCacheKeys.LONGIN_LOG_CACHE);
326328
AtomicInteger loginCount=cache.get(userName);
327-
if(loginCount.get()>=SysComm.USER_LOGIN_COUNT)
329+
if(loginCount!=null&&loginCount.get()>=SysComm.USER_LOGIN_COUNT)
328330
{
329331
if(StringUtils.isBlank(captcha)){
330332
rb = new ResultBean(false,MessageCode.PLASS_CAPTCHA,"请输入验证码","");

src/main/webapp/views/common/sys.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ function handleAjaxRequest(resultBean, status,XMLHttpRequest)
8585
if(resultBean.messageCode=="010"||resultBean.messageCode=="002"||resultBean.messageCode=="003")
8686
{
8787
alert(resultBean.message);
88-
// if(resultBean.data!=""&&resultBean.data.isCaptcha=="1"){
89-
// //需要验证码
90-
// }
91-
9288
window.top.location.href=getContextPath()+"/views/login.html";
9389
return false;
9490
}
@@ -104,7 +100,7 @@ function handleAjaxRequest(resultBean, status,XMLHttpRequest)
104100
alert('您未登录或会话已过期');
105101
window.top.location.href=getContextPath()+"/views/login.html";
106102
return false;
107-
}else if(ajaxRequestHeader=="002"){
103+
}else if(ajaxRequestHeader=="004"){
108104
alert('请输入验证码');
109105
window.top.location.href=getContextPath()+"/views/login.html?isCaptcha=1";
110106
return false;

src/main/webapp/views/login.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,30 @@ <h3>Login</h3>
141141

142142
})
143143

144-
145-
146144
function initLogin(){
147145
var isCaptcha=getUrlParam('isCaptcha');
146+
//alert(isCaptcha);
148147
if(isCaptcha=="1"){
149148
$("#_captcha_div").css("display","block");
150149
}
151150
//$("#_captcha_div").css("display","none");
152-
//$("#_captcha_div").hide(); block
153151
}
154152

155153
$("#_login").click(function() {
156154
var username = $("#_username").val();
157155
var password = $("#_password").val();
158156
var rememberme = $("#_rememberme").is(':checked');
159-
157+
var captcha = $("#_captchaCode").val();
160158

161159
//验证码处理
162-
var capthcaDisplay=$("#_captcha_div").attr("display");
163-
alert(capthcaDisplay);
164-
var captcha = $("#_captchaCode").val();
160+
var capthcaDisplay=$('#_captcha_div').css('display');
161+
//alert(capthcaDisplay);
165162
if(capthcaDisplay=="block")
166163
{
167164
if(captcha==""){
168165
alert("请输入验证码");
169166
return;
170167
}
171-
}else{
172-
captcha="";
173168
}
174169

175170

0 commit comments

Comments
 (0)