/user/info route

This commit is contained in:
Jörn-Michael Miehe 2019-05-09 14:31:54 +02:00
parent e6bfa62381
commit e64f5dbabf
5 changed files with 54 additions and 4 deletions

View file

@ -0,0 +1,24 @@
logger = (require 'logging').default 'info'
# session storage (volatile data)
session = (require '../../session')
module.exports =
url: '/user/info'
method: 'POST'
schema: (require './info.schema')
handler: (request, reply) ->
session.check request.body.session ? ""
.then (user) ->
# active session found
logger.debug "OK '#{user.login}' got info"
reply.send
success: true
user: user
.catch ->
# no session found
logger.info "FAIL '#{request.body.session}' session not found"
reply.send
success: false

View file

@ -0,0 +1,24 @@
module.exports =
body:
session: type: 'string'
response:
200:
type: 'object'
required: ['success']
properties:
success: type: 'boolean'
user:
type: 'object'
required: ['user', 'login', 'settings']
properties:
user: type: 'integer'
login: type: 'string'
settings: type: 'string'
# user is required iff success
if:
properties:
success:
const: true
then:
required: ['user']
else: true

View file

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

View file

@ -57,6 +57,6 @@ class FFTCGSESSION
else
@db.get digest, (err, res) ->
logger.info "OK '#{digest}' resumed"
resolve digest
resolve (JSON.parse res)
module.exports = new FFTCGSESSION

View file

@ -2,7 +2,7 @@
<v-container>
<Header />
<p>user logged in: {{ user }}</p>
<p>user logged in: {{ user.login }}</p>
<v-btn @click.native="logout">Logout</v-btn>
</v-container>
</template>
@ -45,12 +45,12 @@ export default {
mounted() {
axios
.post('/user/login', {
.post('/user/info', {
session: Cookies.get('session')
})
.then(response => {
if (response.data.success) {
this.user = response.data.message
this.user = response.data.user
} else {
this.goHome()
}