added settings loading to API to fix caching, added site init and onboarding, added settings templates to make site set up easier

This commit is contained in:
Ro 2020-06-20 18:13:23 -07:00
parent e6b3917c51
commit cf89b48d17
21 changed files with 455 additions and 195 deletions

1
.gitignore vendored
View file

@ -12,6 +12,7 @@ site/settings.json
site/folks.json site/folks.json
site/pages.json site/pages.json
site/tags.json site/tags.json
site/_backup
brain/models/_backup/ brain/models/_backup/
/_maintenance/ /_maintenance/
*.DS_Store *.DS_Store

View file

@ -5,7 +5,9 @@ const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const fs = require('fs-extra'); const fs = require('fs-extra');
const _ = require('lodash'); const _ = require('lodash');
//const crypto = require('crypto'); // for setting up new accounts const crypto = require('crypto'); // for setting up new accounts
const secret_key = '58d5aeec3c604e2837aef70bc1606f35131ab8fea9731925558f5acfaa00da60';
const moment = require('moment');
/** /**
* Get Auth Status * Get Auth Status
@ -75,6 +77,76 @@ router.post('/login', function (req, res) {
}); });
}); });
/**
* Initial Site Setup
*/
router.post('/init', function (req, res) {
let body = req.body;
let re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
// check email
if (!re.test(body.new_member_email)) {
res.json({
type: DataEvent.API_INIT_LAME,
message: 'Need a valid email address'
});
}
//check handle is being passed
if (body.new_member_handle === null || body.new_member_handle === '') {
res.json({
type: DataEvent.API_INIT_LAME,
message: 'No handle. Kinda need that.'
});
}
// check password match
if (
body.new_member_pass !== body.new_member_pass2 ||
body.new_member_pass === '' ||
body.new_member_pass2 === ''
) {
res.json({
type: DataEvent.API_INIT_LAME,
message: 'Passwords do not match.'
});
}
if (body.new_member_title === null || body.new_member_title === '') {
res.json({
type: DataEvent.API_INIT_LAME,
message: 'No title. Gotta call it something.'
});
}
let key = crypto
.createHash('sha256')
.update(body.new_member_pass + secret_key)
.digest('hex');
// set up config files
fs.readJson('site/init/settings-template.json').then(fresh => {
fresh.global.title = body.new_member_title;
fs.writeJSON('site/settings.json', fresh);
});
fs.readJson('site/init/folks-template.json').then(folks => {
folks[0].id = 1;
folks[0].handle = body.new_member_handle;
folks[0].email = body.new_member_email;
folks[0].password = bcrypt.hashSync(body.new_member_pass, bcrypt.genSaltSync(10), null);
folks[0].key = key;
folks[0].role = 'hnic';
folks[0].created = moment(Date.now()).format();
folks[0].updated = moment(Date.now()).format();
fs.writeJSON('site/folks.json', folks);
});
fs.writeJson('site/tags.json', { tags: [] });
res.json({
type: DataEvent.API_INIT_GOOD,
message: 'All Set Up'
});
});
//router.post('/logout', function(req, res) {}); //router.post('/logout', function(req, res) {});
module.exports = router; module.exports = router;

View file

