confirm-component
This commit is contained in:
parent
a80f123308
commit
9712724b93
|
@ -1,29 +0,0 @@
|
|||
<html>
|
||||
<head><title>discours.io</title></head>
|
||||
<body onmousemove="window.close()" onclick="window.close()" onkeydown="window.close()">
|
||||
<style>
|
||||
.center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 420px;
|
||||
}
|
||||
</style>
|
||||
<div class="center">
|
||||
Авторизация завершена, это окно закрывается по куче причин.
|
||||
</div>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
const ccc = document.cookie.split(';')
|
||||
if (ccc) {
|
||||
const t = ccc[0].replace('token=','')
|
||||
if (t) {
|
||||
console.log('[auth] got token cookie!')
|
||||
document.cookie = ""
|
||||
window.localStorage.setItem('token', t)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
6
src/components/Nav/Confirmed.scss
Normal file
6
src/components/Nav/Confirmed.scss
Normal file
|
@ -0,0 +1,6 @@
|
|||
.center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 420px;
|
||||
}
|
18
src/components/Nav/Confirmed.tsx
Normal file
18
src/components/Nav/Confirmed.tsx
Normal file
|
@ -0,0 +1,18 @@
|
|||
import './Confirmed.scss'
|
||||
import { onMount } from 'solid-js'
|
||||
import { t } from '../../utils/intl'
|
||||
|
||||
export const Confirmed = (props: { token?: string }) => {
|
||||
onMount(() => {
|
||||
const token = props.token ?? document.cookie.split(';').at(0).replace('token=', '')
|
||||
window.addEventListener('mousemove', () => window.close())
|
||||
window.addEventListener('keydown', () => window.close())
|
||||
window.addEventListener('click', () => window.close())
|
||||
localStorage.setItem('token', token)
|
||||
})
|
||||
return (
|
||||
<>
|
||||
<div class="center">{t('You was successfully authorized')}</div>
|
||||
</>
|
||||
)
|
||||
}
|
|
@ -767,7 +767,6 @@ export type User = {
|
|||
updatedAt?: Maybe<Scalars['DateTime']>
|
||||
username: Scalars['String']
|
||||
userpic?: Maybe<Scalars['String']>
|
||||
wasOnlineAt?: Maybe<Scalars['DateTime']>
|
||||
}
|
||||
|
||||
export type UserFollowings = {
|
||||
|
|
31
src/pages/api/sendlink.ts
Normal file
31
src/pages/api/sendlink.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import Mailgun from 'mailgun.js'
|
||||
import FormDataPackage from 'form-data'
|
||||
|
||||
const domain: string = process.env.MAILGUN_DOMAIN
|
||||
const key: string = process.env.MAILGUN_API_KEY
|
||||
const mailgun = new Mailgun(FormDataPackage)
|
||||
const mg = mailgun.client({
|
||||
username: 'api',
|
||||
key,
|
||||
url: 'https://api.mailgun.net'
|
||||
})
|
||||
|
||||
export type EmailContent = {
|
||||
to: string | string[]
|
||||
subject: string
|
||||
text: string
|
||||
html?: string
|
||||
from?: string
|
||||
}
|
||||
|
||||
const from = `discours.io <noreply@discours.io>`
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { to, subject } = req.query
|
||||
const token = '' // FIXME
|
||||
const text = 'Follow the link to confirm email: https://new.discours.io/confirm/' + token // TODO: use templates here
|
||||
mg.messages
|
||||
.create(domain, { to, subject, text, from } as EmailContent)
|
||||
.then((_) => res.status(200))
|
||||
.catch(console.error)
|
||||
}
|
11
src/pages/confirm/[token].astro
Normal file
11
src/pages/confirm/[token].astro
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
import { Confirmed } from '../../components/Nav/Confirmed'
|
||||
|
||||
const token = Astro.params.token?.toString() || ''
|
||||
---
|
||||
<html>
|
||||
<head><title>discours.io</title></head>
|
||||
<body>
|
||||
<Confirmed token={token} />
|
||||
</body>
|
||||
</html>
|
9
src/pages/confirm/index.astro
Normal file
9
src/pages/confirm/index.astro
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
import { Confirmed } from '../../components/Nav/Confirmed'
|
||||
---
|
||||
<html>
|
||||
<head><title>discours.io</title></head>
|
||||
<body>
|
||||
<Confirmed />
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user