/user/info route
This commit is contained in:
parent
e6bfa62381
commit
e64f5dbabf
5 changed files with 54 additions and 4 deletions
24
backend/routes/user/info.coffee
Normal file
24
backend/routes/user/info.coffee
Normal 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
|
24
backend/routes/user/info.schema.coffee
Normal file
24
backend/routes/user/info.schema.coffee
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Reference in a new issue