/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'
|
'test'
|
||||||
# log in user
|
# log in user
|
||||||
'user/login'
|
'user/login'
|
||||||
|
# user info
|
||||||
|
'user/info'
|
||||||
# log out user
|
# log out user
|
||||||
'user/logout'
|
'user/logout'
|
||||||
# register user
|
# register user
|
||||||
|
|
|
@ -57,6 +57,6 @@ class FFTCGSESSION
|
||||||
else
|
else
|
||||||
@db.get digest, (err, res) ->
|
@db.get digest, (err, res) ->
|
||||||
logger.info "OK '#{digest}' resumed"
|
logger.info "OK '#{digest}' resumed"
|
||||||
resolve digest
|
resolve (JSON.parse res)
|
||||||
|
|
||||||
module.exports = new FFTCGSESSION
|
module.exports = new FFTCGSESSION
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<v-container>
|
<v-container>
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
<p>user logged in: {{ user }}</p>
|
<p>user logged in: {{ user.login }}</p>
|
||||||
<v-btn @click.native="logout">Logout</v-btn>
|
<v-btn @click.native="logout">Logout</v-btn>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
@ -45,12 +45,12 @@ export default {
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
axios
|
axios
|
||||||
.post('/user/login', {
|
.post('/user/info', {
|
||||||
session: Cookies.get('session')
|
session: Cookies.get('session')
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
this.user = response.data.message
|
this.user = response.data.user
|
||||||
} else {
|
} else {
|
||||||
this.goHome()
|
this.goHome()
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue