Skip to content

Commit

Permalink
perf: sms env
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou committed Feb 21, 2025
1 parent 6f3cb20 commit fcf2de2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export default function Index(props: Omit<IconButtonProps, 'aria-label'>) {
}
/>
)}
{conf.authConfig?.idp.sms.enabled && conf.authConfig.idp.sms.email.enabled && (
{conf.authConfig?.idp.email.enabled && (
<ConfigItem
LeftElement={<Text>{t('common:email')}</Text>}
RightElement={
Expand Down
6 changes: 3 additions & 3 deletions frontend/desktop/src/pages/api/platform/getAuthConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function genResAuthClientConfig(conf: AuthConfigType) {
enabled: !!conf.idp.sms?.enabled,
ali: {
enabled: !!conf.idp.sms?.ali?.enabled
},
email: {
enabled: !!conf.idp.sms?.email?.enabled
}
},
email: {
enabled: !!conf.idp.email?.enabled
},
github: {
enabled: !!conf.idp.github?.enabled,
proxyAddress: conf.idp.github?.proxyAddress || '',
Expand Down
18 changes: 9 additions & 9 deletions frontend/desktop/src/services/backend/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as Util from '@alicloud/tea-util';
import nodemailer from 'nodemailer';
const getTransporter = () => {
if (!global.nodemailer) {
const emailConfig = global.AppConfig.desktop.auth.idp.sms?.email;
const emailConfig = global.AppConfig.desktop.auth.idp.email;
if (!emailConfig) throw Error('email transporter config error');
const transporter = nodemailer.createTransport({
pool: true,
Expand Down Expand Up @@ -65,8 +65,8 @@ export const smsReq = async (phoneNumbers: string) => {
}
if (_result.body.code !== 'OK') {
throw new Error(`
${_result.body.message}
${phoneNumbers},
${_result.body.message}
${phoneNumbers},
${new Date()}`);
}
return _result;
Expand All @@ -77,7 +77,7 @@ export const smsReq = async (phoneNumbers: string) => {
return code;
};
export const emailSmsReq = async (email: string) => {
const emailConfig = global.AppConfig.desktop.auth.idp.sms?.email;
const emailConfig = global.AppConfig.desktop.auth.idp.email;
if (!emailConfig) throw Error('config error');

const code = Math.floor(Math.random() * 900000 + 100000).toString();
Expand All @@ -101,7 +101,7 @@ export const emailSmsReq = async (email: string) => {
background-color: #f0f0f0;
text-align: center;
}
.container {
max-width: 400px;
margin: 50px auto;
Expand All @@ -110,17 +110,17 @@ export const emailSmsReq = async (email: string) => {
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #3498db;
}
.verification-code {
font-size: 24px;
color: #333;
margin-bottom: 20px;
}
.button {
padding: 10px 20px;
background-color: #3498db;
Expand All @@ -129,7 +129,7 @@ export const emailSmsReq = async (email: string) => {
border-radius: 5px;
cursor: pointer;
}
.button:hover {
background-color: #2980b9;
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/desktop/src/services/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export const enableGithub = () => global.AppConfig.desktop.auth.idp.github?.enab
export const enableSms = () => global.AppConfig.desktop.auth.idp.sms?.enabled || false;
export const enablePhoneSms = () =>
enableSms() && !!global.AppConfig.desktop.auth.idp.sms?.ali?.enabled;
export const enableEmailSms = () =>
enableSms() && !!global.AppConfig.desktop.auth.idp.sms?.email?.enabled;
export const enableEmailSms = () => !!global.AppConfig.desktop.auth.idp.email?.enabled;
export const enableWechat = () => global.AppConfig.desktop.auth.idp.wechat?.enabled || false;
export const enableGoogle = () => global.AppConfig.desktop.auth.idp.google?.enabled || false;
export const enableSignUp = () => global.AppConfig.desktop.auth.signUpEnabled || false;
Expand Down
52 changes: 26 additions & 26 deletions frontend/desktop/src/types/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,30 @@ export type AuthConfigType = {
accessKeyID: string;
accessKeySecret?: string;
};
email?: {
enabled: boolean;
host: string;
port: number;
user: string;
password: string;
};
};
email?: {
enabled: boolean;
host: string;
port: number;
user: string;
password: string;
};
};
};

export type AuthClientConfigType = DeepRequired<
export type AuthClientConfigType = {
idp: {
sms: {
enabled: boolean;
ali: {
enabled: boolean;
};
};
email: {
enabled: boolean;
};
};
} & DeepRequired<
OmitPathArr<
AuthConfigType,
[
Expand All @@ -155,28 +167,16 @@ export type AuthClientConfigType = DeepRequired<
'idp.github.clientSecret',
'idp.wechat.clientSecret',
'idp.google.clientSecret',
'idp.sms.ali',
'idp.sms.email',
'idp.sms',
'idp.email',
'idp.oauth2.clientSecret',
'jwt',
'billingUrl',
'workorderUrl',
'cloudVitrualMachineUrl'
]
>
> & {
idp: {
sms: {
enabled: boolean;
ali: {
enabled: boolean;
};
email: {
enabled: boolean;
};
};
};
};
>;

export type JwtConfigType = {
internal?: string;
Expand Down Expand Up @@ -298,11 +298,11 @@ export const DefaultAuthClientConfig: AuthClientConfigType = {
enabled: false,
ali: {
enabled: false
},
email: {
enabled: false
}
},
email: {
enabled: false
},
oauth2: {
enabled: false,
callbackURL: '',
Expand Down

0 comments on commit fcf2de2

Please sign in to comment.