mirror of
https://github.com/zhaojh329/rttys.git
synced 2026-02-27 09:53:21 +08:00
@@ -42,12 +42,15 @@ router.beforeEach((to, from, next) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (to.path !== '/login' && !sessionStorage.getItem('rttys-sid')) {
|
||||
router.push('/login');
|
||||
return;
|
||||
if (to.path !== '/login') {
|
||||
Vue.axios.get('/alive').then(() => {
|
||||
next();
|
||||
}).catch(() => {
|
||||
router.push('/login');
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
export default router
|
||||
|
||||
@@ -221,7 +221,9 @@
|
||||
|
||||
handleUserCommand(command: string) {
|
||||
if (command === 'logout') {
|
||||
this.$router.push('/login');
|
||||
this.axios.get('/signout').then(() => {
|
||||
this.$router.push('/login');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,12 @@ module.exports = {
|
||||
'/signin': {
|
||||
target: 'http://127.0.0.1:5913'
|
||||
},
|
||||
'/signout': {
|
||||
target: 'http://127.0.0.1:5913'
|
||||
},
|
||||
'/alive': {
|
||||
target: 'http://127.0.0.1:5913'
|
||||
},
|
||||
'/signup': {
|
||||
target: 'http://127.0.0.1:5913'
|
||||
},
|
||||
|
||||
@@ -203,6 +203,25 @@ func httpStart(br *broker) {
|
||||
c.Status(http.StatusForbidden)
|
||||
})
|
||||
|
||||
r.GET("/alive", func(c *gin.Context) {
|
||||
if !httpAuth(c) {
|
||||
c.AbortWithStatus(http.StatusUnauthorized)
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
})
|
||||
|
||||
r.GET("/signout", func(c *gin.Context) {
|
||||
cookie, err := c.Cookie("sid")
|
||||
if err != nil || !httpSessions.Have(cookie) {
|
||||
return
|
||||
}
|
||||
|
||||
httpSessions.Del(cookie)
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
})
|
||||
|
||||
r.POST("/signup", func(c *gin.Context) {
|
||||
var creds credentials
|
||||
|
||||
|
||||
Reference in New Issue
Block a user