2022-02-13 23:39:27 +08:00
|
|
|
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
2021-02-13 12:15:19 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-11-07 15:41:24 +08:00
|
|
|
import {message, Tag, Tooltip} from "antd";
|
2021-06-25 00:13:43 +08:00
|
|
|
import {QuestionCircleTwoTone} from "@ant-design/icons";
|
2021-02-13 12:15:19 +08:00
|
|
|
import React from "react";
|
|
|
|
import {isMobile as isMobileDevice} from "react-device-detect";
|
2021-02-19 23:23:59 +08:00
|
|
|
import "./i18n";
|
|
|
|
import i18next from "i18next";
|
2021-03-14 23:08:08 +08:00
|
|
|
import copy from "copy-to-clipboard";
|
2021-04-28 22:40:21 +08:00
|
|
|
import {authConfig} from "./auth/Auth";
|
2021-04-29 21:28:24 +08:00
|
|
|
import {Helmet} from "react-helmet";
|
2021-09-14 01:22:13 +08:00
|
|
|
import moment from "moment";
|
2022-03-27 16:03:25 +08:00
|
|
|
import * as Conf from "./Conf";
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2021-02-13 21:04:23 +08:00
|
|
|
export let ServerUrl = "";
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2021-06-12 12:07:24 +08:00
|
|
|
// export const StaticBaseUrl = "https://cdn.jsdelivr.net/gh/casbin/static";
|
|
|
|
export const StaticBaseUrl = "https://cdn.casbin.org";
|
2021-06-12 11:52:59 +08:00
|
|
|
|
2021-07-31 16:02:48 +08:00
|
|
|
// https://catamphetamine.gitlab.io/country-flag-icons/3x2/index.html
|
2022-03-27 16:03:25 +08:00
|
|
|
export const CountryRegionData = getCountryRegionData();
|
2021-11-10 22:27:58 +08:00
|
|
|
|
2022-04-21 21:52:34 +08:00
|
|
|
export const OtherProviderInfo = {
|
|
|
|
SMS: {
|
|
|
|
"Aliyun SMS": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_aliyun.png`,
|
|
|
|
url: "https://aliyun.com/product/sms",
|
|
|
|
},
|
|
|
|
"Tencent Cloud SMS": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_tencent_cloud.jpg`,
|
|
|
|
url: "https://cloud.tencent.com/product/sms",
|
|
|
|
},
|
|
|
|
"Volc Engine SMS": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_volc_engine.jpg`,
|
|
|
|
url: "https://www.volcengine.com/products/cloud-sms",
|
|
|
|
},
|
|
|
|
"Huawei Cloud SMS": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_huawei.png`,
|
|
|
|
url: "https://www.huaweicloud.com/product/msgsms.html",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Email: {
|
|
|
|
"Default": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_default.png`,
|
|
|
|
url: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Storage: {
|
|
|
|
"Local File System": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_file.png`,
|
|
|
|
url: "",
|
|
|
|
},
|
|
|
|
"AWS S3": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_aws.png`,
|
|
|
|
url: "https://aws.amazon.com/s3",
|
|
|
|
},
|
|
|
|
"Aliyun OSS": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_aliyun.png`,
|
|
|
|
url: "https://aliyun.com/product/oss",
|
|
|
|
},
|
|
|
|
"Tencent Cloud COS": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_tencent_cloud.jpg`,
|
|
|
|
url: "https://cloud.tencent.com/product/cos",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SAML: {
|
|
|
|
"Aliyun IDaaS": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_aliyun.png`,
|
|
|
|
url: "https://aliyun.com/product/idaas"
|
|
|
|
},
|
|
|
|
"Keycloak": {
|
|
|
|
logo: `${StaticBaseUrl}/img/social_keycloak.png`,
|
|
|
|
url: "https://www.keycloak.org/"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Payment: {
|
|
|
|
"Alipay": {
|
|
|
|
logo: `${StaticBaseUrl}/img/payment_alipay.png`,
|
|
|
|
url: "https://www.alipay.com/"
|
|
|
|
},
|
|
|
|
"WeChat Pay": {
|
|
|
|
logo: `${StaticBaseUrl}/img/payment_wechat_pay.png`,
|
|
|
|
url: "https://pay.weixin.qq.com/"
|
|
|
|
},
|
|
|
|
"PayPal": {
|
|
|
|
logo: `${StaticBaseUrl}/img/payment_paypal.png`,
|
|
|
|
url: "https://www.paypal.com/"
|
|
|
|
},
|
|
|
|
"GC": {
|
|
|
|
logo: `${StaticBaseUrl}/img/payment_gc.png`,
|
|
|
|
url: "https://gc.org"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-11-10 22:27:58 +08:00
|
|
|
export function getCountryRegionData() {
|
2022-03-27 16:03:25 +08:00
|
|
|
let language = i18next.language;
|
|
|
|
if (language === null || language === "null") {
|
|
|
|
language = Conf.DefaultLanguage;
|
|
|
|
}
|
|
|
|
|
2021-11-10 22:27:58 +08:00
|
|
|
var countries = require("i18n-iso-countries");
|
2022-03-27 16:03:25 +08:00
|
|
|
countries.registerLocale(require("i18n-iso-countries/langs/" + language + ".json"));
|
|
|
|
var data = countries.getNames(language, {select: "official"});
|
2021-11-10 22:27:58 +08:00
|
|
|
var result = []
|
|
|
|
for (var i in data)
|
|
|
|
result.push({code:i, name:data[i]})
|
|
|
|
return result
|
|
|
|
}
|
2021-07-31 16:02:48 +08:00
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
export function initServerUrl() {
|
2022-01-29 21:52:04 +08:00
|
|
|
//const hostname = window.location.hostname;
|
|
|
|
// if (hostname === "localhost") {
|
|
|
|
// ServerUrl = `http://${hostname}:8000`;
|
|
|
|
// }
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
2021-09-12 12:09:44 +08:00
|
|
|
export function isLocalhost() {
|
2021-05-14 15:55:50 +08:00
|
|
|
const hostname = window.location.hostname;
|
|
|
|
return hostname === "localhost";
|
|
|
|
}
|
|
|
|
|
2021-08-08 14:18:44 +08:00
|
|
|
export function getFullServerUrl() {
|
|
|
|
let fullServerUrl = window.location.origin;
|
|
|
|
if (fullServerUrl === "http://localhost:7001") {
|
|
|
|
fullServerUrl = "http://localhost:8000";
|
|
|
|
}
|
|
|
|
return fullServerUrl;
|
|
|
|
}
|
|
|
|
|
2021-06-14 21:35:19 +08:00
|
|
|
export function isProviderVisible(providerItem) {
|
|
|
|
if (providerItem.provider === undefined || providerItem.provider === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-06 21:46:50 +08:00
|
|
|
if (providerItem.provider.category !== "OAuth" && providerItem.provider.category !== "SAML") {
|
2021-06-17 01:49:05 +08:00
|
|
|
return false;
|
2021-05-14 15:55:50 +08:00
|
|
|
}
|
|
|
|
|
2022-04-15 11:49:56 +08:00
|
|
|
if (providerItem.provider.type === "WeChatMiniProgram"){
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-19 19:43:54 +08:00
|
|
|
return true;
|
2021-06-14 21:35:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isProviderVisibleForSignUp(providerItem) {
|
|
|
|
if (providerItem.canSignUp === false) {
|
|
|
|
return false;
|
2021-05-14 15:55:50 +08:00
|
|
|
}
|
2021-06-14 21:35:19 +08:00
|
|
|
|
|
|
|
return isProviderVisible(providerItem);
|
2021-05-14 15:55:50 +08:00
|
|
|
}
|
|
|
|
|
2021-06-14 21:35:19 +08:00
|
|
|
export function isProviderVisibleForSignIn(providerItem) {
|
|
|
|
if (providerItem.canSignIn === false) {
|
2021-06-09 20:39:43 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-14 21:35:19 +08:00
|
|
|
return isProviderVisible(providerItem);
|
2021-06-09 20:39:43 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 23:43:36 +08:00
|
|
|
export function isProviderPrompted(providerItem) {
|
|
|
|
return isProviderVisible(providerItem) && providerItem.prompted;
|
|
|
|
}
|
|
|
|
|
2021-06-20 09:46:06 +08:00
|
|
|
export function getAllPromptedProviderItems(application) {
|
|
|
|
return application.providers.filter(providerItem => isProviderPrompted(providerItem));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSignupItem(application, itemName) {
|
2021-06-22 11:31:53 +08:00
|
|
|
const signupItems = application.signupItems?.filter(signupItem => signupItem.name === itemName);
|
2021-06-20 09:46:06 +08:00
|
|
|
if (signupItems.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return signupItems[0];
|
|
|
|
}
|
|
|
|
|
2021-09-21 14:04:17 +08:00
|
|
|
export function isValidEmail(email) {
|
|
|
|
// https://github.com/yiminghe/async-validator/blob/057b0b047f88fac65457bae691d6cb7c6fe48ce1/src/rule/type.ts#L9
|
|
|
|
const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
|
|
return emailRegex.test(email);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isValidPhone(phone) {
|
|
|
|
// https://learnku.com/articles/31543, `^s*$` filter empty email individually.
|
|
|
|
const phoneRegex = /^\s*$|^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
|
|
|
|
return phoneRegex.test(phone);
|
|
|
|
}
|
|
|
|
|
2021-06-20 09:46:06 +08:00
|
|
|
export function isAffiliationPrompted(application) {
|
|
|
|
const signupItem = getSignupItem(application, "Affiliation");
|
|
|
|
if (signupItem === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return signupItem.prompted;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hasPromptPage(application) {
|
|
|
|
const providerItems = getAllPromptedProviderItems(application);
|
|
|
|
if (providerItems.length !== 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isAffiliationPrompted(application);
|
|
|
|
}
|
|
|
|
|
2021-06-20 22:17:03 +08:00
|
|
|
function isAffiliationAnswered(user, application) {
|
|
|
|
if (!isAffiliationPrompted(application)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return user.affiliation !== "";
|
|
|
|
}
|
|
|
|
|
|
|
|
function isProviderItemAnswered(user, application, providerItem) {
|
|
|
|
if (user === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const provider = providerItem.provider;
|
|
|
|
const linkedValue = user[provider.type.toLowerCase()];
|
|
|
|
return linkedValue !== undefined && linkedValue !== "";
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isPromptAnswered(user, application) {
|
|
|
|
if (!isAffiliationAnswered(user, application)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const providerItems = getAllPromptedProviderItems(application);
|
|
|
|
for (let i = 0; i < providerItems.length; i ++) {
|
|
|
|
if (!isProviderItemAnswered(user, application, providerItems[i])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
export function parseJson(s) {
|
|
|
|
if (s === "") {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return JSON.parse(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function myParseInt(i) {
|
|
|
|
const res = parseInt(i);
|
|
|
|
return isNaN(res) ? 0 : res;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function openLink(link) {
|
|
|
|
// this.props.history.push(link);
|
|
|
|
const w = window.open('about:blank');
|
|
|
|
w.location.href = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function goToLink(link) {
|
|
|
|
window.location.href = link;
|
|
|
|
}
|
|
|
|
|
2021-03-26 21:58:19 +08:00
|
|
|
export function goToLinkSoft(ths, link) {
|
2022-04-25 13:27:26 +08:00
|
|
|
if (link.startsWith("http")) {
|
|
|
|
openLink(link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-26 21:58:19 +08:00
|
|
|
ths.props.history.push(link);
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
export function showMessage(type, text) {
|
|
|
|
if (type === "") {
|
|
|
|
return;
|
|
|
|
} else if (type === "success") {
|
|
|
|
message.success(text);
|
|
|
|
} else if (type === "error") {
|
|
|
|
message.error(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 17:34:32 +08:00
|
|
|
export function isAdminUser(account) {
|
2021-03-28 16:35:59 +08:00
|
|
|
if (account === undefined || account === null) {
|
2021-03-21 00:44:19 +08:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-15 22:14:19 +08:00
|
|
|
return account.owner === "built-in" || account.isGlobalAdmin === true;
|
2021-02-13 17:34:32 +08:00
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
export function deepCopy(obj) {
|
|
|
|
return Object.assign({}, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addRow(array, row) {
|
|
|
|
return [...array, row];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function prependRow(array, row) {
|
|
|
|
return [row, ...array];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deleteRow(array, i) {
|
|
|
|
// return array = array.slice(0, i).concat(array.slice(i + 1));
|
|
|
|
return [...array.slice(0, i), ...array.slice(i + 1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function swapRow(array, i, j) {
|
|
|
|
return [...array.slice(0, i), array[j], ...array.slice(i + 1, j), array[i], ...array.slice(j + 1)];
|
|
|
|
}
|
|
|
|
|
2021-05-24 20:48:04 +08:00
|
|
|
export function trim(str, ch) {
|
|
|
|
if (str === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
let start = 0;
|
|
|
|
let end = str.length;
|
|
|
|
|
|
|
|
while(start < end && str[start] === ch)
|
|
|
|
++start;
|
|
|
|
|
|
|
|
while(end > start && str[end - 1] === ch)
|
|
|
|
--end;
|
|
|
|
|
|
|
|
return (start > 0 || end < str.length) ? str.substring(start, end) : str;
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
export function isMobile() {
|
|
|
|
// return getIsMobileView();
|
|
|
|
return isMobileDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFormattedDate(date) {
|
|
|
|
if (date === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
date = date.replace('T', ' ');
|
|
|
|
date = date.replace('+08:00', ' ');
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFormattedDateShort(date) {
|
|
|
|
return date.slice(0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getShortName(s) {
|
|
|
|
return s.split('/').slice(-1)[0];
|
|
|
|
}
|
|
|
|
|
2021-02-13 23:00:43 +08:00
|
|
|
export function getShortText(s, maxLength=35) {
|
|
|
|
if (s.length > maxLength) {
|
|
|
|
return `${s.slice(0, maxLength)}...`;
|
|
|
|
} else {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 00:17:53 +08:00
|
|
|
export function getFriendlyFileSize(size) {
|
|
|
|
if (size < 1024) {
|
|
|
|
return size + ' B';
|
|
|
|
}
|
|
|
|
|
|
|
|
let i = Math.floor(Math.log(size) / Math.log(1024));
|
|
|
|
let num = (size / Math.pow(1024, i));
|
|
|
|
let round = Math.round(num);
|
|
|
|
num = round < 10 ? num.toFixed(2) : round < 100 ? num.toFixed(1) : round;
|
|
|
|
return `${num} ${'KMGTPEZY'[i-1]}B`;
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
function getRandomInt(s) {
|
|
|
|
let hash = 0;
|
|
|
|
if (s.length !== 0) {
|
|
|
|
for (let i = 0; i < s.length; i ++) {
|
|
|
|
let char = s.charCodeAt(i);
|
|
|
|
hash = ((hash << 5) - hash) + char;
|
|
|
|
hash = hash & hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getAvatarColor(s) {
|
|
|
|
const colorList = ['#f56a00', '#7265e6', '#ffbf00', '#00a2ae'];
|
|
|
|
let random = getRandomInt(s);
|
|
|
|
if (random < 0) {
|
|
|
|
random = -random;
|
|
|
|
}
|
|
|
|
return colorList[random % 4];
|
|
|
|
}
|
2021-02-19 23:23:59 +08:00
|
|
|
|
2022-02-27 14:02:52 +08:00
|
|
|
export function getLanguage() {
|
|
|
|
return i18next.language;
|
|
|
|
}
|
|
|
|
|
2021-09-14 01:22:13 +08:00
|
|
|
export function setLanguage(language) {
|
|
|
|
localStorage.setItem("language", language);
|
|
|
|
changeMomentLanguage(language);
|
|
|
|
i18next.changeLanguage(language);
|
2021-02-19 23:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function changeLanguage(language) {
|
2021-09-14 01:22:13 +08:00
|
|
|
localStorage.setItem("language", language);
|
|
|
|
changeMomentLanguage(language);
|
|
|
|
i18next.changeLanguage(language);
|
2021-02-19 23:23:59 +08:00
|
|
|
window.location.reload(true);
|
|
|
|
}
|
2021-03-14 23:08:08 +08:00
|
|
|
|
2021-09-14 01:22:13 +08:00
|
|
|
export function changeMomentLanguage(language) {
|
|
|
|
return;
|
|
|
|
if (language === "zh") {
|
|
|
|
moment.locale("zh", {
|
|
|
|
relativeTime: {
|
|
|
|
future: "%s内",
|
|
|
|
past: "%s前",
|
|
|
|
s: "几秒",
|
|
|
|
ss: "%d秒",
|
|
|
|
m: "1分钟",
|
|
|
|
mm: "%d分钟",
|
|
|
|
h: "1小时",
|
|
|
|
hh: "%d小时",
|
|
|
|
d: "1天",
|
|
|
|
dd: "%d天",
|
|
|
|
M: "1个月",
|
|
|
|
MM: "%d个月",
|
|
|
|
y: "1年",
|
|
|
|
yy: "%d年",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-14 23:08:08 +08:00
|
|
|
export function getClickable(text) {
|
|
|
|
return (
|
2021-03-27 11:38:15 +08:00
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-is-valid
|
2021-03-14 23:08:08 +08:00
|
|
|
<a onClick={() => {
|
|
|
|
copy(text);
|
|
|
|
showMessage("success", `Copied to clipboard`);
|
|
|
|
}}>
|
|
|
|
{text}
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
2021-04-18 23:14:46 +08:00
|
|
|
|
2022-04-21 21:52:34 +08:00
|
|
|
export function getProviderLogoURL(provider) {
|
|
|
|
if (provider.category === "OAuth") {
|
|
|
|
if (provider.type === "Custom") {
|
|
|
|
return provider.customLogo;
|
|
|
|
}
|
|
|
|
return `${StaticBaseUrl}/img/social_${provider.type.toLowerCase()}.png`;
|
|
|
|
} else {
|
|
|
|
return OtherProviderInfo[provider.category][provider.type].logo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 01:14:41 +08:00
|
|
|
export function getProviderLogo(provider) {
|
2021-12-13 19:49:30 +08:00
|
|
|
const idp = provider.type.toLowerCase().trim().split(' ')[0];
|
2022-04-21 21:52:34 +08:00
|
|
|
const url = getProviderLogoURL(provider);
|
2021-04-18 23:14:46 +08:00
|
|
|
return (
|
|
|
|
<img width={30} height={30} src={url} alt={idp} />
|
|
|
|
)
|
|
|
|
}
|
2021-04-28 15:54:50 +08:00
|
|
|
|
2021-12-25 10:55:10 +08:00
|
|
|
export function getProviderTypeOptions(category) {
|
|
|
|
if (category === "OAuth") {
|
|
|
|
return (
|
|
|
|
[
|
|
|
|
{id: 'Google', name: 'Google'},
|
|
|
|
{id: 'GitHub', name: 'GitHub'},
|
|
|
|
{id: 'QQ', name: 'QQ'},
|
|
|
|
{id: 'WeChat', name: 'WeChat'},
|
2022-04-15 11:49:56 +08:00
|
|
|
{id: 'WeChatMiniProgram', name: 'WeChat Mini Program'},
|
2021-12-25 10:55:10 +08:00
|
|
|
{id: 'Facebook', name: 'Facebook'},
|
|
|
|
{id: 'DingTalk', name: 'DingTalk'},
|
|
|
|
{id: 'Weibo', name: 'Weibo'},
|
|
|
|
{id: 'Gitee', name: 'Gitee'},
|
|
|
|
{id: 'LinkedIn', name: 'LinkedIn'},
|
|
|
|
{id: 'WeCom', name: 'WeCom'},
|
|
|
|
{id: 'Lark', name: 'Lark'},
|
|
|
|
{id: 'GitLab', name: 'GitLab'},
|
2022-02-20 15:01:48 +08:00
|
|
|
{id: 'Adfs', name: 'Adfs'},
|
2022-01-22 19:36:44 +08:00
|
|
|
{id: 'Baidu', name: 'Baidu'},
|
2022-04-02 22:37:13 +08:00
|
|
|
{id: 'Alipay', name: 'Alipay'},
|
2022-03-18 18:28:46 +08:00
|
|
|
{id: 'Casdoor', name: 'Casdoor'},
|
2022-02-05 21:54:38 +08:00
|
|
|
{id: 'Infoflow', name: 'Infoflow'},
|
2021-12-25 10:55:10 +08:00
|
|
|
{id: 'Apple', name: 'Apple'},
|
|
|
|
{id: 'AzureAD', name: 'AzureAD'},
|
|
|
|
{id: 'Slack', name: 'Slack'},
|
2022-02-16 19:57:46 +08:00
|
|
|
{id: 'Steam', name: 'Steam'},
|
2022-04-16 17:17:45 +08:00
|
|
|
{id: 'Custom', name: 'Custom'},
|
2021-12-25 10:55:10 +08:00
|
|
|
]
|
|
|
|
);
|
|
|
|
} else if (category === "Email") {
|
|
|
|
return (
|
|
|
|
[
|
|
|
|
{id: 'Default', name: 'Default'},
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} else if (category === "SMS") {
|
|
|
|
return (
|
|
|
|
[
|
|
|
|
{id: 'Aliyun SMS', name: 'Aliyun SMS'},
|
|
|
|
{id: 'Tencent Cloud SMS', name: 'Tencent Cloud SMS'},
|
|
|
|
{id: 'Volc Engine SMS', name: 'Volc Engine SMS'},
|
2022-03-14 20:49:03 +08:00
|
|
|
{id: 'Huawei Cloud SMS', name: 'Huawei Cloud SMS'},
|
2021-12-25 10:55:10 +08:00
|
|
|
]
|
|
|
|
);
|
|
|
|
} else if (category === "Storage") {
|
|
|
|
return (
|
|
|
|
[
|
|
|
|
{id: 'Local File System', name: 'Local File System'},
|
|
|
|
{id: 'AWS S3', name: 'AWS S3'},
|
|
|
|
{id: 'Aliyun OSS', name: 'Aliyun OSS'},
|
|
|
|
{id: 'Tencent Cloud COS', name: 'Tencent Cloud COS'},
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} else if (category === "SAML") {
|
|
|
|
return ([
|
|
|
|
{id: 'Aliyun IDaaS', name: 'Aliyun IDaaS'},
|
|
|
|
{id: 'Keycloak', name: 'Keycloak'},
|
|
|
|
]);
|
2022-02-05 01:18:13 +08:00
|
|
|
} else if (category === "Payment") {
|
|
|
|
return ([
|
|
|
|
{id: 'Alipay', name: 'Alipay'},
|
|
|
|
{id: 'WeChat Pay', name: 'WeChat Pay'},
|
|
|
|
{id: 'PayPal', name: 'PayPal'},
|
2022-03-14 00:12:02 +08:00
|
|
|
{id: 'GC', name: 'GC'},
|
2022-02-05 01:18:13 +08:00
|
|
|
]);
|
2021-12-25 10:55:10 +08:00
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 23:57:54 +08:00
|
|
|
export function getProviderSubTypeOptions(type) {
|
2022-02-05 21:54:38 +08:00
|
|
|
if (type === "WeCom" || type === "Infoflow") {
|
2022-01-28 23:57:54 +08:00
|
|
|
return (
|
|
|
|
[
|
|
|
|
{id: 'Internal', name: 'Internal'},
|
|
|
|
{id: 'Third-party', name: 'Third-party'},
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 15:54:50 +08:00
|
|
|
export function renderLogo(application) {
|
|
|
|
if (application === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (application.homepageUrl !== "") {
|
|
|
|
return (
|
|
|
|
<a target="_blank" rel="noreferrer" href={application.homepageUrl}>
|
|
|
|
<img width={250} src={application.logo} alt={application.displayName} style={{marginBottom: '30px'}}/>
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<img width={250} src={application.logo} alt={application.displayName} style={{marginBottom: '30px'}}/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-04-28 22:40:21 +08:00
|
|
|
|
|
|
|
export function goToLogin(ths, application) {
|
|
|
|
if (application === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-14 23:23:59 +08:00
|
|
|
if (!application.enablePassword && window.location.pathname.includes("/signup/oauth/authorize")) {
|
|
|
|
const link = window.location.href.replace("/signup/oauth/authorize", "/login/oauth/authorize");
|
|
|
|
goToLink(link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:40:21 +08:00
|
|
|
if (authConfig.appName === application.name) {
|
|
|
|
goToLinkSoft(ths, "/login");
|
|
|
|
} else {
|
2021-06-14 22:55:08 +08:00
|
|
|
if (application.signinUrl === "") {
|
|
|
|
goToLink(`${application.homepageUrl}/login`);
|
|
|
|
} else {
|
|
|
|
goToLink(application.signinUrl);
|
|
|
|
}
|
2021-04-28 22:40:21 +08:00
|
|
|
}
|
|
|
|
}
|
2021-04-29 21:28:24 +08:00
|
|
|
|
2021-05-03 00:48:02 +08:00
|
|
|
export function goToSignup(ths, application) {
|
|
|
|
if (application === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-14 23:23:59 +08:00
|
|
|
if (!application.enablePassword && window.location.pathname.includes("/login/oauth/authorize")) {
|
|
|
|
const link = window.location.href.replace("/login/oauth/authorize", "/signup/oauth/authorize");
|
|
|
|
goToLink(link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-03 00:48:02 +08:00
|
|
|
if (authConfig.appName === application.name) {
|
|
|
|
goToLinkSoft(ths, "/signup");
|
|
|
|
} else {
|
|
|
|
if (application.signupUrl === "") {
|
|
|
|
goToLinkSoft(ths, `/signup/${application.name}`);
|
|
|
|
} else {
|
|
|
|
goToLink(application.signupUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function goToForget(ths, application) {
|
|
|
|
if (application === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (authConfig.appName === application.name) {
|
|
|
|
goToLinkSoft(ths, "/forget");
|
|
|
|
} else {
|
2021-06-04 01:21:53 +08:00
|
|
|
if (application.forgetUrl === "") {
|
2021-05-03 00:48:02 +08:00
|
|
|
goToLinkSoft(ths, `/forget/${application.name}`);
|
|
|
|
} else {
|
|
|
|
goToLink(application.forgetUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 21:28:24 +08:00
|
|
|
export function renderHelmet(application) {
|
|
|
|
if (application === undefined || application === null || application.organizationObj === undefined || application.organizationObj === null ||application.organizationObj === "") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Helmet>
|
|
|
|
<title>{application.organizationObj.displayName}</title>
|
|
|
|
<link rel="icon" href={application.organizationObj.favicon} />
|
|
|
|
</Helmet>
|
|
|
|
)
|
|
|
|
}
|
2021-06-25 00:13:43 +08:00
|
|
|
|
|
|
|
export function getLabel(text, tooltip) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<span style={{ marginRight: 4 }}>{text}</span>
|
|
|
|
<Tooltip placement="top" title={tooltip}>
|
|
|
|
<QuestionCircleTwoTone twoToneColor="rgb(45,120,213)" />
|
|
|
|
</Tooltip>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
2021-06-25 21:35:20 +08:00
|
|
|
|
|
|
|
function repeat(str, len) {
|
|
|
|
while (str.length < len) {
|
|
|
|
str += str.substr(0, len - str.length);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function maskString(s) {
|
|
|
|
if (s.length <= 2) {
|
|
|
|
return s;
|
|
|
|
} else {
|
|
|
|
return `${s[0]}${repeat("*", s.length - 2)}${s[s.length - 1]}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-28 11:09:37 +08:00
|
|
|
export function getMaskedPhone(s) {
|
|
|
|
return s.replace(/(\d{3})\d*(\d{4})/,'$1****$2');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getMaskedEmail(email) {
|
2021-07-01 19:22:28 +08:00
|
|
|
if (email === "") return;
|
2021-06-25 21:35:20 +08:00
|
|
|
const tokens = email.split("@");
|
|
|
|
let username = tokens[0];
|
|
|
|
username = maskString(username);
|
|
|
|
|
|
|
|
const domain = tokens[1];
|
|
|
|
let domainTokens = domain.split(".");
|
|
|
|
domainTokens[domainTokens.length - 2] = maskString(domainTokens[domainTokens.length - 2]);
|
|
|
|
|
|
|
|
return `${username}@${domainTokens.join(".")}`;
|
|
|
|
}
|
2021-07-09 23:05:50 +08:00
|
|
|
|
|
|
|
export function getArrayItem(array, key, value) {
|
|
|
|
const res = array.filter(item => item[key] === value)[0];
|
|
|
|
return res;
|
|
|
|
}
|
2021-07-09 23:12:13 +08:00
|
|
|
|
|
|
|
export function getDeduplicatedArray(array, filterArray, key) {
|
|
|
|
const res = array.filter(item => filterArray.filter(filterItem => filterItem[key] === item[key]).length === 0);
|
|
|
|
return res;
|
|
|
|
}
|
2021-11-07 15:41:24 +08:00
|
|
|
|
2021-11-28 18:21:34 +08:00
|
|
|
export function getNewRowNameForTable(table, rowName) {
|
|
|
|
const emptyCount = table.filter(row => row.name.includes(rowName)).length;
|
|
|
|
let res = rowName;
|
|
|
|
for (let i = 0; i < emptyCount; i ++) {
|
|
|
|
res = res + " ";
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-11-07 15:41:24 +08:00
|
|
|
export function getTagColor(s) {
|
2022-01-01 15:11:16 +08:00
|
|
|
return "processing";
|
2021-11-07 15:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getTags(tags) {
|
|
|
|
let res = [];
|
2022-01-25 19:39:04 +08:00
|
|
|
if (!tags) return res;
|
2021-11-07 15:41:24 +08:00
|
|
|
tags.forEach((tag, i) => {
|
|
|
|
res.push(
|
|
|
|
<Tag color={getTagColor(tag)}>
|
|
|
|
{tag}
|
|
|
|
</Tag>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return res;
|
|
|
|
}
|
2021-11-28 20:57:14 +08:00
|
|
|
|
|
|
|
export function getApplicationOrgName(application) {
|
|
|
|
return `${application?.organizationObj.owner}/${application?.organizationObj.name}`;
|
|
|
|
}
|
2021-12-12 18:51:12 +08:00
|
|
|
|
|
|
|
export function getRandomName() {
|
|
|
|
return Math.random().toString(36).slice(-6);
|
|
|
|
}
|
2021-12-23 21:28:40 +08:00
|
|
|
|
|
|
|
export function getRandomNumber() {
|
|
|
|
return Math.random().toString(10).slice(-11);
|
|
|
|
}
|
2022-02-12 09:55:06 +08:00
|
|
|
|
|
|
|
export function getFromLink() {
|
|
|
|
const from = sessionStorage.getItem("from");
|
|
|
|
if (from === null) {
|
|
|
|
return "/";
|
|
|
|
}
|
|
|
|
return from;
|
|
|
|
}
|
2022-04-06 20:38:14 +08:00
|
|
|
|
|
|
|
export function getSyncerTableColumns(syncer) {
|
|
|
|
switch (syncer.type) {
|
|
|
|
case "Keycloak":
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
"name":"ID",
|
|
|
|
"type":"string",
|
|
|
|
"casdoorName":"Id",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"USERNAME",
|
|
|
|
"type":"string",
|
|
|
|
"casdoorName":"Name",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"USERNAME",
|
|
|
|
"type":"string",
|
|
|
|
"casdoorName":"DisplayName",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"EMAIL",
|
|
|
|
"type":"string",
|
|
|
|
"casdoorName":"Email",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"EMAIL_VERIFIED",
|
|
|
|
"type":"boolean",
|
|
|
|
"casdoorName":"EmailVerified",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"FIRST_NAME",
|
|
|
|
"type":"string",
|
|
|
|
"casdoorName":"FirstName",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"LAST_NAME",
|
|
|
|
"type":"string",
|
|
|
|
"casdoorName":"LastName",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"CREATED_TIMESTAMP",
|
|
|
|
"type":"string",
|
|
|
|
"casdoorName":"CreatedTime",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name":"ENABLED",
|
|
|
|
"type":"boolean",
|
|
|
|
"casdoorName":"IsForbidden",
|
|
|
|
"isHashed":true,
|
|
|
|
"values":[
|
|
|
|
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
default:
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|