add routes
This commit is contained in:
@@ -62,8 +62,8 @@ export default function Forgot({}: Route.ComponentProps) {
|
||||
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.
|
||||
Digite seu endereço de email ou cpf e lhe enviaremos um email com as
|
||||
instruções para redefinir sua senha.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -101,7 +101,7 @@ export default function Forgot({}: Route.ComponentProps) {
|
||||
<p className="text-white/50 text-xs text-center">
|
||||
Lembrou da senha?{' '}
|
||||
<Link to="/" className="underline hover:no-underline">
|
||||
Faça login
|
||||
Fazer login
|
||||
</Link>
|
||||
.
|
||||
</p>
|
||||
|
||||
@@ -11,7 +11,7 @@ export default function Layout() {
|
||||
<ChevronLeftIcon className="size-5" /> Página inicial
|
||||
</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 />
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3,8 +3,15 @@ import { useRequest } from 'ahooks'
|
||||
import { z } from 'zod'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
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 {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertTitle
|
||||
} from '@repo/ui/components/ui/alert'
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
@@ -17,7 +24,7 @@ import { Input } from '@repo/ui/components/ui/input'
|
||||
import { Spinner } from '@repo/ui/components/ui/spinner'
|
||||
import { cpf, type RegisterContextProps, type User } from './data'
|
||||
import { RegisterContext } from './data'
|
||||
import { use } from 'react'
|
||||
import { use, useState } from 'react'
|
||||
|
||||
const formSchema = z.object({
|
||||
cpf: cpf
|
||||
@@ -27,10 +34,11 @@ type Schema = z.infer<typeof formSchema>
|
||||
|
||||
export function Cpf() {
|
||||
const { setUser } = use(RegisterContext) as RegisterContextProps
|
||||
const [isOnboarded, setIsOnboarded] = useState<Boolean>(false)
|
||||
const form = useForm({
|
||||
resolver: zodResolver(formSchema)
|
||||
})
|
||||
const { control, handleSubmit, formState } = form
|
||||
const { control, handleSubmit, formState, setError } = form
|
||||
const { runAsync } = useRequest(
|
||||
async ({ cpf }) => {
|
||||
return await fetch(`/lookup?cpf=${cpf}`, {
|
||||
@@ -43,8 +51,15 @@ export function Cpf() {
|
||||
|
||||
const onSubmit = async ({ cpf }: Schema) => {
|
||||
const r = await runAsync({ cpf })
|
||||
const user = (await r.json()) as any
|
||||
setUser({ cpf, ...user })
|
||||
const data = (await r.json()) as any
|
||||
|
||||
if (r.ok) {
|
||||
setUser({ cpf, ...data })
|
||||
}
|
||||
|
||||
if (r.status === 409) {
|
||||
setIsOnboarded(true)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -52,6 +67,27 @@ export function Cpf() {
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<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
|
||||
control={control}
|
||||
name="cpf"
|
||||
|
||||
@@ -9,6 +9,7 @@ export type User = {
|
||||
cpf: string
|
||||
name: string
|
||||
email: string
|
||||
never_logged?: boolean
|
||||
}
|
||||
|
||||
export const cpf = z
|
||||
@@ -16,7 +17,8 @@ export const cpf = z
|
||||
.nonempty('Digite seu CPF')
|
||||
.refine(isValidCPF, 'Deve ser um CPF válido')
|
||||
|
||||
export const formSchema = z.object({
|
||||
export const formSchema = z
|
||||
.object({
|
||||
name: z
|
||||
.string()
|
||||
.trim()
|
||||
@@ -27,8 +29,13 @@ export const formSchema = z.object({
|
||||
.string()
|
||||
.nonempty('Digite sua senha')
|
||||
.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>
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ import type { Route } from '../+types'
|
||||
|
||||
import { PatternFormat } from 'react-number-format'
|
||||
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 { Button } from '@repo/ui/components/ui/button'
|
||||
@@ -20,6 +21,11 @@ import { Label } from '@repo/ui/components/ui/label'
|
||||
|
||||
import { Cpf } from './cpf'
|
||||
import { formSchema, type Schema, RegisterContext, type User } from './data'
|
||||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertTitle
|
||||
} from '@repo/ui/components/ui/alert'
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [{ title: 'Criar conta · EDUSEG®' }]
|
||||
@@ -44,6 +50,17 @@ export default function Signup({}: Route.ComponentProps) {
|
||||
{user ? (
|
||||
<Form {...form}>
|
||||
<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
|
||||
control={control}
|
||||
name="name"
|
||||
@@ -109,7 +126,25 @@ export default function Signup({}: Route.ComponentProps) {
|
||||
<FormControl>
|
||||
<Input
|
||||
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"
|
||||
{...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 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 layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey, TransactKey
|
||||
from layercake.extra_types import CnpjStr, CpfStr
|
||||
@@ -14,36 +19,55 @@ router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(OAUTH2_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
class UserAlreadyOnboardedError(ServiceError):
|
||||
def __init__(self, msg: str | dict):
|
||||
super().__init__(HTTPStatus.CONFLICT, msg)
|
||||
|
||||
|
||||
@router.get('/lookup')
|
||||
def lookup(
|
||||
email: Annotated[EmailStr, Path] = 'unknown',
|
||||
cpf: Annotated[CpfStr, Path] = 'unknown',
|
||||
cnpj: Annotated[CnpjStr, Path] = 'unknown',
|
||||
email: Annotated[EmailStr | None, Path] = None,
|
||||
cpf: Annotated[CpfStr | None, Path] = None,
|
||||
cnpj: Annotated[CnpjStr | None, Path] = None,
|
||||
):
|
||||
if not any([email, cpf, cnpj]):
|
||||
raise BadRequestError('Malformed body request')
|
||||
|
||||
r = dyn.collection.get_items(
|
||||
KeyPair(
|
||||
pk='email',
|
||||
sk=SortKey(email, path_spec='user_id'),
|
||||
rename_key='id',
|
||||
sk=SortKey(email, path_spec='user_id'), # type: ignore
|
||||
rename_key='user_id',
|
||||
)
|
||||
+ KeyPair(
|
||||
pk='cpf',
|
||||
sk=SortKey(cpf, path_spec='user_id'),
|
||||
rename_key='id',
|
||||
sk=SortKey(cpf, path_spec='user_id'), # type: ignore
|
||||
rename_key='user_id',
|
||||
)
|
||||
+ KeyPair(
|
||||
pk='cnpj',
|
||||
sk=SortKey(cnpj, path_spec='user_id'),
|
||||
sk=SortKey(cnpj, path_spec='user_id'), # type: ignore
|
||||
rename_key='org_id',
|
||||
),
|
||||
flatten_top=False,
|
||||
)
|
||||
|
||||
if 'id' in r:
|
||||
if cnpj:
|
||||
return pick(('org_id',), r)
|
||||
|
||||
if 'user_id' not in r:
|
||||
return {}
|
||||
|
||||
user = dyn.collection.get_items(
|
||||
TransactKey(r['id']) + SortKey('0') + SortKey('FRESH_USER')
|
||||
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)],
|
||||
password: Annotated[str, Body(min_length=6, 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,
|
||||
):
|
||||
if user_id:
|
||||
...
|
||||
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user