@ -13,9 +13,6 @@ const settings = new Settings();
const _ = require('lodash'); const _ = require('lodash');
const uploadPath = const uploadPath =
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM'); './public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
fs.ensureDir(uploadPath, () => {
// dir has now been created, including the directory it is to be placed in
});
var storage = multer.diskStorage({ var storage = multer.diskStorage({
destination: function (req, file, cb) { destination: function (req, file, cb) {
cb(null, uploadPath); cb(null, uploadPath);

View file

@ -1,7 +1,7 @@
import * as DataEvent from '../../../src/com/events/DataEvent'; import * as DataEvent from '../../../src/com/events/DataEvent';
import Auth from '../../data/Auth'; import Auth from '../../data/Auth';
import Render from '../../data/Render'; import Render from '../../data/Render';
import SettingsData from '../../data/Settings'; import Settings, { SETTINGS_FILE, SETTINGS_FOLKS } from '../../data/Settings';
import Navigation from '../../data/Navigation'; import Navigation from '../../data/Navigation';
import Book from '../../data/Book'; import Book from '../../data/Book';
const express = require('express'); const express = require('express');
@ -10,12 +10,11 @@ const multer = require('multer');
const fs = require('fs-extra'); const fs = require('fs-extra');
const moment = require('moment'); const moment = require('moment');
const _ = require('lodash'); const _ = require('lodash');
const settings = require('../../../site/settings.json'); //const folks = require('../../../site/folks.json');
const folks = require('../../../site/folks.json');
const auth = new Auth(); const auth = new Auth();
const render = new Render(); const render = new Render();
const book = new Book(); const book = new Book();
const settingsData = new SettingsData(); const settings = new Settings();
const nav = new Navigation(); const nav = new Navigation();
const uploadPath = const uploadPath =
'./public/assets/images/user/' + moment().format('YYYY') + '/' + moment().format('MM'); './public/assets/images/user/' + moment().format('YYYY') + '/' + moment().format('MM');
@ -41,7 +40,7 @@ var background_upload = multer({
router.post('/sync', (req, res) => { router.post('/sync', (req, res) => {
auth.authCheck(req) auth.authCheck(req)
.then(() => { .then(() => {
settingsData settings
.sync(req, res) .sync(req, res)
.then(() => { .then(() => {
res.json({ res.json({
@ -92,10 +91,10 @@ router.post('/nav-sync', (req, res) => {
router.post('/publish-pages', (req, res) => { router.post('/publish-pages', (req, res) => {
auth.authCheck(req) auth.authCheck(req)
.then(() => { .then(() => {
book.getPage() getBookData()
.then(pages => { .then(result => {
render render
.publishAll(pages, settings.global.theme) .publishAll(result.pages, result.settings.global.theme)
.then(response => { .then(response => {
res.json({ res.json({
type: response.type, type: response.type,
@ -133,20 +132,30 @@ router.post('/publish-pages', (req, res) => {
router.post('/add-avatar', avatar_upload, (req, res) => { router.post('/add-avatar', avatar_upload, (req, res) => {
if (req.session.user) { if (req.session.user) {
let user = req.session.user; let user = req.session.user;
let found = _.find(folks, { handle: user.handle }); settings
if (found) { .load(SETTINGS_FOLKS)
var index = found.id - 1; .then(folks => {
var path = req.files[0].path; let found = _.find(folks, { handle: user.handle });
var image = path.substr(7, path.length); if (found) {
folks[index].avi = '/' + image; var index = found.id - 1;
fs.writeJson('site/folks.json', folks); var path = req.files[0].path;
user.avi = '/' + image; var image = path.substr(7, path.length);
res.json({ folks[index].avi = '/' + image;
type: DataEvent.AVATAR_UPLOADED, fs.writeJson('site/folks.json', folks);
message: 'Changed avi. You look great.', user.avi = '/' + image;
url: '/' + image res.json({
type: DataEvent.AVATAR_UPLOADED,
message: 'Changed avi. You look great.',
url: '/' + image
});
}
})
.catch(() => {
res.json({
type: DataEvent.REQUEST_LAME,
message: 'Members Not found'
});
}); });
}
} else { } else {
res.json({ res.json({
type: DataEvent.REQUEST_LAME, type: DataEvent.REQUEST_LAME,
@ -161,15 +170,22 @@ router.post('/add-avatar', avatar_upload, (req, res) => {
router.post('/add-feature-background', background_upload, (req, res) => { router.post('/add-feature-background', background_upload, (req, res) => {
if (req.session.user) { if (req.session.user) {
var path = req.files[0].path; settings
var image = path.substr(7, path.length); .load(SETTINGS_FILE)
settings.background = '/' + image; .then(settings => {
fs.writeJson('site/settings.json', settings); var path = req.files[0].path;
res.json({ var image = path.substr(7, path.length);
type: DataEvent.SITE_BACKGROUND_UPLOADED, settings.background = '/' + image;
message: 'Background Uploaded', fs.writeJson('site/settings.json', settings);
url: '/' + image res.json({
}); type: DataEvent.SITE_BACKGROUND_UPLOADED,
message: 'Background Uploaded',
url: '/' + image
});
})
.catch(err => {
console.log('ERROR', err);
});
} else { } else {
res.json({ res.json({
type: DataEvent.REQUEST_LAME, type: DataEvent.REQUEST_LAME,
@ -178,3 +194,19 @@ router.post('/add-feature-background', background_upload, (req, res) => {
} }
}); });
module.exports = router; module.exports = router;
function getBookData() {
return new Promise((resolve, reject) => {
let getSettings = settings.load(SETTINGS_FILE);
let getBook = book.getPage();
Promise.all([getSettings, getBook])
.then(result => {
const [settings, pages] = result;
let data = { settings: settings, pages: pages };
resolve(data);
})
.catch(err => {
reject(err);
});
});
}

View file

@ -29,7 +29,7 @@ export default class Book {
getPage(id) { getPage(id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fh.create() fh.create()
.paths('content/pages') .paths("content/pages")
.ext('md') .ext('md')
.find() .find()
.then(files => { .then(files => {
@ -66,7 +66,7 @@ export default class Book {
* @parameter body: object that contains all page information * @parameter body: object that contains all page information
* @parameter id: identifier for page being edited * @parameter id: identifier for page being edited
* @parameter task: type of task being performed - listed in DataEvents Class * @parameter task: type of task being performed - listed in DataEvents Class
* @parameter user: object containin user information * @parameter user: object contain user information
*/ */
editPage(body, id, task, user) { editPage(body, id, task, user) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View file

@ -145,19 +145,23 @@ export default class Render {
tag_list: item.tag_list tag_list: item.tag_list
} }
); );
fs.ensureDir('public/tags', () => {
fs.writeFile('public/tags/' + item.slug + '.html', file, err => { fs.writeFile('public/tags/' + item.slug + '.html', file, err => {
// throws an error, you could also catch it here // throws an error, you could also catch it here
if (err) { if (err) {
response = { type: DataEvent.TAG_PAGES_NOT_RENDERED, message: err }; response = {
reject(response); type: DataEvent.TAG_PAGES_NOT_RENDERED,
} message: err
// success case, the file was saved };
response = { reject(response);
type: DataEvent.TAG_PAGES_RENDERED, }
message: 'Tag Pages ready to go. Good job.' // success case, the file was saved
}; response = {
resolve(response); type: DataEvent.TAG_PAGES_RENDERED,
message: 'Tag Pages ready to go. Good job.'
};
resolve(response);
});
}); });
} }
}) })

View file

@ -51,11 +51,13 @@ export default class Utils {
let archive = []; let archive = [];
for (let index = 0; index < pages.length; index++) { for (let index = 0; index < pages.length; index++) {
let page = pages[index].metadata; let page = pages[index].metadata;
let year = moment(page.created).format('YYYY'); if (page.layout !== 'index') {
if (!_.find(years, { year: year })) { let year = moment(page.created).format('YYYY');
years.push({ year: year, count: 1 }); if (!_.find(years, { year: year })) {
} else { years.push({ year: year, count: 1 });
_.find(years, { year: year }).count++; } else {
_.find(years, { year: year }).count++;
}
} }
} }
years.sort((a, b) => parseFloat(b.year) - parseFloat(a.year)); years.sort((a, b) => parseFloat(b.year) - parseFloat(a.year));

View file

@ -1,36 +1,55 @@
import Book from '../../data/Book'; import Book from '../../data/Book';
import Settings, { SETTINGS_FILE } from '../../data/Settings';
const express = require('express'); const express = require('express');
const moment = require('moment'); const moment = require('moment');
const router = express.Router(); const router = express.Router();
const config = require('../../../site/settings.json'); //const config = require('../../../site/settings.json');
const book = new Book(); const book = new Book();
const settings = new Settings();
const indexLimit = 5; const indexLimit = 5;
//-------------------------- //--------------------------
// Index // Index
//-------------------------- //--------------------------
router.get('/', function (req, res) { router.get('/', function (req, res) {
book.getPage().then(result => { settings
result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id)); .load(SETTINGS_FILE)
let indexPages = []; .then(config => {
let indexCount = 0; book.getPage().then(result => {
result.forEach(page => { result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id));
if (typeof page.metadata.deleted === 'undefined' || page.metadata.deleted === false) { let indexPages = [];
if (indexCount === indexLimit) return; let indexCount = 0;
indexPages.push({ page: page, date: moment(page.metadata.created).fromNow() }); result.forEach(page => {
++indexCount; if (
typeof page.metadata.deleted === 'undefined' ||
page.metadata.deleted === false
) {
if (indexCount === indexLimit) return;
indexPages.push({
page: page,
date: moment(page.metadata.created).fromNow()
});
++indexCount;
}
});
let pageData = [];
if (req.session.user) {
pageData = { title: config.global.title, status: true, pages: indexPages };
} else {
pageData = { title: config.global.title, status: false, pages: indexPages };
}
res.render('index', pageData);
});
})
.catch(err => {
if (err.code === 'ENOENT') {
let setupData = { title: 'Fipamo Set up' };
res.render('init', setupData);
} else {
//render error page
} }
}); });
let pageData = [];
if (req.session.user) {
pageData = { title: config.global.title, status: true, pages: indexPages };
} else {
pageData = { title: config.global.title, status: false, pages: indexPages };
}
res.render('index', pageData);
});
}); });
//-------------------------- //--------------------------

View file

@ -1,68 +1,77 @@
import Book from '../../../brain/data/Book'; import Book from '../../../brain/data/Book';
import Settings, { SETTINGS_FILE } from '../../data/Settings';
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const _ = require('lodash'); const _ = require('lodash');
const settings = require('../../../site/settings.json'); //const settings = require('../../../site/settings.json');
const book = new Book(); const book = new Book();
const settings = new Settings();
//-------------------------- //--------------------------
// SETTINGS // SETTINGS
//-------------------------- //--------------------------
router.get('/', function (req, res) { router.get('/', function (req, res) {
if (req.session.user) { if (req.session.user) {
var nav = []; settings
book.getPage() .load(SETTINGS_FILE)
.then(pages => { .then(settings => {
if (settings.menu.length === 0) { var nav = [];
for (let index = 0; index < pages.length; index++) { book.getPage()
let item = pages[index].metadata; .then(pages => {
if (item.menu) { if (settings.menu.length === 0) {
nav.push({ for (let index = 0; index < pages.length; index++) {
id: item.id, let item = pages[index].metadata;
uuid: item.uuid, if (item.menu) {
title: item.title, nav.push({
slug: item.slug, id: item.id,
path: item.path uuid: item.uuid,
}); title: item.title,
} slug: item.slug,
} path: item.path
} else { });
let newpages = []; }
nav = settings.menu; }
for (let index = 0; index < pages.length; index++) {
let item = pages[index].metadata;
if (item.menu)
newpages.push({
id: item.id,
uuid: item.uuid,
title: item.title,
slug: item.slug,
path: item.path
});
}
for (let i = 0; i < newpages.length; i++) {
if (_.find(nav, { uuid: newpages[i].uuid })) {
//menu item already exists
} else { } else {
nav.push({ let newpages = [];
id: newpages[i].id, nav = settings.menu;
uuid: newpages[i].uuid, for (let index = 0; index < pages.length; index++) {
title: newpages[i].title, let item = pages[index].metadata;
slug: newpages[i].slug, if (item.menu)
path: newpages[i].path newpages.push({
}); id: item.id,
uuid: item.uuid,
title: item.title,
slug: item.slug,
path: item.path
});
}
for (let i = 0; i < newpages.length; i++) {
if (_.find(nav, { uuid: newpages[i].uuid })) {
//menu item already exists
} else {
nav.push({
id: newpages[i].id,
uuid: newpages[i].uuid,
title: newpages[i].title,
slug: newpages[i].slug,
path: newpages[i].path
});
}
}
} }
} res.render('navigation', {
} menu: nav,
res.render('navigation', { welcome: 'Edit Navigation',
menu: nav, status: true,
welcome: 'Edit Navigation', title: 'Dashboard | Navigation'
status: true, });
title: 'Dashboard | Navigation' })
}); .catch(err => {
//console.log('ERROR', err);
//render error pages
});
}) })
.catch(err => { .catch(err => {
//console.log('ERROR', err); console.log('ERROR', err);
//render error pages
}); });
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');

View file

@ -92,22 +92,27 @@ router.get('/list/:filter?/:page?', function (req, res) {
router.get('/add/new', function (req, res) { router.get('/add/new', function (req, res) {
if (req.session.user) { if (req.session.user) {
//need to grab a few copy of settings for the lastest index //need to grab a few copy of settings for the lastest index
fs.readJSON('site/settings.json') fs.ensureDir(
.then(config => { './public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM'),
res.render('page-edit', { () => {
id: config.library_stats.current_index, fs.readJSON('site/settings.json')
uuid: uuidv4(), .then(config => {
title: 'Add New Page', res.render('page-edit', {
user_status: true, id: config.library_stats.current_index,
welcome: 'Add New Page', uuid: uuidv4(),
date: moment(Date.now()).format('YYYY MMM DD'), title: 'Add New Page',
page: [], user_status: true,
rawDate: moment(Date.now()).format(), welcome: 'Add New Page',
status: ['false', 'false', 'false'], date: moment(Date.now()).format('YYYY MMM DD'),
edit: false page: [],
}); rawDate: moment(Date.now()).format(),
}) status: ['false', 'false', 'false'],
.catch(err => {}); edit: false
});
})
.catch(err => {});
}
);
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }

View file

@ -1,18 +1,21 @@
import Settings, { SETTINGS_FILE } from '../../data/Settings';
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const FileHound = require('filehound'); const FileHound = require('filehound');
const fs = require('fs-extra'); const fs = require('fs-extra');
var settings = []; const settings = new Settings();
var config = [];
//-------------------------- //--------------------------
// SETTINGS // SETTINGS
//-------------------------- //--------------------------
router.get('/', function (req, res) { router.get('/', function (req, res) {
fs.readJson('site/settings.json') settings
.load(SETTINGS_FILE)
.then(obj => { .then(obj => {
settings = obj; config = obj;
}) })
.catch(() => { .catch(err => {
//console.error(err); console.log('SETTINGS ERROR', err);
}); });
loadThemes().then(themes => { loadThemes().then(themes => {
if (req.session.user) { if (req.session.user) {
@ -34,7 +37,7 @@ router.get('/', function (req, res) {
welcome: 'Your Settings', welcome: 'Your Settings',
status: true, status: true,
themes: themes, themes: themes,
settings: settings, settings: config,
member: memberInfo[0] member: memberInfo[0]
}); });
} else { } else {
@ -46,30 +49,37 @@ module.exports = router;
function loadThemes() { function loadThemes() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
FileHound.create() settings
.paths('content/themes') .load(SETTINGS_FILE)
.ext('json') .then(settings => {
.find() FileHound.create()
.then(files => { .paths('content/themes')
let themes = []; .ext('json')
for (let index = 0; index < files.length; index++) { .find()
fs.readJSON(files[index], (err, theme) => { .then(files => {
if (theme.name == settings.global.theme) { let themes = [];
themes.push({ for (let index = 0; index < files.length; index++) {
theme: theme, fs.readJSON(files[index], (err, theme) => {
current: 'true' if (theme.name == settings.global.theme) {
}); themes.push({
} else { theme: theme,
themes.push({ current: 'true'
theme: theme, });
current: 'false' } else {
themes.push({
theme: theme,
current: 'false'
});
}
}); });
} }
setTimeout(() => {
resolve(themes);
}, 200);
})
.catch(err => {
reject(err);
}); });
}
setTimeout(() => {
resolve(themes);
}, 200);
}) })
.catch(err => { .catch(err => {
reject(err); reject(err);

31
brain/views/init.pug Normal file
View file

@ -0,0 +1,31 @@
extends frame
block main-content
#dash-index
#dash-index-wrapper
.dash-init#dash-init
h1 HI! Let's get you set up, champ.
h2 Just a few questions to get started
br
form#init-form
label What's your handle?
br
input(type='text', name='new_member_handle' id='new_member_handle', placeholder="What\'s your handle?")
br
label Let's get that email
br
input(type='text', name='new_member_email' id='new_member_email', placeholder="Email Please")
br
label Let's get a password
br
input(type='password', name='new_member_pass' id='new_member_pass', placeholder="Password Please")
br
label And let's confirm that password
br
input(type='password', name='new_member_pass2' id='new_member_pass2', placeholder="Email Confirm")
br
label And finally, a title
br
input(type='text', name='new_member_title' id='new_member_title', placeholder="Site Title Please")
br
button#init-blog(data-action='blog-init' type='submit') LETSGO

6
package-lock.json generated
View file

@ -5412,6 +5412,12 @@
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
}, },
"prettier": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz",
"integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==",
"dev": true
},
"private": { "private": {
"version": "0.1.8", "version": "0.1.8",
"resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz",

View file

@ -60,6 +60,7 @@
"animejs": "^3.2.0", "animejs": "^3.2.0",
"babel-preset-env": "^1.7.0", "babel-preset-env": "^1.7.0",
"bulma.styl": "^0.6.11", "bulma.styl": "^0.6.11",
"prettier": "^2.0.5",
"scramble-text": "0.0.8", "scramble-text": "0.0.8",
"stylus": "^0.54.7" "stylus": "^0.54.7"
} }

View file

@ -0,0 +1,14 @@
[
{
"id": "",
"handle": "",
"avi": "/assets/images/global/default-avi.png",
"email": "",
"password": "",
"key": "",
"role": "",
"created": "",
"updated": "",
"deleted": null
}
]

View file

@ -0,0 +1,26 @@
{
"global": {
"base_url": "http://your.domain",
"title": "This is a Title",
"descriptions": "Because it should be easy.",
"background": "/assets/images/global/default-bg.jpg",
"private": "true",
"renderOnSave": "false",
"theme": "default-light"
},
"library_stats": {
"current_index": 1
},
"email": {
"smtp": {
"domain": "",
"email": "",
"password": ""
},
"mailgun": {
"domain": "",
"api-key": ""
}
},
"menu": []
}

View file

@ -1,22 +0,0 @@
{
"url": "http://your.domain",
"title": "This is the title",
"description": "A few words describing the site",
"theme": "default-light",
"private": "false",
"feautred-url":"fancybackground.something",
"email":
{
"smtp":
{
"domain": "",
"email": "",
"password": ""
},
"mailgun":
{
"domain": "",
"api-key": ""
}
}
}

View file

@ -1,4 +1,9 @@
import FipamoApi, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON, API_LOGIN } from '../libraries/FipamoAPI'; import FipamoApi, {
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
API_LOGIN,
API_INIT
} from '../libraries/FipamoAPI';
import DataUitls from './utils/DataUtils'; import DataUitls from './utils/DataUtils';
import * as DataEvent from './events/DataEvent'; import * as DataEvent from './events/DataEvent';
import DashManager from './controllers/DashManager'; import DashManager from './controllers/DashManager';
@ -20,10 +25,16 @@ export default class Base {
// methods // methods
//-------------------------- //--------------------------
start() { start() {
if (document.getElementById('dash-form')) { if (document.getElementById('dash-form') || document.getElementById('dash-init')) {
document if (document.getElementById('dash-form')) {
.getElementById('login-btn') document
.addEventListener('click', e => this.handleLogin(e)); .getElementById('login-btn')
.addEventListener('click', e => this.handleLogin(e));
} else {
document
.getElementById('init-blog')
.addEventListener('click', e => this.handleSetup(e));
}
} else { } else {
new DashManager(); new DashManager();
} }
@ -57,4 +68,25 @@ export default class Base {
//console.log(err); //console.log(err);
}); });
} }
handleSetup(e) {
e.stopPropagation();
e.preventDefault();
let setUpForm = data.formDataToJSON(document.getElementById('init-form'));
api.request(API_INIT, DataEvent.API_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, setUpForm)
.then(r => {
let response = JSON.parse(r.request['response']);
if (response.type === DataEvent.API_INIT_LAME) {
notify.alert(response.message, false);
} else {
notify.alert(response.message, true);
setTimeout(() => {
//window.location = '/@/dashboard';
}, 500);
}
})
.catch(err => {
//console.log(err);
});
}
} }

View file

@ -29,6 +29,9 @@ export const API_PAGE_DELETE = 'erasingPage';
export const API_SETTINGS_WRITE = 'savingSettings'; export const API_SETTINGS_WRITE = 'savingSettings';
export const API_IMAGES_UPLOAD = 'uploadProfileImages'; export const API_IMAGES_UPLOAD = 'uploadProfileImages';
export const API_RENDER_PAGES = 'renderPages'; export const API_RENDER_PAGES = 'renderPages';
export const API_INIT = 'blogInit';
export const API_INIT_GOOD = 'blogInitGood';
export const API_INIT_LAME = 'blogInitLame';
class DataEvent { class DataEvent {
//-------------------------- //--------------------------
// methods // methods

View file

@ -5,6 +5,7 @@ export const REQUEST_TYPE_DELETE = 'DELETE';
export const CONTENT_TYPE_JSON = 'json'; export const CONTENT_TYPE_JSON = 'json';
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded'; export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
export const API_STATUS = '/api/v1/auth/status'; export const API_STATUS = '/api/v1/auth/status';
export const API_INIT = '/api/v1/auth/init';
export const API_LOGIN = '/api/v1/auth/login'; export const API_LOGIN = '/api/v1/auth/login';
export const API_GET_NAV = '/api/settings/nav'; export const API_GET_NAV = '/api/settings/nav';
export const API_NEW_PAGE = '/api/v1/page/write/new'; export const API_NEW_PAGE = '/api/v1/page/write/new';

View file

@ -14,6 +14,23 @@
height 100% height 100%
margin 0 auto margin 0 auto
.dash-init
width 100%
max-width 900px
margin 0 auto
color $secondary
label
color $primary
form
background $white
padding 10px
input[type=email], input[type=password], input[type=text]
margin-bottom 15px
button
height 30px
width 100px
#dash-login #dash-login
width 100% width 100%
max-width 900px max-width 900px