浏览代码

fix: automatic root admin creation if heroku

NGPixel 8 年之前
父节点
当前提交
de23e6c498
共有 4 个文件被更改,包括 38 次插入16 次删除
  1. 1 0
      CHANGELOG.md
  2. 8 11
      README.md
  3. 2 2
      npm/configs/config.heroku.yml
  4. 27 3
      server/libs/auth.js

+ 1 - 0
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)

+ 8 - 11
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)*
 

+ 2 - 2
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:

+ 27 - 3
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 }
+    })
   })
 }