add routes
This commit is contained in:
@@ -62,8 +62,8 @@ export default function Forgot({}: Route.ComponentProps) {
|
|||||||
Redefinir senha
|
Redefinir senha
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-white/50 text-sm">
|
<p className="text-white/50 text-sm">
|
||||||
Digite seu email e lhe enviaremos um email com as instruções para
|
Digite seu endereço de email ou cpf e lhe enviaremos um email com as
|
||||||
redefinir sua senha.
|
instruções para redefinir sua senha.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ export default function Forgot({}: Route.ComponentProps) {
|
|||||||
<p className="text-white/50 text-xs text-center">
|
<p className="text-white/50 text-xs text-center">
|
||||||
Lembrou da senha?{' '}
|
Lembrou da senha?{' '}
|
||||||
<Link to="/" className="underline hover:no-underline">
|
<Link to="/" className="underline hover:no-underline">
|
||||||
Faça login
|
Fazer login
|
||||||
</Link>
|
</Link>
|
||||||
.
|
.
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default function Layout() {
|
|||||||
<ChevronLeftIcon className="size-5" /> Página inicial
|
<ChevronLeftIcon className="size-5" /> Página inicial
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div className="w-full max-w-xs relative z-1 max-lg:mt-8">
|
<div className="w-full max-w-xs relative z-1 max-lg:mt-8 space-y-6">
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,15 @@ import { useRequest } from 'ahooks'
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { zodResolver } from '@hookform/resolvers/zod'
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
import { useForm } from 'react-hook-form'
|
import { useForm } from 'react-hook-form'
|
||||||
|
import { AlertCircleIcon } from 'lucide-react'
|
||||||
|
import { Link } from 'react-router'
|
||||||
|
|
||||||
import { Button } from '@repo/ui/components/ui/button'
|
import { Button } from '@repo/ui/components/ui/button'
|
||||||
|
import {
|
||||||
|
Alert,
|
||||||
|
AlertDescription,
|
||||||
|
AlertTitle
|
||||||
|
} from '@repo/ui/components/ui/alert'
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@@ -17,7 +24,7 @@ import { Input } from '@repo/ui/components/ui/input'
|
|||||||
import { Spinner } from '@repo/ui/components/ui/spinner'
|
import { Spinner } from '@repo/ui/components/ui/spinner'
|
||||||
import { cpf, type RegisterContextProps, type User } from './data'
|
import { cpf, type RegisterContextProps, type User } from './data'
|
||||||
import { RegisterContext } from './data'
|
import { RegisterContext } from './data'
|
||||||
import { use } from 'react'
|
import { use, useState } from 'react'
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
cpf: cpf
|
cpf: cpf
|
||||||
@@ -27,10 +34,11 @@ type Schema = z.infer<typeof formSchema>
|
|||||||
|
|
||||||
export function Cpf() {
|
export function Cpf() {
|
||||||
const { setUser } = use(RegisterContext) as RegisterContextProps
|
const { setUser } = use(RegisterContext) as RegisterContextProps
|
||||||
|
const [isOnboarded, setIsOnboarded] = useState<Boolean>(false)
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
resolver: zodResolver(formSchema)
|
resolver: zodResolver(formSchema)
|
||||||
})
|
})
|
||||||
const { control, handleSubmit, formState } = form
|
const { control, handleSubmit, formState, setError } = form
|
||||||
const { runAsync } = useRequest(
|
const { runAsync } = useRequest(
|
||||||
async ({ cpf }) => {
|
async ({ cpf }) => {
|
||||||
return await fetch(`/lookup?cpf=${cpf}`, {
|
return await fetch(`/lookup?cpf=${cpf}`, {
|
||||||
@@ -43,8 +51,15 @@ export function Cpf() {
|
|||||||
|
|
||||||
const onSubmit = async ({ cpf }: Schema) => {
|
const onSubmit = async ({ cpf }: Schema) => {
|
||||||
const r = await runAsync({ cpf })
|
const r = await runAsync({ cpf })
|
||||||
const user = (await r.json()) as any
|
const data = (await r.json()) as any
|
||||||
setUser({ cpf, ...user })
|
|
||||||
|
if (r.ok) {
|
||||||
|
setUser({ cpf, ...data })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.status === 409) {
|
||||||
|
setIsOnboarded(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -52,6 +67,27 @@ export function Cpf() {
|
|||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<fieldset disabled={formState.isSubmitting} className="grid gap-6">
|
<fieldset disabled={formState.isSubmitting} className="grid gap-6">
|
||||||
|
{isOnboarded && (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircleIcon />
|
||||||
|
<AlertTitle>Você já está cadastrado.</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
<p>
|
||||||
|
Por favor, siga as instruções abaixo para acessar sua conta:
|
||||||
|
</p>
|
||||||
|
<ul className="list-disc text-sm mt-2.5 [&_a]:underline [&_a]:hover:no-underline">
|
||||||
|
<li>
|
||||||
|
Você lembra da sua senha? <Link to="/">Fazer login</Link>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Esqueceu a senha?{' '}
|
||||||
|
<Link to="/forgot">Recuperar minha senha</Link>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={control}
|
control={control}
|
||||||
name="cpf"
|
name="cpf"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export type User = {
|
|||||||
cpf: string
|
cpf: string
|
||||||
name: string
|
name: string
|
||||||
email: string
|
email: string
|
||||||
|
never_logged?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cpf = z
|
export const cpf = z
|
||||||
@@ -16,19 +17,25 @@ export const cpf = z
|
|||||||
.nonempty('Digite seu CPF')
|
.nonempty('Digite seu CPF')
|
||||||
.refine(isValidCPF, 'Deve ser um CPF válido')
|
.refine(isValidCPF, 'Deve ser um CPF válido')
|
||||||
|
|
||||||
export const formSchema = z.object({
|
export const formSchema = z
|
||||||
name: z
|
.object({
|
||||||
.string()
|
name: z
|
||||||
.trim()
|
.string()
|
||||||
.nonempty('Digite seu nome')
|
.trim()
|
||||||
.refine(isName, { message: 'Nome inválido' }),
|
.nonempty('Digite seu nome')
|
||||||
email: z.email('Digite seu email'),
|
.refine(isName, { message: 'Nome inválido' }),
|
||||||
password: z
|
email: z.email('Digite seu email'),
|
||||||
.string()
|
password: z
|
||||||
.nonempty('Digite sua senha')
|
.string()
|
||||||
.min(6, 'Deve ter no mínimo 6 caracteres'),
|
.nonempty('Digite sua senha')
|
||||||
cpf: cpf
|
.min(6, 'Deve ter no mínimo 6 caracteres'),
|
||||||
})
|
confirm_password: z.string(),
|
||||||
|
cpf: cpf
|
||||||
|
})
|
||||||
|
.refine((data) => data.password === data.confirm_password, {
|
||||||
|
message: 'As senhas não coincidem',
|
||||||
|
path: ['confirm_password']
|
||||||
|
})
|
||||||
|
|
||||||
export type Schema = z.infer<typeof formSchema>
|
export type Schema = z.infer<typeof formSchema>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import type { Route } from '../+types'
|
|||||||
|
|
||||||
import { PatternFormat } from 'react-number-format'
|
import { PatternFormat } from 'react-number-format'
|
||||||
import { zodResolver } from '@hookform/resolvers/zod'
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
import { useState, createContext, type ReactNode, use } from 'react'
|
import { useState } from 'react'
|
||||||
|
import { CheckCircle2Icon } from 'lucide-react'
|
||||||
import { useForm } from 'react-hook-form'
|
import { useForm } from 'react-hook-form'
|
||||||
|
|
||||||
import { Button } from '@repo/ui/components/ui/button'
|
import { Button } from '@repo/ui/components/ui/button'
|
||||||
@@ -20,6 +21,11 @@ import { Label } from '@repo/ui/components/ui/label'
|
|||||||
|
|
||||||
import { Cpf } from './cpf'
|
import { Cpf } from './cpf'
|
||||||
import { formSchema, type Schema, RegisterContext, type User } from './data'
|
import { formSchema, type Schema, RegisterContext, type User } from './data'
|
||||||
|
import {
|
||||||
|
Alert,
|
||||||
|
AlertDescription,
|
||||||
|
AlertTitle
|
||||||
|
} from '@repo/ui/components/ui/alert'
|
||||||
|
|
||||||
export function meta({}: Route.MetaArgs) {
|
export function meta({}: Route.MetaArgs) {
|
||||||
return [{ title: 'Criar conta · EDUSEG®' }]
|
return [{ title: 'Criar conta · EDUSEG®' }]
|
||||||
@@ -44,6 +50,17 @@ export default function Signup({}: Route.ComponentProps) {
|
|||||||
{user ? (
|
{user ? (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="grid gap-6">
|
<form onSubmit={handleSubmit(onSubmit)} className="grid gap-6">
|
||||||
|
{user?.never_logged && (
|
||||||
|
<Alert>
|
||||||
|
<CheckCircle2Icon />
|
||||||
|
<AlertTitle>Confirme seus dados</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
Revise suas informações e edite o que precisar antes de
|
||||||
|
continuar.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={control}
|
control={control}
|
||||||
name="name"
|
name="name"
|
||||||
@@ -109,7 +126,25 @@ export default function Signup({}: Route.ComponentProps) {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
type={show ? 'text' : 'password'}
|
type={show ? 'text' : 'password'}
|
||||||
placeholder="••••••••"
|
autoComplete="false"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={control}
|
||||||
|
name="password"
|
||||||
|
defaultValue=""
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Confirmar senha</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type={show ? 'text' : 'password'}
|
||||||
autoComplete="false"
|
autoComplete="false"
|
||||||
{...field}
|
{...field}
|
||||||
/>
|
/>
|
||||||
|
|||||||
25
enrollments-events/app/events/enroll_scheduled.py
Normal file
25
enrollments-events/app/events/enroll_scheduled.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from aws_lambda_powertools import Logger
|
||||||
|
from aws_lambda_powertools.utilities.data_classes import (
|
||||||
|
EventBridgeEvent,
|
||||||
|
event_source,
|
||||||
|
)
|
||||||
|
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||||
|
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||||
|
|
||||||
|
from boto3clients import dynamodb_client
|
||||||
|
from config import (
|
||||||
|
ENROLLMENT_TABLE,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = Logger(__name__)
|
||||||
|
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||||
|
|
||||||
|
|
||||||
|
@event_source(data_class=EventBridgeEvent)
|
||||||
|
@logger.inject_lambda_context
|
||||||
|
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||||
|
old_image = event.detail['old_image']
|
||||||
|
# Key pattern `SCHEDULED#ORG#{org_id}`
|
||||||
|
*_, org_id = old_image['id'].split('#')
|
||||||
|
|
||||||
|
return True
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
|
from http import HTTPStatus
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||||
|
from aws_lambda_powertools.event_handler.exceptions import (
|
||||||
|
BadRequestError,
|
||||||
|
ServiceError,
|
||||||
|
)
|
||||||
from aws_lambda_powertools.event_handler.openapi.params import Path
|
from aws_lambda_powertools.event_handler.openapi.params import Path
|
||||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey, TransactKey
|
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey, TransactKey
|
||||||
from layercake.extra_types import CnpjStr, CpfStr
|
from layercake.extra_types import CnpjStr, CpfStr
|
||||||
@@ -14,36 +19,55 @@ router = Router()
|
|||||||
dyn = DynamoDBPersistenceLayer(OAUTH2_TABLE, dynamodb_client)
|
dyn = DynamoDBPersistenceLayer(OAUTH2_TABLE, dynamodb_client)
|
||||||
|
|
||||||
|
|
||||||
|
class UserAlreadyOnboardedError(ServiceError):
|
||||||
|
def __init__(self, msg: str | dict):
|
||||||
|
super().__init__(HTTPStatus.CONFLICT, msg)
|
||||||
|
|
||||||
|
|
||||||
@router.get('/lookup')
|
@router.get('/lookup')
|
||||||
def lookup(
|
def lookup(
|
||||||
email: Annotated[EmailStr, Path] = 'unknown',
|
email: Annotated[EmailStr | None, Path] = None,
|
||||||
cpf: Annotated[CpfStr, Path] = 'unknown',
|
cpf: Annotated[CpfStr | None, Path] = None,
|
||||||
cnpj: Annotated[CnpjStr, Path] = 'unknown',
|
cnpj: Annotated[CnpjStr | None, Path] = None,
|
||||||
):
|
):
|
||||||
|
if not any([email, cpf, cnpj]):
|
||||||
|
raise BadRequestError('Malformed body request')
|
||||||
|
|
||||||
r = dyn.collection.get_items(
|
r = dyn.collection.get_items(
|
||||||
KeyPair(
|
KeyPair(
|
||||||
pk='email',
|
pk='email',
|
||||||
sk=SortKey(email, path_spec='user_id'),
|
sk=SortKey(email, path_spec='user_id'), # type: ignore
|
||||||
rename_key='id',
|
rename_key='user_id',
|
||||||
)
|
)
|
||||||
+ KeyPair(
|
+ KeyPair(
|
||||||
pk='cpf',
|
pk='cpf',
|
||||||
sk=SortKey(cpf, path_spec='user_id'),
|
sk=SortKey(cpf, path_spec='user_id'), # type: ignore
|
||||||
rename_key='id',
|
rename_key='user_id',
|
||||||
)
|
)
|
||||||
+ KeyPair(
|
+ KeyPair(
|
||||||
pk='cnpj',
|
pk='cnpj',
|
||||||
sk=SortKey(cnpj, path_spec='user_id'),
|
sk=SortKey(cnpj, path_spec='user_id'), # type: ignore
|
||||||
rename_key='org_id',
|
rename_key='org_id',
|
||||||
),
|
),
|
||||||
flatten_top=False,
|
flatten_top=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
if 'id' in r:
|
if cnpj:
|
||||||
user = dyn.collection.get_items(
|
return pick(('org_id',), r)
|
||||||
TransactKey(r['id']) + SortKey('0') + SortKey('FRESH_USER')
|
|
||||||
|
if 'user_id' not in r:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
user = dyn.collection.get_items(
|
||||||
|
TransactKey(r['user_id'])
|
||||||
|
+ SortKey('0')
|
||||||
|
+ SortKey(
|
||||||
|
sk='NEVER_LOGGED',
|
||||||
|
rename_key='never_logged',
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return r | pick(('name', 'email'), user) if 'FRESH_USER' in user else {}
|
if 'never_logged' not in user:
|
||||||
|
raise UserAlreadyOnboardedError('User is already onboarded')
|
||||||
|
|
||||||
return r
|
return {'never_logged': True} | pick(('id', 'name', 'email'), user)
|
||||||
|
|||||||
@@ -32,10 +32,7 @@ def register(
|
|||||||
email: Annotated[EmailStr, Body(embed=True)],
|
email: Annotated[EmailStr, Body(embed=True)],
|
||||||
password: Annotated[str, Body(min_length=6, embed=True)],
|
password: Annotated[str, Body(min_length=6, embed=True)],
|
||||||
cpf: Annotated[CpfStr, Body(embed=True)],
|
cpf: Annotated[CpfStr, Body(embed=True)],
|
||||||
user_id: Annotated[str | None, Body(embed=True)] = None,
|
id: Annotated[str | None, Body(embed=True)] = None,
|
||||||
org: Annotated[Org | None, Body(embed=True)] = None,
|
org: Annotated[Org | None, Body(embed=True)] = None,
|
||||||
):
|
):
|
||||||
if user_id:
|
|
||||||
...
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
Reference in New Issue
Block a user