Skip to content
Permalink
Browse files
易用性方面的一点优化 (#673)
* 增加用户token有效时长配置

* 修复登录根路径时不校验登录态问题

* 优化登录后及登录态失效后的页面跳转

* Update UserController.java

* Update AuthInterceptor.java

* Update application.properties

* Update http-common.js

* Update http-common.js

* Update Login.vue

* Update http-common.js

Co-authored-by: chaihaipeng <chaihaipeng@sogou-inc.com>
  • Loading branch information
sadeychai and chaihaipeng committed Feb 7, 2021
1 parent 61615f8 commit 89d937710254c11431f33d19128414250a69ce00
Showing 5 changed files with 22 additions and 5 deletions.
@@ -43,6 +43,10 @@ public class UserController {
private String rootUserName;
@Value("${admin.root.user.password:}")
private String rootUserPassword;
//make session timeout configurable
//default to be an hour:1000 * 60 * 60
@Value("${admin.check.sessionTimeoutMilli:3600000}")
private long sessionTimeoutMilli;

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(@RequestParam String userName, @RequestParam String password) {
@@ -69,7 +73,7 @@ public boolean logout() {

@Scheduled(cron= "0 5 * * * ?")
public void clearExpiredToken() {
tokenMap.entrySet().removeIf(entry -> entry.getValue() == null || System.currentTimeMillis() - entry.getValue().getLastUpdateTime() > 1000 * 60 * 15);
tokenMap.entrySet().removeIf(entry -> entry.getValue() == null || System.currentTimeMillis() - entry.getValue().getLastUpdateTime() > sessionTimeoutMilli);
}

public static class User {
@@ -35,12 +35,11 @@
public class AuthInterceptor extends HandlerInterceptorAdapter {
@Value("${admin.check.authority:true}")
private boolean checkAuthority;

//make session timeout configurable
//default to be an hour:1000 * 60 * 60
@Value("${admin.check.sessionTimeoutMilli:3600000}")
private long sessionTimeoutMilli;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (!(handler instanceof HandlerMethod) || !checkAuthority) {
@@ -31,6 +31,9 @@ admin.registry.group=dubbo
admin.config-center.group=dubbo
admin.metadata-report.group=dubbo

#session timeout, default is one hour
admin.check.sessionTimeoutMilli=3600000

#namespace used by nacos
admin.registry.namespace=public
admin.config-center.namespace=public
@@ -85,7 +85,13 @@
if (response.status === 200 && response.data) {
localStorage.setItem('token', response.data)
localStorage.setItem('username', userName)
this.$router.replace('/')
//login and redirect
let redirect = this.$route.query.redirect
if(redirect) {
this.$router.replace(redirect)
} else {
this.$router.replace('/')
}
} else {
vm.$notify('Username or password error,please try again')
}
@@ -41,7 +41,12 @@ instance.interceptors.response.use((response) => {
localStorage.removeItem('token')
localStorage.removeItem('username')
Vue.prototype.$notify.error(i18n.t('authFailed'))
router.push({ path: 'login' })
let paths = location.href.split('#')
if (paths.length > 1 && paths[1].startsWith('/login')) {
// avoid splicing multiple redirects
return
}
router.push({path: 'login', query: {redirect: paths.length === 1 ? '/' : paths[1]}})
} else if (error.response.status >= HttpStatus.BAD_REQUEST) {
Vue.prototype.$notify.error(error.response.data.message)
}

0 comments on commit 89d9377

Please sign in to comment.