From ceae2b25b59189bcc17af5df3e8f10f76094c7d7 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 13 Mar 2021 20:39:29 +0100 Subject: [PATCH] Make the login form pluggable Allow extending the login form with additional authentication methods by adding them to the web plugin's loginForms array. --- packages/lib/plugin.js | 22 +++++++++ packages/web_ui/src/components/App.jsx | 5 +- packages/web_ui/src/components/LoginForm.jsx | 52 ++++++++++++++++---- 3 files changed, 66 insertions(+), 13 deletions(-) diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index 68687718..960150a0 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -424,6 +424,21 @@ class BaseControlPlugin { } +/** + * Plugin supplied login form + * @typedef {Object} module:lib/plugin~LoginForm + * @property {string} name - + * Internal name of the login form, this should start with the + * plugin name followed by a dot. + * @property {string} title - + * Name displayed above this form in the login window. + * @property {React.Component} Component - + * React component that's rendered for this login form. This is + * supplied the setToken function via its props which should be + * called when an authentication token is aquired via this + * form. + */ + /** * Base class for web interface plugins * @@ -455,6 +470,13 @@ class BaseWebPlugin { * `error`, `warn`, `audit`, `info` and `verbose`. */ this.logger = logger.child({ plugin: this.info.name }); + + /** + * List of login forms provided by this plugin + * + * @type {Array} + */ + this.loginForms = []; } /** diff --git a/packages/web_ui/src/components/App.jsx b/packages/web_ui/src/components/App.jsx index 255f1aa1..c326d014 100644 --- a/packages/web_ui/src/components/App.jsx +++ b/packages/web_ui/src/components/App.jsx @@ -81,10 +81,7 @@ export default function App(props) { } else { page =
- -

Clusterio

- -
+
; } diff --git a/packages/web_ui/src/components/LoginForm.jsx b/packages/web_ui/src/components/LoginForm.jsx index 6a5a13cf..7e78b915 100644 --- a/packages/web_ui/src/components/LoginForm.jsx +++ b/packages/web_ui/src/components/LoginForm.jsx @@ -1,27 +1,61 @@ -import React from "react"; -import { Form, Input, Button } from "antd"; +import React, { Fragment, useContext } from "react"; +import { Button, Card, Divider, Form, Image, Input, List, Space, Spin, Typography } from "antd"; import LockOutlined from "@ant-design/icons/LockOutlined"; -export default function LoginForm(props) { - return ( +import logo from "../images/logo.png"; +import PluginsContext from "./PluginsContext"; + +const { Paragraph, Text } = Typography; + + +function TokenAuth(props) { + return <> + If you have generated an authentication token from the master server, use that here.
{ props.setToken(values.token); }} + layout="inline" > } + style={{ width: "14em" }} + prefix= type="password" placeholder="Authentication Token" />
- ); + ; +} + +export default function LoginForm(props) { + let plugins = useContext(PluginsContext); + + let loginForms = []; + for (let plugin of plugins.values()) { + loginForms.push(...plugin.loginForms); + } + + loginForms.push({ + name: "core.token", + title: "Token", + Component: TokenAuth, + }); + + return + +

Clusterio

+ + Log in to the cluster using one of the methods below. +
+ {loginForms.map(form => + {form.title} + + )} +
; }