fix: sign out

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2021-02-27 23:15:34 +08:00
parent dd3fb3e9a7
commit 1324911b10
4 changed files with 36 additions and 6 deletions
+8 -5
View File
@@ -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
+3 -1
View File
@@ -221,7 +221,9 @@
handleUserCommand(command: string) {
if (command === 'logout') {
this.$router.push('/login');
this.axios.get('/signout').then(() => {
this.$router.push('/login');
});
}
}
+6
View File
@@ -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'
},
+19
View File
@@ -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