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

feat: 🎊 Any length of invitation code #469

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def validate_code(self, _, value: str):
if value is None:
return

# Check that the code is a 6 character string of only letters and numbers
if not isinstance(value, str) or len(value) != 6 or not value.isalnum():
# Check that the code only contains letters and numbers
if not isinstance(value, str) or not value.isalnum():
raise ValidationError("Invalid code")

# Check that the code has not been used
Expand Down Expand Up @@ -104,7 +104,7 @@ def create_code():
raise ValidationError("Unable to generate a unique code")

# If code is None, generate a new code
if not invitation["code"] or len(invitation["code"]) != 6 or not str(invitation["code"]).isalnum():
if not invitation["code"] or not str(invitation["code"]).isalnum():
invitation["code"] = create_code()

# Upper case the code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<FormKit type="form" name="inviteForm" id="inviteForm" @submit="createInvite" :actions="!eventBus" v-model="invitationData" :disabled="disabled" :submit-label="__('Create Invitation')" :submit-attrs="{ inputClass: 'w-full justify-center mt-2' }">
<div class="space-y-4">
<!-- Invite Code -->
<FormKit type="text" placeholder="XMFGEJI" label="Invitation Code" name="inviteCode" validation="length:6,6|uppercase" />
<FormKit type="text" placeholder="XMFGEJI" label="Invitation Code" name="inviteCode" validation="uppercase" />

<!-- Select Expiration -->
<FormKit type="select" label="Invitation Expiration" name="expiration" :options="expirationOptions" />
Expand Down Expand Up @@ -399,8 +399,7 @@ export default defineComponent({
watch: {
"invitationData.inviteCode": {
immediate: true,
handler(inviteCode) {
if (inviteCode.length >= 7) this.invitationData.inviteCode = inviteCode.slice(0, 6);
handler() {
this.invitationData.inviteCode = this.invitationData.inviteCode.replace(/[^a-zA-Z0-9]/g, "");
this.invitationData.inviteCode = this.invitationData.inviteCode.toUpperCase();
},
Expand Down
4 changes: 2 additions & 2 deletions apps/wizarr-frontend/src/modules/home/pages/JoinForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export default defineComponent({
methods: {
async join() {
// Check if the code is inputted
if (!this.code || this.code.length !== 6) {
this.$toast.info(this.__('Please enter an invite code'));
if (!this.code) {
this.$toast.info(this.__("Please enter an invite code"));
return;
}

Expand Down