From de23e6c4985b705aac18affae1c10bf1c50ed7f5 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Mon, 15 May 2017 22:00:01 -0400 Subject: [PATCH] fix: automatic root admin creation if heroku --- CHANGELOG.md | 1 + README.md | 19 ++++++++----------- npm/configs/config.heroku.yml | 4 ++-- server/libs/auth.js | 30 +++++++++++++++++++++++++++--- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fba2930e..22a0d65a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- **Deploy**: Heroku support - **History**: History section to list all changes - **Localization**: All UI text elements are now localized - **Localization**: Chinese locale is now available (thanks to @choicky) diff --git a/README.md b/README.md index 7da50e9c..2128fe15 100644 --- a/README.md +++ b/README.md @@ -44,23 +44,19 @@ Wiki.js can run on virtually all platforms where Node.js can (Windows, Mac, Linu ## Milestones -Current and upcoming milestones *(features only, see the [changelog](https://github.com/Requarks/wiki/blob/master/CHANGELOG.md) for list of bug fixes)*: - -### Beta 11 - -- [x] Azure AD authentication -- [x] MathML / Tex math equations -- [x] Support for CJK (Chinese, Japanese & Korean) characters in content, meta and uploads -- [x] All Pages section +Current and upcoming milestones *(major features only, see the [changelog](https://github.com/Requarks/wiki/blob/master/CHANGELOG.md) for complete list of features and bug fixes)*: ### Beta 12 - [ ] Better localization in the UI +- [x] Heroku support + +### Beta 13 + - [ ] History / Revert to previous version feature - [ ] Docker support + Auto compile/publish to Docker Hub -- [ ] Heroku support -### Beta 13 +### Beta 14 - [ ] Insert Link modal in Editor - [ ] Better simultaneous user editing handling @@ -83,8 +79,9 @@ We are looking for translators to make Wiki.js available in multiple languages. **Languages that are already translated:** - [x] English -- [x] French - [x] Chinese - *Thanks to [@choicky](https://github.com/choicky)* +- [x] French +- [x] Korean - *Thanks to [@junwonpk](https://github.com/junwonpk)* - [x] Russian - *Thanks to [@efimlosev](https://github.com/efimlosev)* - [x] Spanish - *Thanks to [@MatiasArriola](https://github.com/MatiasArriola)* diff --git a/npm/configs/config.heroku.yml b/npm/configs/config.heroku.yml index 215a259c..b427046c 100644 --- a/npm/configs/config.heroku.yml +++ b/npm/configs/config.heroku.yml @@ -57,11 +57,11 @@ auth: local: enabled: true google: - enabled: true + enabled: false clientId: GOOGLE_CLIENT_ID clientSecret: GOOGLE_CLIENT_SECRET microsoft: - enabled: true + enabled: false clientId: MS_APP_ID clientSecret: MS_APP_SECRET facebook: diff --git a/server/libs/auth.js b/server/libs/auth.js index 3629a8f5..ab4de309 100644 --- a/server/libs/auth.js +++ b/server/libs/auth.js @@ -216,7 +216,7 @@ module.exports = function (passport) { // Create users for first-time db.onReady.then(() => { - db.User.findOne({ provider: 'local', email: 'guest' }).then((c) => { + return db.User.findOne({ provider: 'local', email: 'guest' }).then((c) => { if (c < 1) { // Create guest account @@ -238,8 +238,32 @@ module.exports = function (passport) { winston.error(err) }) } - }) + }).then(() => { + if (process.env.WIKI_JS_HEROKU) { + return db.User.findOne({ provider: 'local', email: process.env.WIKI_ADMIN_EMAIL }).then((c) => { + if (c < 1) { + // Create root admin account (HEROKU ONLY) - return true + return db.User.create({ + provider: 'local', + email: process.env.WIKI_ADMIN_EMAIL, + name: 'Administrator', + password: '$2a$04$MAHRw785Xe/Jd5kcKzr3D.VRZDeomFZu2lius4gGpZZ9cJw7B7Mna', // admin123 (default) + rights: [{ + role: 'admin', + path: '/', + exact: false, + deny: false + }] + }).then(() => { + winston.info('[AUTH] Root admin account created successfully!') + }).catch((err) => { + winston.error('[AUTH] An error occured while creating root admin account:') + winston.error(err) + }) + } else { return true } + }) + } else { return true } + }) }) }