Add support for fetching session data; add /start url
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

(Noded/frontend#15)
This commit is contained in:
Garrett Mills 2020-10-12 20:31:57 -05:00
parent 6ee03ec0f8
commit 273460b126
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
4 changed files with 82 additions and 24 deletions

View File

@ -27,13 +27,24 @@ class Home extends Controller {
*/ */
return res.page('welcome', { user: req.user }); return res.page('welcome', { user: req.user });
} }
async get_login(req, res) { async get_login(req, res) {
const AppName = this.configs.get('app.name'); const AppName = this.configs.get('app.name');
return res.page('login', { AppName }); return res.page('login', { AppName });
} }
toApp(req, res) { toApp(req, res) {
return res.redirect('/i'); return res.redirect('/i');
} }
async get_stat(req, res, next) {
return res.api({
noded: true,
app_name: this.configs.get('app.name'),
system_base: this.configs.get('app.url'),
authenticated_user: !!req.user,
})
}
} }
module.exports = Home; module.exports = Home;

View File

@ -0,0 +1,26 @@
const { Controller } = require('libflitter')
class SessionController extends Controller {
static get services() {
return [...super.services, 'configs']
}
async get_session(req, res, next) {
return res.api(await this.session_data(req.user))
}
async session_data(user) {
return {
user: {
id: user.id,
username: user.uid,
},
app: {
name: this.configs.get('app.name'),
url: this.configs.get('app.url'),
},
}
}
}
module.exports = exports = SessionController

View File

@ -0,0 +1,18 @@
const index = {
prefix: '/api/v1/session',
middleware: [
'auth:UserOnly',
],
get: {
'/': [ 'controller::api:v1:Session.get_session' ],
},
post: {
},
}
module.exports = exports = index

View File

@ -41,9 +41,12 @@ const index = {
// e.g. controller::Home.welcome // e.g. controller::Home.welcome
'/': ['controller::Home.welcome'], '/': ['controller::Home.welcome'],
'/stat': ['controller::Home.get_stat'],
// Placeholder for auth dashboard. You'd replace this with // Placeholder for auth dashboard. You'd replace this with
// your own route protected by 'middleware::auth:UserOnly' // your own route protected by 'middleware::auth:UserOnly'
'/dash': ['controller::Home.toApp'], '/dash': ['middleware::auth:UserOnly', 'controller::Home.toApp'],
'/start': ['middleware::auth:UserOnly', 'controller::Home.toApp'],
'/login': ['middleware::auth:GuestOnly', 'controller::Home.get_login'], '/login': ['middleware::auth:GuestOnly', 'controller::Home.get_login'],
'/test-json': ['controller::Export.json_export'], '/test-json': ['controller::Export.json_export'],
'/test-markdown': ['controller::Export.markdown_export'], '/test-markdown': ['controller::Export.markdown_export'],