Commit c85364d6 by fsn

增加一个开关,控制登录页面的验证码

parent 3e6d7e6d
package com.stylefeng.guns.config.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* guns项目配置
*
* @author stylefeng
* @Date 2017/5/23 22:31
*/
@Component
@ConfigurationProperties(prefix = GunsProperties.PREFIX)
public class GunsProperties {
public static final String PREFIX = "guns";
private Boolean kaptchaOpen;
public Boolean getKaptchaOpen() {
return kaptchaOpen;
}
public void setKaptchaOpen(Boolean kaptchaOpen) {
this.kaptchaOpen = kaptchaOpen;
}
}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.stylefeng.guns.core.util; package com.stylefeng.guns.core.util;
import com.stylefeng.guns.config.properties.GunsProperties;
import com.stylefeng.guns.core.support.StrKit; import com.stylefeng.guns.core.support.StrKit;
import java.io.IOException; import java.io.IOException;
...@@ -523,4 +524,14 @@ public class ToolUtil { ...@@ -523,4 +524,14 @@ public class ToolUtil {
public static String firstLetterToLower(String val){ public static String firstLetterToLower(String val){
return StrKit.firstCharToLowerCase(val); return StrKit.firstCharToLowerCase(val);
} }
/**
* 获取验证码开关
*
* @author stylefeng
* @Date 2017/5/23 22:34
*/
public static Boolean getKaptchaOnOff(){
return SpringContextHolder.getBean(GunsProperties.class).getKaptchaOpen();
}
} }
\ No newline at end of file
...@@ -83,12 +83,14 @@ public class LoginController extends BaseController { ...@@ -83,12 +83,14 @@ public class LoginController extends BaseController {
String username = super.getPara("username").trim(); String username = super.getPara("username").trim();
String password = super.getPara("password").trim(); String password = super.getPara("password").trim();
String kaptcha = super.getPara("kaptcha").trim();
//验证验证码是否正确 //验证验证码是否正确
String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY); if(ToolUtil.getKaptchaOnOff()){
if(ToolUtil.isEmpty(kaptcha) || !kaptcha.equals(code)){ String kaptcha = super.getPara("kaptcha").trim();
throw new InvalidKaptchaException(); String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
if(ToolUtil.isEmpty(kaptcha) || !kaptcha.equals(code)){
throw new InvalidKaptchaException();
}
} }
Subject currentUser = ShiroKit.getSubject(); Subject currentUser = ShiroKit.getSubject();
......
################### guns项目独有的配置 ###################
guns:
kaptcha-open: false #是否开启登录时验证码 (true/false)
################### 项目启动端口 ################### ################### 项目启动端口 ###################
server: server:
port: 80 port: 80
################### spring配置 ################### ################### spring配置 ###################
spring: spring:
......
...@@ -35,14 +35,16 @@ ...@@ -35,14 +35,16 @@
<div class="form-group"> <div class="form-group">
<input type="password" name="password" class="form-control" placeholder="密码" required=""> <input type="password" name="password" class="form-control" placeholder="密码" required="">
</div> </div>
<div class="form-group" style="float: left;"> @if(tool.getKaptchaOnOff() == true){
<div class="col-sm-8" style="padding-left: 0px; padding-right: 0px;"> <div class="form-group" style="float: left;">
<input class="form-control" type="text" name="kaptcha" placeholder="验证码" required=""> <div class="col-sm-8" style="padding-left: 0px; padding-right: 0px;">
<input class="form-control" type="text" name="kaptcha" placeholder="验证码" required="">
</div>
<div class="col-sm-4" style="padding-left: 0px; padding-right: 0px;">
<img src="${ctxPath}/kaptcha" id="kaptcha" width="100%" height="100%"/>
</div>
</div> </div>
<div class="col-sm-4" style="padding-left: 0px; padding-right: 0px;"> @}
<img src="${ctxPath}/kaptcha" id="kaptcha" width="100%" height="100%"/>
</div>
</div>
<button type="submit" class="btn btn-primary block full-width m-b">登 录</button> <button type="submit" class="btn btn-primary block full-width m-b">登 录</button>
</p> </p>
</form> </form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment