mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 21:30:24 +08:00
feat: support multiple country codes for sending SMS (#1557)
* feat: support multiple country code * feat: improve UI * feat: migrate accountItem * fix: Aliyun compatible * fix: phone validate * fix: typo
This commit is contained in:
@ -23,6 +23,7 @@ import copy from "copy-to-clipboard";
|
||||
import {authConfig} from "./auth/Auth";
|
||||
import {Helmet} from "react-helmet";
|
||||
import * as Conf from "./Conf";
|
||||
import * as phoneNumber from "libphonenumber-js";
|
||||
import * as path from "path-browserify";
|
||||
|
||||
export const ServerUrl = "";
|
||||
@ -30,6 +31,16 @@ export const ServerUrl = "";
|
||||
// export const StaticBaseUrl = "https://cdn.jsdelivr.net/gh/casbin/static";
|
||||
export const StaticBaseUrl = "https://cdn.casbin.org";
|
||||
|
||||
export const Countries = [{label: "English", key: "en", country: "US", alt: "English"},
|
||||
{label: "简体中文", key: "zh", country: "CN", alt: "简体中文"},
|
||||
{label: "Español", key: "es", country: "ES", alt: "Español"},
|
||||
{label: "Français", key: "fr", country: "FR", alt: "Français"},
|
||||
{label: "Deutsch", key: "de", country: "DE", alt: "Deutsch"},
|
||||
{label: "日本語", key: "ja", country: "JP", alt: "日本語"},
|
||||
{label: "한국어", key: "ko", country: "KR", alt: "한국어"},
|
||||
{label: "Русский", key: "ru", country: "RU", alt: "Русский"},
|
||||
];
|
||||
|
||||
export function getThemeData(organization, application) {
|
||||
if (application?.themeData?.isEnabled) {
|
||||
return application.themeData;
|
||||
@ -188,20 +199,33 @@ export const OtherProviderInfo = {
|
||||
},
|
||||
};
|
||||
|
||||
export function getCountriesData() {
|
||||
export function initCountries() {
|
||||
const countries = require("i18n-iso-countries");
|
||||
countries.registerLocale(require("i18n-iso-countries/langs/" + getLanguage() + ".json"));
|
||||
return countries;
|
||||
}
|
||||
|
||||
export function getCountryNames() {
|
||||
const data = getCountriesData().getNames(getLanguage(), {select: "official"});
|
||||
|
||||
return Object.entries(data).map(items => {
|
||||
return {code: items[0], name: items[1]};
|
||||
export function getCountriesData(countryCodes = phoneNumber.getCountries()) {
|
||||
return countryCodes?.map((countryCode) => {
|
||||
if (phoneNumber.isSupportedCountry(countryCode)) {
|
||||
const name = initCountries().getName(countryCode, getLanguage());
|
||||
return {
|
||||
code: countryCode,
|
||||
name: name || "",
|
||||
phone: phoneNumber.getCountryCallingCode(countryCode),
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function countryFlag(country) {
|
||||
return <img src={`${StaticBaseUrl}/flag-icons/${country.code}.svg`} alt={country.name} height={20} style={{marginRight: 10}} />;
|
||||
}
|
||||
|
||||
export function getPhoneCodeFromCountryCode(countryCode) {
|
||||
return phoneNumber.isSupportedCountry(countryCode) ? phoneNumber.getCountryCallingCode(countryCode) : "";
|
||||
}
|
||||
|
||||
export function initServerUrl() {
|
||||
// const hostname = window.location.hostname;
|
||||
// if (hostname === "localhost") {
|
||||
@ -299,16 +323,14 @@ export function isValidEmail(email) {
|
||||
return emailRegex.test(email);
|
||||
}
|
||||
|
||||
export function isValidPhone(phone) {
|
||||
return phone !== "";
|
||||
export function isValidPhone(phone, countryCode = "") {
|
||||
if (countryCode !== "") {
|
||||
return phoneNumber.isValidPhoneNumber(phone, countryCode);
|
||||
}
|
||||
|
||||
// if (phone === "") {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // 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);
|
||||
const phoneRegex = /[0-9]{4,15}$/;
|
||||
return phoneRegex.test(phone);
|
||||
}
|
||||
|
||||
export function isValidInvoiceTitle(invoiceTitle) {
|
||||
|
Reference in New Issue
Block a user