Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using username and email in SMTP configuration #3398

Merged
merged 18 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions packages/playground/src/components/smtp_server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
<input-validator
:value="$props.modelValue.username"
:rules="[
validators.required('Email is required.'),
validators.isEmail('Please provide a valid email address.'),
v => {
return isDiscourse ? undefined : validators.isEmail('Please provide a valid email address.')(v);
},
validators.required('Email or Username is required.'),
(v: string) => {
return validators.validateSmtp(v);
}
]"
#="{ props }"
>
<input-tooltip :tooltip="isDiscourse ? 'SMTP admin email, Username or API key.' : 'SMTP admin email'">
<input-tooltip tooltip="SMTP admin email, Username or API key.">
<v-text-field
label="Admin Email"
label="Admin Email or Username"
placeholder="email@example.com"
v-model="$props.modelValue.username"
v-bind="props"
Expand All @@ -46,7 +45,7 @@
:rules="[
validators.required('Password is required.'),
validators.minLength('Password must be at least 6 characters.', 6),
validators.maxLength('Password cannot exceed 50 characters.', 50),
validators.maxLength('Password cannot exceed 69 characters.', 69),
samaradel marked this conversation as resolved.
Show resolved Hide resolved
validators.pattern('Password should not contain whitespaces.', {
pattern: /^[^\s]+$/,
}),
Expand Down Expand Up @@ -139,7 +138,6 @@ defineProps<{
tls?: boolean;
email?: boolean;
persistent?: boolean;
isDiscourse?: boolean;
}>();
</script>

Expand Down
8 changes: 8 additions & 0 deletions packages/playground/src/utils/validators.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,11 @@
return { message: "Name is already taken." };
}
}

export function validateSmtp(v: string) {
samaradel marked this conversation as resolved.
Show resolved Hide resolved
const emailValidation = isEmail("Please provide a valid email address.")(v);
const username = /[!@#$%^&*()_+-={}:<>?,./]/.test(v);
Fixed Show fixed Hide fixed
if (username && emailValidation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this condition, does that mean if it's email and a username (doesn't have special characters) then it's true?

shouldn't it be like that

const isValidEmail = isEmail("Please provide a valid email address.")(input);
const hasSpecialCharacters = /[!@#$%^&*()\s_+\-={}:<>?,./]/.test(input);

if (hasSpecialCharacters && isValidEmail) {
      return { message: "Please provide a valid username or email" };
}

Which I still don't understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant here it could accept both and validate if it's not a valid email or username with a special character.

return { message: "Please provide a valid input" };
samaradel marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion packages/playground/src/weblets/tf_discourse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</template>

<template #mail>
<SmtpServer v-model="smtp" :persistent="true" :tls="true" :is-discourse="true">
<SmtpServer v-model="smtp" persistent tls>
Discourse needs SMTP service so please configure these settings properly.
</SmtpServer>
</template>
Expand Down
Loading