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

[PLA-1781] update password query #115

Merged
merged 3 commits into from
May 28, 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
76 changes: 8 additions & 68 deletions resources/js/components/pages/VerifyPasswordModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@
name="password"
type="password"
/>
<vue-recaptcha
v-if="hasCaptcha"
ref="captchaRef"
:style="{ visibility: isCaptchaBadgeVisible ? 'visible' : 'hidden' }"
size="invisible"
:load-recaptcha-script="false"
:sitekey="reCaptchaSiteKey"
@verify="confirm"
@expired="onCaptchaExpired"
/>
</div>

<div class="flex justify-end space-x-4 mt-6">
<Btn @click="closeModal">Cancel</Btn>
<Btn primary @click="verifyCaptcha">Confirm</Btn>
<Btn primary @click="confirm">Confirm</Btn>
</div>
</Modal>
</template>
Expand All @@ -42,74 +32,24 @@ import { DialogTitle } from '@headlessui/vue';
import Btn from '~/components/Btn.vue';
import Modal from '~/components/Modal.vue';
import FormInput from '../FormInput.vue';
import { ref } from 'vue';
import { useAppStore } from '~/store';
import { AuthApi } from '~/api/auth';
import { VueRecaptcha } from 'vue-recaptcha';
import snackbar from '~/util/snackbar';
import { onUnmounted, ref } from 'vue';

const props = defineProps<{ isOpen: boolean }>();

const emit = defineEmits(['closed', 'confirm']);

const appStore = useAppStore();

const password = ref();
const isCaptchaBadgeVisible = ref(false);
const captchaRef = ref();
const hasCaptcha = window.bootstrap?.captcha_key?.length > 0;
const reCaptchaSiteKey = window.bootstrap?.captcha_key || 'null';

const confirm = async (recaptcha?: string) => {
const email = appStore.user?.email;
const res = await AuthApi.login(email, password.value, recaptcha);
if (res.data.Login) {
emit('confirm', password.value);
closeModal();
} else {
snackbar.error({
title: 'Error',
text: 'Invalid password',
});
}
};

const loadCaptchaScript = async () => {
if (!hasCaptcha) {
isCaptchaBadgeVisible.value = true;

return;
}
if (!document.getElementById('recaptcha-script')) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'recaptcha-script';
script.async = true;
script.defer = true;
script.src = 'https://www.google.com/recaptcha/api.js?onload=vueRecaptchaApiLoaded&render=explicit&hl=:1';
document.getElementsByTagName('head')[0].appendChild(script);
}

isCaptchaBadgeVisible.value = true;
};

const onCaptchaExpired = () => {
captchaRef.value.reset();
};

const verifyCaptcha = () => {
if (!hasCaptcha) {
return confirm();
}

captchaRef.value.execute();
const confirm = async () => {
emit('confirm', password.value);
closeModal();
};

const closeModal = () => {
emit('closed');
};

(() => {
loadCaptchaScript();
})();
onUnmounted(() => {
password.value = '';
});
</script>
2 changes: 1 addition & 1 deletion resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const useAppStore = defineStore('app', {
const res = await CollectionApi.getCollectionsIds(totalCount);
const collectionsData = res.data.GetCollections;
if (collectionsData.pageInfo.hasNextPage) {
await this.fetchCollectionIds(collectionsData.totalCount);
await this.fetchCollectionIds(collectionsData.totalCount > 500 ? 500 : collectionsData.totalCount);
} else {
this.collections = collectionsData.edges.map((collection: any) => collection.node.collectionId);
}
Expand Down
Loading