Skip to content

Commit

Permalink
feat: 🎊 Any length of invitation code (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
albinmedoc authored Aug 1, 2024
1 parent c405bea commit c850c8e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
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

0 comments on commit c850c8e

Please sign in to comment.