add turborepo
This commit is contained in:
69
apps/id.saladeaula.digital/app/routes/authorize.ts
Normal file
69
apps/id.saladeaula.digital/app/routes/authorize.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
import { parse } from 'cookie'
|
||||
|
||||
export const OK = 200
|
||||
export const FOUND = 302
|
||||
export const INTERNAL_SERVER_ERROR = 500
|
||||
|
||||
export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
const cookies = parse(request.headers.get('Cookie') || '')
|
||||
const url = new URL(request.url)
|
||||
const loginUrl = new URL('/', url.origin)
|
||||
const issuerUrl = new URL('/authorize', context.cloudflare.env.ISSUER_URL)
|
||||
issuerUrl.search = url.search
|
||||
loginUrl.search = url.search
|
||||
|
||||
if (!cookies?.__session) {
|
||||
return new Response(null, {
|
||||
status: FOUND,
|
||||
headers: {
|
||||
Location: loginUrl.toString()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
const r = await fetch(issuerUrl.toString(), {
|
||||
method: 'GET',
|
||||
headers: new Headers([
|
||||
['Content-Type', 'application/json'],
|
||||
['Cookie', request.headers.get('Cookie') as string]
|
||||
]),
|
||||
redirect: 'manual'
|
||||
})
|
||||
|
||||
if (r.status === FOUND) {
|
||||
return new Response(await r.text(), {
|
||||
status: r.status,
|
||||
headers: r.headers
|
||||
})
|
||||
}
|
||||
|
||||
console.log('Authorize response', {
|
||||
json: await r.json(),
|
||||
headers: r.headers,
|
||||
status: r.status
|
||||
})
|
||||
|
||||
// Deny authorization if user lacks scopes requested by client
|
||||
if (r.status === FOUND) {
|
||||
return new Response(null, {
|
||||
status: r.status,
|
||||
headers: {
|
||||
Location: new URL('/deny', url.origin).toString()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return new Response(null, {
|
||||
status: FOUND,
|
||||
headers: {
|
||||
Location: loginUrl.toString()
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return new Response(null, { status: INTERNAL_SERVER_ERROR })
|
||||
}
|
||||
}
|
||||
20
apps/id.saladeaula.digital/app/routes/deny.tsx
Normal file
20
apps/id.saladeaula.digital/app/routes/deny.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { LockIcon } from 'lucide-react'
|
||||
import type { Route } from './+types'
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [{ title: 'Acesso negado · EDUSEG®' }]
|
||||
}
|
||||
|
||||
export default function Deny({}: Route.ComponentProps) {
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col text-center items-center gap-6">
|
||||
<LockIcon className="size-12" />
|
||||
<div className="space-y-1.5">
|
||||
<h1 className="text-xl text-gray-10 font-bold">Acesso negado.</h1>
|
||||
<p>Você não tem permissão.</p>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
111
apps/id.saladeaula.digital/app/routes/forgot.tsx
Normal file
111
apps/id.saladeaula.digital/app/routes/forgot.tsx
Normal file
@@ -0,0 +1,111 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
import { Link } from 'react-router'
|
||||
|
||||
import logo from '@/components/logo.svg'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage
|
||||
} from '@/components/ui/form'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
|
||||
const schema = z.object({
|
||||
username: z
|
||||
.string()
|
||||
.trim()
|
||||
.nonempty('Digite seu Email ou CPF')
|
||||
.refine((val) => {
|
||||
const onlyDigits = val.replace(/\D/g, '')
|
||||
|
||||
return onlyDigits.length === 11
|
||||
? isValidCPF(val)
|
||||
: z.email().safeParse(val).success
|
||||
}, 'Deve ser um Email ou CPF válido')
|
||||
})
|
||||
|
||||
type Schema = z.infer<typeof schema>
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [{ title: 'Redefinir senha · EDUSEG®' }]
|
||||
}
|
||||
|
||||
export default function Forgot({}: Route.ComponentProps) {
|
||||
const form = useForm({
|
||||
resolver: zodResolver(schema)
|
||||
})
|
||||
const { control, handleSubmit, formState } = form
|
||||
|
||||
const onSubmit = async (data: Schema) => {
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="w-full max-w-xs grid gap-6">
|
||||
<div className="flex justify-center">
|
||||
<div className="border border-white/15 bg-white/5 px-2.5 py-3 rounded-xl">
|
||||
<img src={logo} alt="EDUSEG®" className="block size-12" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-center space-y-1.5">
|
||||
<h1 className="text-2xl font-semibold font-display text-balance">
|
||||
Redefinir senha
|
||||
</h1>
|
||||
<p className="text-white/50 text-sm">
|
||||
Digite seu email e lhe enviaremos um email com as instruções para
|
||||
redefinir sua senha.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="grid gap-6">
|
||||
<FormField
|
||||
control={control}
|
||||
name="username"
|
||||
defaultValue=""
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Email ou CPF</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
autoFocus={true}
|
||||
placeholder="seu@email.com"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full bg-lime-400 cursor-pointer"
|
||||
disabled={formState.isSubmitting}
|
||||
>
|
||||
Enviar instruções
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
<p className="text-white/50 text-xs text-center">
|
||||
Lembrou da senha?{' '}
|
||||
<Link to="/" className="underline hover:no-underline">
|
||||
Faça login
|
||||
</Link>
|
||||
.
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
228
apps/id.saladeaula.digital/app/routes/index.tsx
Normal file
228
apps/id.saladeaula.digital/app/routes/index.tsx
Normal file
@@ -0,0 +1,228 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage
|
||||
} from '@/components/ui/form'
|
||||
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { Loader2Icon } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { Link, useFetcher } from 'react-router'
|
||||
import { z } from 'zod'
|
||||
|
||||
import logo from '@/components/logo.svg'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { FOUND, INTERNAL_SERVER_ERROR, OK } from './authorize'
|
||||
|
||||
const schema = z.object({
|
||||
username: z
|
||||
.string()
|
||||
.trim()
|
||||
.nonempty('Digite seu Email ou CPF')
|
||||
.refine((val) => {
|
||||
const onlyDigits = val.replace(/\D/g, '')
|
||||
|
||||
return onlyDigits.length === 11
|
||||
? isValidCPF(val)
|
||||
: z.email().safeParse(val).success
|
||||
}, 'Deve ser um Email ou CPF válido'),
|
||||
password: z
|
||||
.string()
|
||||
.nonempty('Digite sua senha')
|
||||
.min(6, 'Deve ter no mínimo 6 caracteres')
|
||||
})
|
||||
|
||||
type Schema = z.infer<typeof schema>
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [{ title: 'EDUSEG®' }]
|
||||
}
|
||||
|
||||
export async function action({ request, context }: Route.ActionArgs) {
|
||||
const issuerUrl = new URL('/session', context.cloudflare.env.ISSUER_URL)
|
||||
const formData = Object.fromEntries(await request.formData())
|
||||
|
||||
try {
|
||||
const r = await fetch(issuerUrl.toString(), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(formData)
|
||||
})
|
||||
|
||||
if (r.status !== OK) {
|
||||
return Response.json(await r.json(), {
|
||||
status: r.status,
|
||||
headers: r.headers
|
||||
})
|
||||
}
|
||||
|
||||
const url = new URL(request.url)
|
||||
url.pathname = '/authorize'
|
||||
|
||||
const headers = new Headers(r.headers)
|
||||
headers.set('Location', url.toString())
|
||||
|
||||
return new Response(await r.text(), {
|
||||
status: FOUND,
|
||||
headers
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return Response.json({}, { status: INTERNAL_SERVER_ERROR })
|
||||
}
|
||||
}
|
||||
|
||||
export default function Index({}: Route.ComponentProps) {
|
||||
const [show, setShow] = useState(false)
|
||||
const fetcher = useFetcher()
|
||||
|
||||
const form = useForm({
|
||||
resolver: zodResolver(schema)
|
||||
})
|
||||
const { control, handleSubmit, formState, setError } = form
|
||||
|
||||
const onSubmit = async (data: Schema) => {
|
||||
await fetcher.submit(data, { method: 'post' })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (fetcher.state === 'idle' && fetcher.data) {
|
||||
const message = fetcher.data?.message
|
||||
|
||||
switch (message) {
|
||||
case 'User not found':
|
||||
return setError('username', {
|
||||
message:
|
||||
'Conta não encontrada. Certifique-se de que está usando o Email ou CPF correto.',
|
||||
type: 'manual'
|
||||
})
|
||||
case 'Invalid credentials':
|
||||
return setError('password', {
|
||||
message: 'A senha está incorreta.',
|
||||
type: 'manual'
|
||||
})
|
||||
}
|
||||
}
|
||||
}, [fetcher.state, fetcher.data])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="w-full max-w-xs grid gap-6">
|
||||
<div className="flex justify-center">
|
||||
<div className="border border-white/15 bg-white/5 px-2.5 py-3 rounded-xl">
|
||||
<img src={logo} alt="EDUSEG®" className="block size-12" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="grid gap-6">
|
||||
<div className="text-center space-y-1.5">
|
||||
<h1 className="text-2xl font-semibold font-display text-balance">
|
||||
Entrar
|
||||
</h1>
|
||||
<p className="text-white/50 text-sm">
|
||||
Não tem uma senha?{' '}
|
||||
<Link
|
||||
to="/signup"
|
||||
className="font-medium text-white hover:underline"
|
||||
>
|
||||
Criar senha
|
||||
</Link>
|
||||
.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<FormField
|
||||
control={control}
|
||||
name="username"
|
||||
defaultValue=""
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Email ou CPF</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
autoFocus={true}
|
||||
placeholder="seu@email.com"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={control}
|
||||
name="password"
|
||||
defaultValue=""
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<div className="flex">
|
||||
<FormLabel>Senha</FormLabel>
|
||||
<Link
|
||||
to="/forgot"
|
||||
tabIndex={-1}
|
||||
className="ml-auto text-sm underline-offset-4 hover:underline"
|
||||
>
|
||||
Esqueceu sua senha?
|
||||
</Link>
|
||||
</div>
|
||||
<FormControl>
|
||||
<Input
|
||||
type={show ? 'text' : 'password'}
|
||||
placeholder="••••••••"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="flex items-center gap-3">
|
||||
<Checkbox
|
||||
id="showPassword"
|
||||
onClick={() => setShow((x) => !x)}
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<Label htmlFor="showPassword">Mostrar senha</Label>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full bg-lime-400 cursor-pointer"
|
||||
disabled={formState.isSubmitting}
|
||||
>
|
||||
{formState.isSubmitting && (
|
||||
<Loader2Icon className="animate-spin" />
|
||||
)}
|
||||
Entrar
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
<p className="text-white/50 text-xs text-center">
|
||||
Ao fazer login, você concorda com nossa{' '}
|
||||
<a
|
||||
href="//eduseg.com.br/politica"
|
||||
target="_blank"
|
||||
className="underline hover:no-underline"
|
||||
>
|
||||
política de privacidade
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
29
apps/id.saladeaula.digital/app/routes/layout.tsx
Normal file
29
apps/id.saladeaula.digital/app/routes/layout.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ChevronLeftIcon } from 'lucide-react'
|
||||
import { Outlet } from 'react-router'
|
||||
|
||||
export default function Layout() {
|
||||
return (
|
||||
<div className="flex min-h-svh w-full items-center justify-center p-6 md:p-10 relative">
|
||||
<a
|
||||
href="//eduseg.com.br"
|
||||
className="flex items-center gap-0.5 absolute top-5 left-5 text-sm z-1"
|
||||
>
|
||||
<ChevronLeftIcon className="size-5" /> Página inicial
|
||||
</a>
|
||||
|
||||
<div className="w-full max-w-sm relative z-1">
|
||||
<Outlet />
|
||||
</div>
|
||||
|
||||
<div className="w-full top-1/2 max-w-sm absolute pt-12 -translate-y-1/2">
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="absolute inset-0 grid grid-cols-2 opacity-20"
|
||||
>
|
||||
<div className="blur-[106px] h-56 bg-gradient-to-br to-lime-400 from-lime-700"></div>
|
||||
<div className="blur-[106px] h-42 bg-gradient-to-r from-lime-400 to-lime-600"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
173
apps/id.saladeaula.digital/app/routes/signup.tsx
Normal file
173
apps/id.saladeaula.digital/app/routes/signup.tsx
Normal file
@@ -0,0 +1,173 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { Link } from 'react-router'
|
||||
|
||||
import logo from '@/components/logo.svg'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage
|
||||
} from '@/components/ui/form'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod'
|
||||
|
||||
const schema = z.object({
|
||||
name: z.string().trim().nonempty('Digite seu nome'),
|
||||
email: z.email('Digite seu email'),
|
||||
password: z
|
||||
.string()
|
||||
.nonempty('Digite sua senha')
|
||||
.min(6, 'Deve ter no mínimo 6 caracteres'),
|
||||
cpf: z
|
||||
.string()
|
||||
.nonempty('Digite seu CPF')
|
||||
.refine(isValidCPF, 'Deve ser um CPF válido')
|
||||
})
|
||||
|
||||
type Schema = z.infer<typeof schema>
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [{ title: 'Criar conta · EDUSEG®' }]
|
||||
}
|
||||
|
||||
export default function Signup({}: Route.ComponentProps) {
|
||||
const [show, setShow] = useState(false)
|
||||
const form = useForm({
|
||||
resolver: zodResolver(schema)
|
||||
})
|
||||
const { control, handleSubmit, formState } = form
|
||||
|
||||
const onSubmit = async (data: Schema) => {
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="w-full max-w-xs grid gap-6">
|
||||
<div className="flex justify-center">
|
||||
<div className="border border-white/15 bg-white/5 px-2.5 py-3 rounded-xl">
|
||||
<img src={logo} alt="EDUSEG®" className="block size-12" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-center space-y-1.5">
|
||||
<h1 className="text-2xl font-semibold font-display text-balance">
|
||||
Criar conta
|
||||
</h1>
|
||||
<p className="text-white/50 text-sm">
|
||||
Já tem uma conta?{' '}
|
||||
<Link to="/" className="font-medium text-white hover:underline">
|
||||
Faça login
|
||||
</Link>
|
||||
.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="grid gap-6">
|
||||
<FormField
|
||||
control={control}
|
||||
name="name"
|
||||
defaultValue=""
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Nome</FormLabel>
|
||||
<FormControl>
|
||||
<Input autoFocus={true} placeholder="Seu nome" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={control}
|
||||
name="email"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Email</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="seu@email.com" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={control}
|
||||
name="cpf"
|
||||
defaultValue=""
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>CPF</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="___.___.___-__" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={control}
|
||||
name="password"
|
||||
defaultValue=""
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Senha</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type={show ? 'text' : 'password'}
|
||||
placeholder="••••••••"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="flex items-center gap-3">
|
||||
<Checkbox
|
||||
id="showPassword"
|
||||
onClick={() => setShow((x) => !x)}
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<Label htmlFor="showPassword">Mostrar senha</Label>
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full bg-lime-400 cursor-pointer"
|
||||
disabled={formState.isSubmitting}
|
||||
>
|
||||
Criar conta
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
<p className="text-white/50 text-xs text-center">
|
||||
Ao fazer login, você concorda com nossa{' '}
|
||||
<a
|
||||
href="//eduseg.com.br/politica"
|
||||
target="_blank"
|
||||
className="underline hover:no-underline"
|
||||
>
|
||||
política de privacidade
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
31
apps/id.saladeaula.digital/app/routes/upstream.ts
Normal file
31
apps/id.saladeaula.digital/app/routes/upstream.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
export const loader = proxy
|
||||
export const action = proxy
|
||||
|
||||
async function proxy({
|
||||
request,
|
||||
context
|
||||
}: Route.ActionArgs): Promise<Response> {
|
||||
const pathname = new URL(request.url).pathname
|
||||
const url = new URL(pathname, context.cloudflare.env.ISSUER_URL)
|
||||
const headers = new Headers(request.headers)
|
||||
const response = await fetch(url.toString(), {
|
||||
method: request.method,
|
||||
headers,
|
||||
...(['GET', 'HEAD'].includes(request.method)
|
||||
? {}
|
||||
: { body: await request.text() })
|
||||
})
|
||||
|
||||
const contentType = response.headers.get('content-type') || ''
|
||||
const body =
|
||||
contentType.includes('application/json') || contentType.startsWith('text/')
|
||||
? await response.text()
|
||||
: await response.arrayBuffer()
|
||||
|
||||
return new Response(body, {
|
||||
status: response.status,
|
||||
headers: response.headers
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user