mirror of
https://github.com/ArthurDanjou/website-old.git
synced 2026-01-14 12:14:42 +01:00
Working
This commit is contained in:
@@ -16,15 +16,18 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex space-x-4">
|
<div class="flex space-x-4">
|
||||||
<nuxt-link class="link font-semibold" to="env">
|
<nuxt-link class="link font-semibold" to="/env">
|
||||||
<span>{{ $t('header.env') }}</span>,
|
<span>{{ $t('header.env') }}</span>,
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
<nuxt-link class="link font-semibold" to="guestbook">
|
<nuxt-link class="link font-semibold" to="/guestbook">
|
||||||
<span>{{ $t('header.guestbook') }}</span>,
|
<span>{{ $t('header.guestbook') }}</span>,
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
<nuxt-link class="link font-semibold" to="contact">
|
<nuxt-link class="link font-semibold" to="/contact">
|
||||||
<span>{{ $t('header.contact') }}</span>
|
<span>{{ $t('header.contact') }}</span>
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
|
<nuxt-link class="link font-semibold" to="/newsletter">
|
||||||
|
<span>{{ $t('header.newsletter') }}</span>
|
||||||
|
</nuxt-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center my-4">
|
<div class="text-center my-4">
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
<h1 class="text-black font-bold dark:text-white text-2xl">{{ $t('guestbook.signin') }}</h1>
|
<h1 class="text-black font-bold dark:text-white text-2xl">{{ $t('guestbook.signin') }}</h1>
|
||||||
<h3 class="text-gray-500 dark:text-gray-400">{{ $t('guestbook.share') }}</h3>
|
<h3 class="text-gray-500 dark:text-gray-400">{{ $t('guestbook.share') }}</h3>
|
||||||
<div class="flex space-x-4 my-3">
|
<div class="flex space-x-4 my-3">
|
||||||
<div @click="loginWithGoogle" class="icon-parent flex justify-center items-center p-2 border border-black dark:border-white duration-300 cursor-pointer">
|
<div @click="login('github')" class="icon-parent flex justify-center items-center p-2 border border-black dark:border-white duration-300 cursor-pointer">
|
||||||
<GoogleIcon />
|
<GoogleIcon />
|
||||||
</div>
|
</div>
|
||||||
<div @click="loginWithGithub" class="icon-parent flex justify-center items-center p-2 border border-black dark:border-white duration-300 cursor-pointer">
|
<div @click="login('google')" class="icon-parent flex justify-center items-center p-2 border border-black dark:border-white duration-300 cursor-pointer">
|
||||||
<GithubIcon />
|
<GithubIcon />
|
||||||
</div>
|
</div>
|
||||||
<div @click="loginWithTwitter" class="icon-parent flex justify-center items-center p-2 border border-black dark:border-white duration-300 cursor-pointer">
|
<div @click="login('twitter')" class="icon-parent flex justify-center items-center p-2 border border-black dark:border-white duration-300 cursor-pointer">
|
||||||
<TwitterIcon />
|
<TwitterIcon />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -45,46 +45,32 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {defineComponent, ref, useContext} from "@nuxtjs/composition-api";
|
import {computed, defineComponent, ref, useContext} from "@nuxtjs/composition-api";
|
||||||
import {GuestbookForm} from "~/types/types";
|
import {GuestbookForm} from "~/types/types";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "GuestBookForm",
|
name: "GuestBookForm",
|
||||||
setup() {
|
setup() {
|
||||||
const { $axios, $sentry } = useContext()
|
const { $axios, $sentry, app } = useContext()
|
||||||
|
|
||||||
const loginWithGithub = () => {
|
const login = async (driver: 'github' | 'google' | 'twitter') => {
|
||||||
$axios.get('/auth/github', {
|
const response = await $axios.get(`/auth/${driver}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
protocol: 'https',
|
protocol: 'https',
|
||||||
host: '127.0.0.1',
|
host: 'https://api.arthurdanjou.fr',
|
||||||
port: 80,
|
port: 80,
|
||||||
},
|
},
|
||||||
}).then((response) => {
|
|
||||||
console.log(response.headers, response.data, response.status, response.request)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const loginWithGoogle = () => {
|
|
||||||
return $axios.get('/auth/google', {
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const loginWithTwitter = () => {
|
|
||||||
$axios.get('/auth/twitter', {
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
if (response.status === 200) {
|
||||||
|
await hasAlreadySignMessage(response.data.user.id)
|
||||||
|
} else {
|
||||||
|
$sentry.captureEvent(response.data)
|
||||||
|
app.error({statusCode: 500})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = ref(false)
|
const error = ref(false)
|
||||||
@@ -92,7 +78,7 @@ export default defineComponent({
|
|||||||
const form = ref<GuestbookForm>({} as GuestbookForm)
|
const form = ref<GuestbookForm>({} as GuestbookForm)
|
||||||
|
|
||||||
const handleForm = async () => {
|
const handleForm = async () => {
|
||||||
const response = await $axios.post('/api/guestbook', {
|
const response = await $axios.post('/guestbook', {
|
||||||
message: form.value.message
|
message: form.value.message
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -111,14 +97,35 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const alreadySent = ref(false)
|
||||||
|
const hasAlreadySignMessage = async (id: number) => {
|
||||||
|
const response = await $axios.get(`/guestbook/${id}`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${process.env.API_TOKEN}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (response.status === 200) {
|
||||||
|
switch (response.data.data) {
|
||||||
|
case 0:
|
||||||
|
alreadySent.value = false
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
alreadySent.value = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sentry.captureEvent(response.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loginWithGithub,
|
login,
|
||||||
loginWithTwitter,
|
|
||||||
loginWithGoogle,
|
|
||||||
form,
|
form,
|
||||||
success,
|
success,
|
||||||
error,
|
error,
|
||||||
handleForm
|
alreadySent,
|
||||||
|
handleForm,
|
||||||
|
hasAlreadySignMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ export default {
|
|||||||
contact: 'Contact',
|
contact: 'Contact',
|
||||||
projects: 'Projects',
|
projects: 'Projects',
|
||||||
env: 'Tools',
|
env: 'Tools',
|
||||||
guestbook: 'Guestbook'
|
guestbook: 'Guestbook',
|
||||||
|
newsletter: 'Newsletter'
|
||||||
},
|
},
|
||||||
|
|
||||||
part: {
|
part: {
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ export default {
|
|||||||
contact: 'Contact',
|
contact: 'Contact',
|
||||||
projects: 'Projets',
|
projects: 'Projets',
|
||||||
env: 'Outils',
|
env: 'Outils',
|
||||||
guestbook: "Livre d'or"
|
guestbook: "Livre d'or",
|
||||||
|
newsletter: 'Newsletter'
|
||||||
},
|
},
|
||||||
|
|
||||||
part: {
|
part: {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export default defineComponent({
|
|||||||
const guestbook_messages = ref([])
|
const guestbook_messages = ref([])
|
||||||
|
|
||||||
useAsync(async () => {
|
useAsync(async () => {
|
||||||
await $axios.get('/guestbook', {
|
await $axios.get('guestbook', {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${process.env.API_TOKEN}`
|
'Authorization': `Bearer ${process.env.API_TOKEN}`
|
||||||
}
|
}
|
||||||
|
|||||||
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
@@ -22,7 +22,7 @@ declare module '@nuxt/types' {
|
|||||||
$axios: NuxtAxiosInstance,
|
$axios: NuxtAxiosInstance,
|
||||||
i18n: VueI18n & IVueI18n
|
i18n: VueI18n & IVueI18n
|
||||||
$colorMode: ColorModeInstance,
|
$colorMode: ColorModeInstance,
|
||||||
$app: NuxtApp,
|
app: NuxtApp,
|
||||||
$storage: NuxtStorage
|
$storage: NuxtStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user