From 42f242993722dd977b8167998b546e0af8b2cba0 Mon Sep 17 00:00:00 2001 From: Thomas Atkins Date: Sat, 8 Feb 2020 23:22:12 -0600 Subject: [PATCH 1/4] fixed redrect links --- app/views/welcome.pug | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/welcome.pug b/app/views/welcome.pug index 76f4f06..dea3e76 100644 --- a/app/views/welcome.pug +++ b/app/views/welcome.pug @@ -37,10 +37,10 @@ html body .flitter-container img.flitter-image(src="/assets/logo/3x/logo3x.png") - a.flitter-name(href="https://hack20.glmdev.tech/i" target="_blank") powered by #{_app.name} + a.flitter-name(href="/login" target="_blank") powered by #{_app.name} if user .flitter-container p.flitter-text Welcome, #{user.uid}! Log out. else .flitter-container - p.flitter-text New to #{_app.name}? Start here. + p.flitter-text New to #{_app.name}? Start here. From 7fd4e996499ce458cefe8418c83e5f0034495883 Mon Sep 17 00:00:00 2001 From: Thomas Atkins Date: Sat, 8 Feb 2020 23:29:10 -0600 Subject: [PATCH 2/4] fixed dash path --- app/controllers/Home.controller.js | 40 +++--- app/routing/routers/auth/forms.routes.js | 169 +++++++++++------------ app/routing/routers/index.routes.js | 105 +++++++------- 3 files changed, 155 insertions(+), 159 deletions(-) diff --git a/app/controllers/Home.controller.js b/app/controllers/Home.controller.js index 9c6e005..c764ad5 100644 --- a/app/controllers/Home.controller.js +++ b/app/controllers/Home.controller.js @@ -1,4 +1,4 @@ -const Controller = require('libflitter/controller/Controller') +const Controller = require('libflitter/controller/Controller'); /* * Home Controller @@ -7,26 +7,28 @@ 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'] - } + static get services() { + return [...super.services, 'configs']; + } + /* + * Serve the main welcome page. + */ + welcome(req, res) { /* - * Serve the main welcome page. + * Return the welcome view. + * The page() method is added by Flitter and passes some + * helpful contextual data to the view as well. */ - welcome(req, res){ - - /* - * 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}) - } + 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'); + } } -module.exports = Home +module.exports = Home; diff --git a/app/routing/routers/auth/forms.routes.js b/app/routing/routers/auth/forms.routes.js index d4911e0..871e1df 100644 --- a/app/routing/routers/auth/forms.routes.js +++ b/app/routing/routers/auth/forms.routes.js @@ -15,99 +15,96 @@ * /auth/register */ const index = { + prefix: '/auth', - prefix: '/auth', + middleware: [], - middleware: [ + get: { + '/:provider/register': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'middleware::auth:ProviderRegistrationEnabled', + 'controller::auth:Forms.registration_provider_get' + ], + '/register': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'middleware::auth:ProviderRegistrationEnabled', + 'controller::auth:Forms.registration_provider_get' + ], + '/:provider/login': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'controller::auth:Forms.login_provider_get' + ], + '/login': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'controller::auth:Forms.login_provider_get' ], - get: { - '/:provider/register': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'middleware::auth:ProviderRegistrationEnabled', - 'controller::auth:Forms.registration_provider_get', - ], - '/register': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'middleware::auth:ProviderRegistrationEnabled', - 'controller::auth:Forms.registration_provider_get', - ], - - '/:provider/login': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'controller::auth:Forms.login_provider_get', - ], - '/login': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'controller::auth:Forms.login_provider_get', - ], - - '/:provider/logout': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:UserOnly', - 'controller::auth:Forms.logout_provider_clean_session', + '/:provider/logout': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:UserOnly', + 'controller::auth:Forms.logout_provider_clean_session', - // Note, this separation is between when the auth action has happened properly - // and before the user is allowed to continue. You can use it to add your own - // custom middleware for auth flow handling. + // Note, this separation is between when the auth action has happened properly + // and before the user is allowed to continue. You can use it to add your own + // custom middleware for auth flow handling. + + 'controller::auth:Forms.logout_provider_present_success' + ], + '/logout': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:UserOnly', + 'controller::auth:Forms.logout_provider_clean_session', + 'controller::auth:Forms.logout_provider_present_success' + ] + }, - 'controller::auth:Forms.logout_provider_present_success', - ], - '/logout': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:UserOnly', - 'controller::auth:Forms.logout_provider_clean_session', - 'controller::auth:Forms.logout_provider_present_success', - ], - }, + post: { + '/:provider/register': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'middleware::auth:ProviderRegistrationEnabled', + 'controller::auth:Forms.registration_provider_create_user', + 'controller::auth:Forms.registration_provider_present_user_created' + ], + '/register': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'middleware::auth:ProviderRegistrationEnabled', + 'controller::auth:Forms.registration_provider_create_user', + 'controller::auth:Forms.registration_provider_present_user_created' + ], - post: { - '/:provider/register': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'middleware::auth:ProviderRegistrationEnabled', - 'controller::auth:Forms.registration_provider_create_user', - 'controller::auth:Forms.registration_provider_present_user_created', - ], - '/register': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'middleware::auth:ProviderRegistrationEnabled', - 'controller::auth:Forms.registration_provider_create_user', - 'controller::auth:Forms.registration_provider_present_user_created', - ], - - '/:provider/login': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'controller::auth:Forms.login_provider_authenticate_user', - 'controller::auth:Forms.login_provider_present_success', - ], - '/login': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:GuestOnly', - 'controller::auth:Forms.login_provider_authenticate_user', - 'controller::auth:Forms.login_provider_present_success', - ], + '/:provider/login': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'controller::auth:Forms.login_provider_authenticate_user', + 'controller::auth:Forms.login_provider_present_success' + ], + '/login': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:GuestOnly', + 'controller::auth:Forms.login_provider_authenticate_user', + 'controller::auth:Forms.login_provider_present_success' + ], - '/:provider/logout': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:UserOnly', - 'controller::auth:Forms.logout_provider_clean_session', - 'controller::auth:Forms.logout_provider_present_success', - ], - '/logout': [ - 'middleware::auth:ProviderRoute', - 'middleware::auth:UserOnly', - 'controller::auth:Forms.logout_provider_clean_session', - 'controller::auth:Forms.logout_provider_present_success', - ], - }, -} + '/:provider/logout': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:UserOnly', + 'controller::auth:Forms.logout_provider_clean_session', + 'controller::auth:Forms.logout_provider_present_success' + ], + '/logout': [ + 'middleware::auth:ProviderRoute', + 'middleware::auth:UserOnly', + 'controller::auth:Forms.logout_provider_clean_session', + 'controller::auth:Forms.logout_provider_present_success' + ] + } +}; -module.exports = exports = index +module.exports = exports = index; diff --git a/app/routing/routers/index.routes.js b/app/routing/routers/index.routes.js index 308976c..51161dc 100644 --- a/app/routing/routers/index.routes.js +++ b/app/routing/routers/index.routes.js @@ -5,62 +5,59 @@ * defined here, but no logic should occur. */ const index = { + /* + * Define the prefix applied to each of these routes. + * For example, if prefix is '/auth': + * '/' becomes '/auth' + * '/login' becomes '/auth/login' + */ + prefix: '/', - /* - * Define the prefix applied to each of these routes. - * For example, if prefix is '/auth': - * '/' becomes '/auth' - * '/login' becomes '/auth/login' - */ - prefix: '/', + /* + * Define middleware that should be applied to all + * routes defined in this file. Middleware should be + * included using its non-prefixed canonical name. + * + * You can pass arguments along to a middleware by + * specifying it as an array where the first element + * is the canonical name of the middleware and the + * second element is the argument passed to the + * handler's exec() method. + */ + middleware: [ + // 'MiddlewareName', // Or without arguments + ], - /* - * Define middleware that should be applied to all - * routes defined in this file. Middleware should be - * included using its non-prefixed canonical name. - * - * You can pass arguments along to a middleware by - * specifying it as an array where the first element - * is the canonical name of the middleware and the - * second element is the argument passed to the - * handler's exec() method. - */ - middleware: [ - // 'MiddlewareName', // Or without arguments - ], + /* + * Define GET routes. + * These routes are registered as GET methods. + * Handlers for these routes should be specified as + * an array of canonical references to controller methods + * or middleware that are applied in order. + */ + get: { + // handlers should be a list of either controller:: or middleware:: references + // e.g. middleware::HomeLogger + // e.g. controller::Home.welcome + '/': ['controller::Home.welcome'], - /* - * Define GET routes. - * These routes are registered as GET methods. - * Handlers for these routes should be specified as - * an array of canonical references to controller methods - * or middleware that are applied in order. - */ - get: { - // handlers should be a list of either controller:: or middleware:: references - // e.g. middleware::HomeLogger - // e.g. controller::Home.welcome - '/': [ 'controller::Home.welcome' ], + // Placeholder for auth dashboard. You'd replace this with + // your own route protected by 'middleware::auth:UserOnly' + '/dash': ['controller::Home.toApp'], + '/login': ['middleware::auth:GuestOnly', 'controller::Home.get_login'], + '/test-json': ['controller::Export.json_export'], + '/test-markdown': ['controller::Export.markdown_export'], + '/test-html': ['controller::Export.html_export'] + }, - // Placeholder for auth dashboard. You'd replace this with - // your own route protected by 'middleware::auth:UserOnly' - '/dash': [ 'controller::Home.welcome' ], - '/login': [ 'middleware::auth:GuestOnly', 'controller::Home.get_login' ], - '/test-json' : [ 'controller::Export.json_export' ], - '/test-markdown' : [ 'controller::Export.markdown_export' ], - '/test-html' : [ 'controller::Export.html_export' ] - }, + /* + * Define POST routes. + * These routes are registered as POST methods. + * Handlers for these routes should be specified as + * an array of canonical references to controller methods + * or middleware that are applied in order. + */ + post: {} +}; - /* - * Define POST routes. - * These routes are registered as POST methods. - * Handlers for these routes should be specified as - * an array of canonical references to controller methods - * or middleware that are applied in order. - */ - post: { - - }, -} - -module.exports = exports = index +module.exports = exports = index; From d005a9f3c8cda4aa4d29c55abf31a342efe05c8a Mon Sep 17 00:00:00 2001 From: QiTao Date: Sun, 9 Feb 2020 00:02:09 -0600 Subject: [PATCH 3/4] Task #27 - Fix for export markdown function and archiving. --- app/controllers/Export.controller.js | 46 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/app/controllers/Export.controller.js b/app/controllers/Export.controller.js index b2bf1ef..43c501c 100644 --- a/app/controllers/Export.controller.js +++ b/app/controllers/Export.controller.js @@ -11,7 +11,7 @@ const path = require('path'); */ class Export extends Controller { static get services() { - return [...super.services, 'models'] + return [...super.services, 'models', 'app'] } /* * Serve the main page. @@ -40,11 +40,12 @@ class Export extends Controller { const temp_dir = path.resolve(os.tmpdir(), uuid()) await fs.mkdir(temp_dir) - this._markdown_recurse(page0, temp_dir) + await this._markdown_recurse(page0, temp_dir) /* Archive directory */ const exec = require('child_process').exec; - exec('zip -r ' + path.resolve(temp_dir, 'archive.zip') + ' ' + path.resolve(temp_dir), (error) => { + console.log('zip -9jpr ' + path.resolve(temp_dir, '../archive.zip') + ' ' + path.resolve(temp_dir) + '/') + exec('cd ' + path.resolve(temp_dir) + '; zip -r archive.zip *', (error) => { if (error) { console.error(`exec error: ${error}`); return res.error(500); @@ -56,16 +57,17 @@ class Export extends Controller { } async _markdown_recurse(root, temp_dir) { //recursive function for creating directory and generating markdown pages - console.log('root', root) + const fs = require('fs').promises const Page = this.models.get('api:Page') const child = await Page.find({ UUID: { $in: root.ChildPageIds } }) - for (const page of child) { - const markdown = this._generate_markdown(page) + const markdown = await this._generate_markdown(page) + await fs.writeFile(path.resolve(temp_dir, page.Name.replace(/\s/g, '_')) + '.md', markdown) if (page.ChildPageIds && page.ChildPageIds.length) { const sub_temp_dir = path.resolve(temp_dir, page.Name.replace(/\s/g, '_')) + // console.log(sub_temp_dir) await fs.mkdir(sub_temp_dir) - this._markdown_recurse(page, sub_temp_dir) + await this._markdown_recurse(page, sub_temp_dir) } } } @@ -91,16 +93,19 @@ class Export extends Controller { const html_name = page.Name.replace(/\s/g, '_') + '.html' mapping[page.UUID] = html_name } - const sidebar_html = this._generate_sidebar(page0) //generates the sidebar contents - + console.log(page0) + const sidebar_html = await this._generate_sidebar(mapping, page0) //generates the sidebar contents + const temp_dir = path.resolve(os.tmpdir(), uuid()) //make temporary directory await fs.mkdir(temp_dir) - /* Generates html files from template */ - for(const page of pages) { + for (const page of pages) { const fs = require('fs').promises - const contents = await fs.readFile('../assets/export-template.html') - const content_html = this._generate_html(page) + const contents = (await fs.readFile(path.resolve(this.app.directories.assets, 'export-template.html'))).toString('utf8') + console.log(page) + //console.log({contents}) + const content_html = await this._generate_html(page) + //console.log({content_html, sidebar_html}) const page_html = contents.replace('%%SIDEBAR%%', sidebar_html).replace('%%CONTENTS%%', content_html) await fs.writeFile(path.resolve(temp_dir, mapping[page.UUID]), page_html) } @@ -112,18 +117,21 @@ class Export extends Controller { return res.error(500); return; } - return res.sendFile(`${path.resolve(temp_dir, 'archive.zip')}`) }) } - async _generate_sidebar(root) { //generate sidebar from mapping array and root - if (root.ChildPageIds < 1) { - return '' + root.Name + '' + async _generate_sidebar(mapping, upper_node) { //generate sidebar from mapping array and upper_node + const Page = this.models.get('api:Page') + console.log(upper_node) + console.log(upper_node.ChildPageIds == 'undefined') + if (upper_node.ChildPageIds == 'undefined') { + return '' + upper_node.Name + '' } else { let base = '