backend/app/controllers/Home.controller.js
garrettmills 273460b126
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Add support for fetching session data; add /start url
(Noded/frontend#15)
2020-10-12 20:32:27 -05:00

51 lines
1.3 KiB
JavaScript

const Controller = require('libflitter/controller/Controller');
/*
* Home Controller
* -------------------------------------------------------------
* Controller for the main homepage of this Flitter app. Methods here
* 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')
}
/*
* 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;