Add support for fetching session data; add /start url
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

(Noded/frontend#15)
master
Garrett Mills 4 years ago
parent 6ee03ec0f8
commit 273460b126
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -7,33 +7,44 @@ const Controller = require('libflitter/controller/Controller');
* are used as handlers for routes specified in the route files.
*/
class Home extends Controller {
static get services() {
return [...super.services, 'configs'];
}
/*
* Serve the main welcome page.
*/
welcome(req, res) {
if (req.user) {
// If we have a user, redirect them to the main app
return res.redirect('/i')
static get services() {
return [...super.services, 'configs'];
}
/*
* Return the welcome view.
* The page() method is added by Flitter and passes some
* helpful contextual data to the view as well.
* Serve the main welcome page.
*/
return res.page('welcome', { user: req.user });
}
async get_login(req, res) {
const AppName = this.configs.get('app.name');
return res.page('login', { AppName });
}
toApp(req, res) {
return res.redirect('/i');
}
welcome(req, res) {
if (req.user) {
// If we have a user, redirect them to the main app
return res.redirect('/i')
}
/*
* Return the welcome view.
* The page() method is added by Flitter and passes some
* helpful contextual data to the view as well.
*/
return res.page('welcome', { user: req.user });
}
async get_login(req, res) {
const AppName = this.configs.get('app.name');
return res.page('login', { AppName });
}
toApp(req, res) {
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;

@ -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

@ -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

@ -41,9 +41,12 @@ const index = {
// e.g. controller::Home.welcome
'/': ['controller::Home.welcome'],
'/stat': ['controller::Home.get_stat'],
// Placeholder for auth dashboard. You'd replace this with
// 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'],
'/test-json': ['controller::Export.json_export'],
'/test-markdown': ['controller::Export.markdown_export'],

Loading…
Cancel
Save