Просмотр исходного кода

Redirect to /login & Added translations

Taichi Masuyama 3 лет назад
Родитель
Сommit
cd2c234438

+ 2 - 1
packages/app/public/static/locales/en_US/translation.json

@@ -192,7 +192,8 @@
     "create_initial_account": "Create an initial account",
     "initial_account_will_be_administrator_automatically": "The initial account will be administrator automatically.",
     "unavaliable_user_id": "This 'User ID' is unavailable.",
-    "failed_to_install": "Failed to install GROWI."
+    "failed_to_install": "Failed to install GROWI. Please try again.",
+    "failed_to_login_after_install": "Failed to login after installation. Redirecting to the login form ..."
   },
   "breaking_changes": {
     "v346_using_basic_auth": "Basic Authentication currently in use will <strong>no longer be available</strong> in the near future. Remove settings from %s"

+ 2 - 1
packages/app/public/static/locales/ja_JP/translation.json

@@ -185,7 +185,8 @@
     "create_initial_account": "最初のアカウントの作成",
     "initial_account_will_be_administrator_automatically": "初めに作成するアカウントは、自動的に管理者権限が付与されます",
     "unavaliable_user_id": "このユーザーIDは利用できません。",
-    "failed_to_install": "GROWI のインストールに失敗しました。"
+    "failed_to_install": "GROWI のインストールに失敗しました。再度お試しください。",
+    "failed_to_login_after_install": "インストール後、ログインに失敗しました。ログインフォームに遷移しています ..."
   },
   "breaking_changes": {
     "v346_using_basic_auth": "現在利用中の Basic 認証機能は、近い将来<strong>廃止されます</strong>。%s から設定を削除してください。"

+ 2 - 1
packages/app/public/static/locales/zh_CN/translation.json

@@ -187,7 +187,8 @@
 		"create_initial_account": "创建初始用户",
 		"initial_account_will_be_administrator_automatically": "初始帐户将自动成为管理员。",
 		"unavaliable_user_id": "用户ID不可用",
-    "failed_to_install": "GROWI安装失败。"
+    "failed_to_install": "GROWI安装失败。请再试一次。",
+    "failed_to_login_after_install": "安装后登录失败。重定向到登录表格..."
 	},
 	"breaking_changes": {
 		"v346_using_basic_auth": "当前使用的基本身份验证在不久的将来将不再可用。从%s中删除设置"

+ 10 - 2
packages/app/src/components/InstallerForm.tsx

@@ -7,8 +7,8 @@ import { useTranslation, i18n } from 'next-i18next';
 
 import { i18n as i18nConfig } from '^/config/next-i18next.config';
 
-import { apiv3Post } from '~/client/util/apiv3-client';
 import { toastError } from '~/client/util/apiNotification';
+import { apiv3Post } from '~/client/util/apiv3-client';
 
 const InstallerForm = memo((): JSX.Element => {
   const { t } = useTranslation();
@@ -67,7 +67,15 @@ const InstallerForm = memo((): JSX.Element => {
       await apiv3Post('/installer', data);
       window.location.href = '/';
     }
-    catch (err) {
+    catch (errs) {
+      const err = errs[0];
+      const code = err.code;
+
+      if (code === 'failed_to_login_after_install') {
+        toastError(t('installer.failed_to_login_after_install'));
+        setTimeout(() => { window.location.href = '/login' }, 700); // Wait 700 ms to show toastr
+      }
+
       toastError(t('installer.failed_to_install'));
     }
   }, [isSubmittingDisabled, t]);

+ 7 - 1
packages/app/src/server/routes/apiv3/index.js

@@ -13,7 +13,7 @@ const router = express.Router();
 const routerForAdmin = express.Router();
 const routerForAuth = express.Router();
 
-module.exports = (crowi) => {
+module.exports = (crowi, isInstalled) => {
 
   // add custom functions to express response
   require('./response')(express, crowi);
@@ -40,6 +40,12 @@ module.exports = (crowi) => {
   // auth
   routerForAuth.use('/logout', require('./logout')(crowi));
 
+  // installer
+  if (!isInstalled) {
+    routerForAdmin.use('/installer', require('./installer')(crowi));
+    return [router, routerForAdmin, routerForAuth];
+  }
+
   router.use('/in-app-notification', require('./in-app-notification')(crowi));
 
   router.use('/personal-setting', require('./personal-setting')(crowi));

+ 2 - 2
packages/app/src/server/routes/apiv3/installer.ts

@@ -52,9 +52,9 @@ module.exports = (crowi: Crowi): Router => {
     }
     catch (err) {
       if (err instanceof FailedToCreateAdminUserError) {
-        return res.apiv3Err(new ErrorV3(err.message, 'failed_to_create_admin_user'));
+        return res.apiv3Err(new ErrorV3(err.message, 'failed_to_install'));
       }
-      return res.apiv3Err(new ErrorV3(err, 'failed_to_create_admin_user'));
+      return res.apiv3Err(new ErrorV3(err, 'failed_to_install'));
     }
 
     await appService.setupAfterInstall();

+ 1 - 4
packages/app/src/server/routes/index.js

@@ -52,8 +52,6 @@ module.exports = function(crowi, app) {
   // const hackmd = require('./hackmd')(crowi, app);
   const ogp = require('./ogp')(crowi);
 
-  const apiv3Installer = require('./apiv3/installer')(crowi);
-
   const next = nextFactory(crowi);
 
   const unavailableWhenMaintenanceMode = generateUnavailableWhenMaintenanceModeMiddleware(crowi);
@@ -63,7 +61,7 @@ module.exports = function(crowi, app) {
 
   /* eslint-disable max-len, comma-spacing, no-multi-spaces */
 
-  const [apiV3Router, apiV3AdminRouter, apiV3AuthRouter] = require('./apiv3')(crowi);
+  const [apiV3Router, apiV3AdminRouter, apiV3AuthRouter] = require('./apiv3')(crowi, isInstalled);
 
   app.use('/api-docs', require('./apiv3/docs')(crowi));
 
@@ -95,7 +93,6 @@ module.exports = function(crowi, app) {
 
   // installer
   if (!isInstalled) {
-    app.use('/_api/v3/installer', applicationNotInstalled, apiv3Installer);
     app.get('/installer'              , applicationNotInstalled, next.delegateToNext);
     return;
   }