Skip to content

Commit

Permalink
[PLA-1781] update password query (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine authored May 28, 2024
1 parent fce2180 commit d791876
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 69 deletions.
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

0 comments on commit d791876

Please sign in to comment.