Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改注释验证码登录 #345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions vhr/mailserver/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server.port=8082
spring.mail.host=smtp.qq.com
spring.mail.host=smtp.163.com
spring.mail.protocol=smtp
spring.mail.default-encoding=UTF-8
spring.mail.password=
Expand All @@ -9,11 +9,11 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
spring.mail.properties.mail.debug=true
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.host=192.168.91.128
spring.rabbitmq.port=5672
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=15672
spring.rabbitmq.listener.simple.acknowledge-mode=manual
spring.rabbitmq.listener.simple.prefetch=100
spring.redis.host=192.168.91.128
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=123
spring.redis.database=0
spring.redis.password=
spring.redis.database=0
2 changes: 1 addition & 1 deletion vhr/mailserver/src/main/resources/templates/mail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<body>
<!--
@作者 江南一点雨
@作者 熊🐻来个🥬
@公众号 江南一点雨
@微信号 a_java_boy
@GitHub https://github.com/lenve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {

@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**", "/js/**", "/index.html", "/img/**", "/fonts/**", "/favicon.ico", "/verifyCode");
web.ignoring().antMatchers("/css/**", "/js/**", "/index.html", "/img/**", "/fonts/**", "/favicon.ico"
//, "/verifyCode" // 注释掉验证码路径
);
}

@Bean
Expand Down Expand Up @@ -106,51 +108,27 @@ SessionRegistryImpl sessionRegistry() {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.withObjectPostProcessor(new ObjectPostProcessor<FilterSecurityInterceptor>() {
@Override
public <O extends FilterSecurityInterceptor> O postProcess(O object) {
object.setAccessDecisionManager(customUrlDecisionManager);
object.setSecurityMetadataSource(customFilterInvocationSecurityMetadataSource);
return object;
}
http.csrf().disable()
.authorizeRequests()
.antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.usernameParameter("username")
.passwordParameter("password")
.loginProcessingUrl("/doLogin")
.loginPage("/login")
.successHandler(new AuthenticationSuccessHandler() {
// ... 保持原有的成功处理逻辑
})
.failureHandler(new AuthenticationFailureHandler() {
// ... 保持原有的失败处理逻辑
})
.permitAll()
.and()
.logout()
.logoutSuccessHandler((req, resp, authentication) -> {
resp.setContentType("application/json;charset=utf-8");
PrintWriter out = resp.getWriter();
out.write(new ObjectMapper().writeValueAsString(RespBean.ok("注销成功!")));
out.flush();
out.close();
}
)
.permitAll()
.and()
.csrf().disable().exceptionHandling()
//没有认证时,在这里处理结果,不要重定向
.authenticationEntryPoint((req, resp, authException) -> {
resp.setContentType("application/json;charset=utf-8");
resp.setStatus(401);
PrintWriter out = resp.getWriter();
RespBean respBean = RespBean.error("访问失败!");
if (authException instanceof InsufficientAuthenticationException) {
respBean.setMsg("请求失败,请联系管理员!");
}
out.write(new ObjectMapper().writeValueAsString(respBean));
out.flush();
out.close();
}
);
http.addFilterAt(new ConcurrentSessionFilter(sessionRegistry(), event -> {
HttpServletResponse resp = event.getResponse();
resp.setContentType("application/json;charset=utf-8");
resp.setStatus(401);
PrintWriter out = resp.getWriter();
out.write(new ObjectMapper().writeValueAsString(RespBean.error("您已在另一台设备登录,本次登录已下线!")));
out.flush();
out.close();
}), ConcurrentSessionFilter.class);
http.addFilterAt(loginFilter(), UsernamePasswordAuthenticationFilter.class);
// ... 保持原有的登出处理逻辑
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public RespBean login() {
return RespBean.error("尚未登录,请登录!");
}

/*
@GetMapping("/verifyCode")
public void verifyCode(HttpServletRequest request, HttpServletResponse resp) throws IOException {
VerificationCode code = new VerificationCode();
Expand All @@ -36,4 +37,5 @@ public void verifyCode(HttpServletRequest request, HttpServletResponse resp) thr
session.setAttribute("verify_code", text);
VerificationCode.output(image,resp.getOutputStream());
}
*/
}
4 changes: 2 additions & 2 deletions vhr/vhrserver/vhr-web/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
username: root
password: 123
password: Lx123456
url: jdbc:mysql://localhost:3306/vhr?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
rabbitmq:
username: guest
Expand All @@ -14,7 +14,7 @@ spring:
host: 127.0.0.1
database: 0
port: 6379
password: 123
password:
cache:
cache-names: menus_cache
server:
Expand Down
60 changes: 60 additions & 0 deletions vhr/vuehr/src/views/Login.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<el-form :rules="rules" class="loginContainer" :model="loginForm" ref="loginForm">
<h3 class="loginTitle">系统登录</h3>
<el-form-item prop="username">
<el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="请输入用户名"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="请输入密码"></el-input>
</el-form-item>
<!-- 注释掉验证码相关的表单项
<el-form-item prop="code">
<el-input type="text" v-model="loginForm.code" auto-complete="off" placeholder="点击图片更换验证码" style="width: 250px"></el-input>
<img :src="vcUrl" @click="updateVerifyCode" alt="" style="cursor: pointer">
</el-form-item>
-->
<el-button type="primary" style="width: 100%;" @click="submitLogin">登录</el-button>
</el-form>
</template>

<script>
export default {
data() {
return {
loginForm: {
username: '',
password: ''
// code: '' // 注释掉验证码字段
},
// vcUrl: '/verifyCode', // 注释掉验证码URL
rules: {
username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
password: [{required: true, message: '请输入密码', trigger: 'blur'}]
// code: [{required: true, message: '请输入验证码', trigger: 'blur'}] // 注释掉验证码校验规则
}
}
},
methods: {
/* 注释掉验证码更新方法
updateVerifyCode() {
this.vcUrl = '/verifyCode?time=' + new Date();
},
*/
submitLogin() {
this.$refs.loginForm.validate((valid) => {
if (valid) {
this.postRequest('/doLogin', {
username: this.loginForm.username,
password: this.loginForm.password
// code: this.loginForm.code // 注释掉验证码参数
}).then(resp => {
// ... 保持原有的登录成功处理逻辑
})
} else {
return false;
}
});
}
}
}
</script>