logout
This commit is contained in:
parent
655f64c193
commit
84ec601e2a
4 changed files with 53 additions and 0 deletions
25
backend/routes/user/logout.coffee
Normal file
25
backend/routes/user/logout.coffee
Normal 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
|
|
@ -14,6 +14,8 @@ fastify.route (require "./routes/#{route}") for route in [
|
||||||
'test'
|
'test'
|
||||||
# log in user
|
# log in user
|
||||||
'user/login'
|
'user/login'
|
||||||
|
# log out user
|
||||||
|
'user/logout'
|
||||||
# register user
|
# register user
|
||||||
'user/register'
|
'user/register'
|
||||||
]
|
]
|
||||||
|
|
|
@ -33,6 +33,16 @@ class FFTCGSESSION
|
||||||
logger.info "OK '#{digest}' created"
|
logger.info "OK '#{digest}' created"
|
||||||
resolve digest
|
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) ->
|
check: (digest) ->
|
||||||
new Promise (resolve, reject) =>
|
new Promise (resolve, reject) =>
|
||||||
# refresh expiry timer on digest
|
# refresh expiry timer on digest
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
</p>
|
</p>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
<p>user session: {{ sessionID }}</p>
|
<p>user session: {{ sessionID }}</p>
|
||||||
|
<v-btn @click.native="logout">Logout</v-btn>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -21,6 +22,21 @@ export default {
|
||||||
sessionID: ''
|
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() {
|
mounted() {
|
||||||
axios
|
axios
|
||||||
.post('/user/login', {
|
.post('/user/login', {
|
||||||
|
|
Reference in a new issue