Skip to content

Commit

Permalink
feat(Register): implement email verification on register
Browse files Browse the repository at this point in the history
  • Loading branch information
jkklapp committed Jun 7, 2022
1 parent 6dd73e4 commit 1c7e8f8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
5 changes: 5 additions & 0 deletions frontend/src/components/Dashboard/Input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const mountComponent = (isPosting = false, showWarning = false) => {
return isPosting;
},
},
user: {
get() {
return { verified: true };
},
},
},
});
};
Expand Down
24 changes: 17 additions & 7 deletions frontend/src/components/Dashboard/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
class="relative bg-white border-gray-200 dark:bg-gray-600 text-gray-800 dark:text-gray-100 px-6 pt-10 pb-8 mb-2 ring-1 ring-gray-900/5 sm:mx-auto sm:max-w-lg sm:rounded-lg sm:px-10"
>
<form>
<label
for="default-search"
class="shadow-xl mb-2 text-sm font-medium text-gray-900 sr-only dark:text-gray-300"
>{{ inputLabel }}</label
>
<p>
<span
v-if="!user.verified"
class="text-red-700 dark:text-red-300 text-xs"
>
You need to verify your email address to access the fully-featured
Fluunker.
</span>
</p>
<div class="relative">
<div
class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"
Expand Down Expand Up @@ -63,20 +67,26 @@ export default {
inputLabel: () => process.env.VUE_APP_INPUT_LABEL,
inputCtaLabel: () => process.env.VUE_APP_INPUT_CTA_LABEL,
placeholder() {
return `You have ${this.remainingMessages} ${process.env.VUE_APP_MESSAGE_NAME}s left today`;
return `You have ${this.remainingMessagesForUser} ${process.env.VUE_APP_MESSAGE_NAME}s left today`;
},
isInputDisabled() {
return (
this.isPosting ||
this.remainingMessages === 0 ||
this.remainingMessagesForUser === 0 ||
this.message.length === 0 ||
this.message.length > 120
);
},
showWarning() {
return this.message.length > 100;
},
remainingMessagesForUser() {
return this.user.verified
? this.remainingMessages
: parseInt(this.remainingMessages / 10, 10);
},
...mapGetters({
user: 'user',
posts: 'getPosts',
isPosting: 'isCreatingPost',
remainingMessages: 'getRemainingMessages',
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Register.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ describe('Register', () => {
appName: () => 'Fluu',
userEmailExists: {
get() {
return true;
return false;
},
},
userNameExists: {
get() {
return true;
return false;
},
},
},
Expand All @@ -65,7 +65,7 @@ describe('Register', () => {
await confirm.setValue('password');
await acceptTerms.setChecked(true);

const button = wrapper.find('button');
const button = wrapper.find('button[type="submit"]');
expect(button.element.disabled).toEqual(false);
});
});
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@

<script>
import { getAuth } from '../auth';
import { createUserWithEmailAndPassword, updateProfile } from 'firebase/auth';
import {
createUserWithEmailAndPassword,
updateProfile,
sendEmailVerification,
} from 'firebase/auth';
import Email from './misc/icons/Email.vue';
import Password from './misc/icons/Password.vue';
import { mapGetters } from 'vuex';
Expand Down Expand Up @@ -214,6 +218,7 @@ export default {
displayName: this.form.name,
});
this.$router.replace({ name: 'Dashboard' });
await sendEmailVerification(user);
},
async validate(field) {
if (this.form[field]) {
Expand Down

0 comments on commit 1c7e8f8

Please sign in to comment.