Browse Source

后台登录加入验证码

v2
蟑螂恶霸 2 years ago
parent
commit
b040840222
  1. 10
      lib/EmergencyService/zdxtEmergencyAuthService/src/main/java/com/zdxt/auth/framework/shiro/service/LoginService.java
  2. 43
      lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/templates/login.html

10
lib/EmergencyService/zdxtEmergencyAuthService/src/main/java/com/zdxt/auth/framework/shiro/service/LoginService.java

@ -41,11 +41,11 @@ public class LoginService
public User login(String username, String password)
{
// 验证码校验
// if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA)))
// {
// AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
// throw new CaptchaException();
// }
if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA)))
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
throw new CaptchaException();
}
// 用户名或密码为空 错误
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password))
{

43
lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/templates/login.html

@ -16,6 +16,28 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<link rel="shortcut icon" href="../static/favicon.ico" th:href="@{favicon.ico}"/>-->
<style type="text/css">label.error { position:inherit; }</style>
<style>
.loginbox input.vcsty {
width: 30%;
border-bottom: 1px solid #ddd;
}
.vcode {
float: right;
margin-right: 5%;
width: 54%;
height: 40px;
border: 1px solid #eee;
overflow: hidden;
}
.vcode img {
width: auto;
height: 100%;
}
</style>
</head>
<body>
@ -31,6 +53,15 @@
<input class="pwsty" type="password" placeholder="请输入密码" id="login-password" name="password" />
<input class="checksty" name="" type="checkbox" value="" checked="checked" /><span class="remtxt">记住密码</span>
<!--<a href="#" class="fortxt">忘记密码?</a> -->
<div class="vcbox" th:if="${captchaEnabled==true}">
<div class="inptit">验证码</div>
<input class="vcsty" type="text" placeholder="请输入验证码" name="validateCode" maxlength="6" autocomplete="off" />
<div class="vcode">
<a href="javascript:void(0);" title="点击更换验证码">
<img th:src="@{captcha/captchaImage(type=${captchaType})}" class="imgcode" width="85%"/>
</a>
</div>
</div>
<div class="loginbtn" id="login">登录</div>
</div>
</div>
@ -59,6 +90,14 @@
<script>
$(function(){
console.log(document.cookie);
$(function() {
$('.imgcode').click(function() {
var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
$(".imgcode").attr("src", url);
});
});
/*登录*/
$("#login").click(function(){
login();
@ -79,12 +118,14 @@
//var rememberMe = false;
var userName=$("#login-username").val();
var passWord=$("#login-password").val();
var validateCode=$("[name = 'validateCode']").val();
$.ajax({
type: "post",
url: ctx + "login",
data: {
"secretName": userName,
"secretKey": Encrypt(passWord)
"secretKey": Encrypt(passWord),
"validateCode": validateCode
//"rememberMe": rememberMe
},
success: function(r) {

Loading…
Cancel
Save