From fb9f18af2cbd7ad6ca1b06dd7972ce4fc90f5b5d Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Fri, 14 May 2021 23:45:20 +0800 Subject: [PATCH] Add Email provider. --- object/provider.go | 3 ++ web/src/OrganizationEditPage.js | 2 +- web/src/ProviderEditPage.js | 83 +++++++++++++++++++++++++++------ web/src/ProviderListPage.js | 20 ++++++-- web/src/UrlTable.js | 4 +- web/src/auth/LoginPage.js | 2 +- web/src/locales/en.json | 5 +- web/src/locales/zh.json | 7 +-- 8 files changed, 101 insertions(+), 25 deletions(-) diff --git a/object/provider.go b/object/provider.go index 21c3876f..24c04b31 100644 --- a/object/provider.go +++ b/object/provider.go @@ -25,9 +25,12 @@ type Provider struct { CreatedTime string `xorm:"varchar(100)" json:"createdTime"` DisplayName string `xorm:"varchar(100)" json:"displayName"` + Category string `xorm:"varchar(100)" json:"category"` Type string `xorm:"varchar(100)" json:"type"` ClientId string `xorm:"varchar(100)" json:"clientId"` ClientSecret string `xorm:"varchar(100)" json:"clientSecret"` + Host string `xorm:"varchar(100)" json:"host"` + Port int `json:"port"` ProviderUrl string `xorm:"varchar(200)" json:"providerUrl"` } diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index e68b65fc..3265d826 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -121,7 +121,7 @@ class OrganizationEditPage extends React.Component { {i18next.t("organization:Website URL")}: - { + } value={this.state.organization.websiteUrl} onChange={e => { this.updateOrganizationField('websiteUrl', e.target.value); }} /> diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index c071f312..62497071 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -13,7 +13,8 @@ // limitations under the License. import React from "react"; -import {Button, Card, Col, Input, Row, Select} from 'antd'; +import {Button, Card, Col, Input, InputNumber, Row, Select} from 'antd'; +import {LinkOutlined} from "@ant-design/icons"; import * as ProviderBackend from "./backend/ProviderBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; @@ -44,9 +45,9 @@ class ProviderEditPage extends React.Component { } parseProviderField(key, value) { - // if ([].includes(key)) { - // value = Setting.myParseInt(value); - // } + if (["port"].includes(key)) { + value = Setting.myParseInt(value); + } return value; } @@ -60,6 +61,29 @@ class ProviderEditPage extends React.Component { }); } + getProviderTypeOptions(provider) { + if (provider.category === "OAuth") { + return ( + [ + {id: 'Google', name: 'Google'}, + {id: 'GitHub', name: 'GitHub'}, + {id: 'QQ', name: 'QQ'}, + {id: 'WeChat', name: 'WeChat'}, + ] + ); + } else if (provider.category === "Email") { + return ( + [ + {id: 'Default', name: 'Default'}, + ] + ); + } else { + return ( + [] + ); + } + } + renderProvider() { return ( - {i18next.t("provider:Type")}: + {i18next.t("provider:Category")}: - {this.updateProviderField('category', value);})}> { [ - {id: 'Google', name: 'Google'}, - {id: 'GitHub', name: 'GitHub'}, - {id: 'QQ', name: 'QQ'}, - {id: 'WeChat', name: 'WeChat'}, - ].map((providerType, index) => ) + {id: 'OAuth', name: 'OAuth'}, + {id: 'Email', name: 'Email'}, + {id: 'Phone', name: 'Phone'}, + ].map((providerCategory, index) => ) } - {i18next.t("provider:Client ID")}: + {i18next.t("provider:Type")}: + + + + + + + + {this.state.provider.category === "Email" ? i18next.t("signup:Username") : i18next.t("provider:Client ID")}: { @@ -117,7 +152,7 @@ class ProviderEditPage extends React.Component { - {i18next.t("provider:Client secret")}: + {this.state.provider.category === "Email" ? i18next.t("login:Password") : i18next.t("provider:Client secret")}: { @@ -125,12 +160,32 @@ class ProviderEditPage extends React.Component { }} /> + + + {i18next.t("provider:Host")}: + + + } value={this.state.provider.host} onChange={e => { + this.updateProviderField('host', e.target.value); + }} /> + + + + + {i18next.t("provider:Port")}: + + + { + this.updateProviderField('port', value); + }} /> + + {i18next.t("provider:Provider URL")}: - { + } value={this.state.provider.providerUrl} onChange={e => { this.updateProviderField('providerUrl', e.target.value); }} /> diff --git a/web/src/ProviderListPage.js b/web/src/ProviderListPage.js index 59c6dbe2..09b09d04 100644 --- a/web/src/ProviderListPage.js +++ b/web/src/ProviderListPage.js @@ -49,9 +49,12 @@ class ProviderListPage extends React.Component { name: `provider_${this.state.providers.length}`, createdTime: moment().format(), displayName: `New Provider - ${this.state.providers.length}`, + category: "OAuth", type: "GitHub", clientId: "", clientSecret: "", + host: "", + port: 0, providerUrl: "https://github.com/organizations/xxx/settings/applications/1234567", } } @@ -118,6 +121,13 @@ class ProviderListPage extends React.Component { // width: '100px', sorter: (a, b) => a.displayName.localeCompare(b.displayName), }, + { + title: i18next.t("provider:Category"), + dataIndex: 'category', + key: 'category', + width: '100px', + sorter: (a, b) => a.category.localeCompare(b.category), + }, { title: i18next.t("provider:Type"), dataIndex: 'type', @@ -125,9 +135,13 @@ class ProviderListPage extends React.Component { width: '80px', sorter: (a, b) => a.type.localeCompare(b.type), render: (text, record, index) => { - return ( - {record.displayName} - ) + if (record.category !== "OAuth") { + return text; + } else { + return ( + {record.displayName} + ) + } } }, { diff --git a/web/src/UrlTable.js b/web/src/UrlTable.js index 6a40a3a3..661f3372 100644 --- a/web/src/UrlTable.js +++ b/web/src/UrlTable.js @@ -13,7 +13,7 @@ // limitations under the License. import React from "react"; -import {DownOutlined, DeleteOutlined, UpOutlined} from '@ant-design/icons'; +import {DownOutlined, DeleteOutlined, UpOutlined, LinkOutlined} from '@ant-design/icons'; import {Button, Col, Input, Row, Table, Tooltip} from 'antd'; import * as Setting from "./Setting"; @@ -66,7 +66,7 @@ class UrlTable extends React.Component { key: 'id', render: (text, record, index) => { return ( - { + } value={text} onChange={e => { this.updateField(table, index, e.target.value); }} /> ) diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index 4fea16f3..ece6f079 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -184,7 +184,7 @@ class LoginPage extends React.Component { } type="password" - placeholder={i18next.t("login:password")} + placeholder={i18next.t("login:Password")} disabled={!application.enablePassword} /> diff --git a/web/src/locales/en.json b/web/src/locales/en.json index b2cd9a8d..ec8efed3 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -55,7 +55,7 @@ "Please input your username, Email or phone number!": "Please input your username, Email or phone number!", "username, Email or phone number": "username, Email or phone number", "Please input your password!": "Please input your password!", - "password": "password", + "Password": "Password", "Auto login": "Auto login", "Forgot password?": "Forgot password?", "Sign In": "Sign In", @@ -77,6 +77,9 @@ }, "provider": { + "Name": "Name", + "Display name": "Display name", + "Category": "Category", "Type": "Type", "Client ID": "Client ID", "Client secret": "Client secret", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 2a95df12..1a9716b3 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -30,7 +30,7 @@ "OAuth providers": "OAuth提供方", "Applications that requires authentication": "需要鉴权的应用", "Swagger": "API总览", - "Phone Prefix": "电话前缀" + "Phone Prefix": "手机号前缀" }, "signup": { @@ -55,7 +55,7 @@ "Please input your username, Email or phone number!": "请输入您的用户名、Email或手机号!", "username, Email or phone number": "用户名、Email或手机号", "Please input your password!": "请输入您的密码!", - "password": "密码", + "Password": "密码", "Auto login": "下次自动登录", "Forgot password?": "忘记密码?", "Sign In": "登录", @@ -79,6 +79,7 @@ { "Name": "名称", "Display name": "显示名称", + "Category": "分类", "Type": "类型", "Client ID": "Client ID", "Client secret": "Client secret", @@ -123,7 +124,7 @@ "Reset Phone": "重置手机号", "Send Code": "发送验证码", "Empty email": "邮箱为空", - "Empty phone": "电话为空", + "Empty phone": "手机号为空", "Empty Code": "验证码为空", "phone reset": "手机号已设置", "email reset": "邮箱已设置",