This commit is contained in:
Jörn-Michael Miehe 2019-05-07 22:15:18 +02:00
parent 655f64c193
commit 84ec601e2a
4 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,25 @@
logger = (require 'logging').default 'logout'
# session storage (volatile data)
session = (require '../../session')
# fftcg.db (persistent data)
fftcgdb = (require '../../db')
module.exports =
url: '/user/logout'
method: 'POST'
handler: (request, reply) ->
new Promise (resolve) ->
session.destroy request.body.session ? ""
.then ->
# active session found
logger.debug "OK removed session '#{request.body.session}'"
resolve null
.catch ->
resolve null
.then ->
reply.send
success: true

View file

@ -14,6 +14,8 @@ fastify.route (require "./routes/#{route}") for route in [
'test'
# log in user
'user/login'
# log out user
'user/logout'
# register user
'user/register'
]

View file

@ -33,6 +33,16 @@ class FFTCGSESSION
logger.info "OK '#{digest}' created"
resolve digest
destroy: (digest) ->
new Promise (resolve, reject) =>
# delete hash immediately
@db.del digest, (err, res) ->
if res == 0
reject null
else
logger.info "OK '#{digest}' deleted"
resolve null
check: (digest) ->
new Promise (resolve, reject) =>
# refresh expiry timer on digest

View file

@ -7,6 +7,7 @@
</p>
</v-flex>
<p>user session: {{ sessionID }}</p>
<v-btn @click.native="logout">Logout</v-btn>
</v-container>
</template>
@ -21,6 +22,21 @@ export default {
sessionID: ''
}),
methods: {
logout() {
axios
.post('/user/logout', {
session: Cookies.get('session')
})
.then(response => {
if (response.data.success) {
Cookies.remove('session')
this.$router.push({name: 'home'})
}
})
}
},
mounted() {
axios
.post('/user/login', {