first commit
This commit is contained in:
156
frontend/app/auth/login/page.tsx
Normal file
156
frontend/app/auth/login/page.tsx
Normal file
@@ -0,0 +1,156 @@
|
||||
"use client"
|
||||
|
||||
import React, { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { loginSchema, LoginInput } from '@/lib/auth-schema'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Turnstile } from 'nextjs-turnstile'
|
||||
import { signIn } from 'next-auth/react'
|
||||
import Swal from 'sweetalert2'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
|
||||
const LoginPage = () => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [turnstileToken, setTurnstileToken] = useState<string | null>(null)
|
||||
const router = useRouter()
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm<LoginInput>({
|
||||
resolver: zodResolver(loginSchema),
|
||||
})
|
||||
|
||||
const siteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITEKEY
|
||||
|
||||
const onSubmit = async (data: LoginInput) => {
|
||||
if (siteKey && !turnstileToken) {
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
title: 'Güvenlik Doğrulaması',
|
||||
text: 'Lütfen robot olmadığınızı doğrulayın.',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
|
||||
try {
|
||||
const result = await signIn('credentials', {
|
||||
redirect: false,
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
})
|
||||
|
||||
if (result?.error) {
|
||||
throw new Error(result.error)
|
||||
}
|
||||
|
||||
if (result?.ok) {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Giriş Başarılı',
|
||||
text: 'Yönlendiriliyorsunuz...',
|
||||
timer: 1500,
|
||||
showConfirmButton: false,
|
||||
}).then(() => {
|
||||
const callbackUrl = new URLSearchParams(window.location.search).get("callbackUrl") || "/"
|
||||
router.push(callbackUrl)
|
||||
router.refresh()
|
||||
})
|
||||
}
|
||||
|
||||
} catch {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Giriş Başarısız',
|
||||
text: 'E-posta veya şifre hatalı olabilir.',
|
||||
})
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-gray-100 p-4 dark:bg-gray-900">
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="space-y-1">
|
||||
<CardTitle className="text-2xl font-bold text-center">Giriş Yap</CardTitle>
|
||||
<CardDescription className="text-center">
|
||||
Hesabınıza erişmek için bilgilerinizi girin
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">E-posta</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="ornek@domain.com"
|
||||
{...register('email')}
|
||||
className={errors.email ? 'border-red-500' : ''}
|
||||
/>
|
||||
{errors.email && (
|
||||
<p className="text-sm text-red-500">{errors.email.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label htmlFor="password">Şifre</Label>
|
||||
<Link
|
||||
href="/auth/forgot-password"
|
||||
className="text-sm text-blue-600 hover:underline"
|
||||
>
|
||||
Şifremi Unuttum?
|
||||
</Link>
|
||||
</div>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
placeholder="********"
|
||||
{...register('password')}
|
||||
className={errors.password ? 'border-red-500' : ''}
|
||||
/>
|
||||
{errors.password && (
|
||||
<p className="text-sm text-red-500">{errors.password.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{siteKey && (
|
||||
<div className="flex justify-center my-4">
|
||||
<Turnstile
|
||||
siteKey={siteKey}
|
||||
onSuccess={(token) => setTurnstileToken(token)}
|
||||
onError={() => setTurnstileToken(null)}
|
||||
onExpire={() => setTurnstileToken(null)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Button type="submit" className="w-full" disabled={isLoading}>
|
||||
{isLoading ? 'Giriş Yapılıyor...' : 'Giriş Yap'}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
<CardFooter className="justify-center">
|
||||
<p className="text-sm text-gray-500">
|
||||
Hesabınız yok mu?{' '}
|
||||
<Link href="/auth/register" className="text-blue-600 hover:underline">
|
||||
Kayıt Ol
|
||||
</Link>
|
||||
</p>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginPage
|
||||
176
frontend/app/auth/register/page.tsx
Normal file
176
frontend/app/auth/register/page.tsx
Normal file
@@ -0,0 +1,176 @@
|
||||
"use client"
|
||||
|
||||
import React, { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { registerSchema, RegisterInput } from '@/lib/auth-schema'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import Link from 'next/link'
|
||||
import Swal from 'sweetalert2'
|
||||
import { Turnstile } from 'nextjs-turnstile'
|
||||
import { useRouter } from 'next/navigation'
|
||||
|
||||
const RegisterPage = () => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [turnstileToken, setTurnstileToken] = useState<string | null>(null)
|
||||
const router = useRouter()
|
||||
const siteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITEKEY
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm<RegisterInput>({
|
||||
resolver: zodResolver(registerSchema),
|
||||
})
|
||||
|
||||
const onSubmit = async (data: RegisterInput) => {
|
||||
if (siteKey && !turnstileToken) {
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
title: 'Güvenlik Doğrulaması',
|
||||
text: 'Lütfen robot olmadığınızı doğrulayın.',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/register`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: data.username,
|
||||
email: data.email,
|
||||
password: data.password
|
||||
}),
|
||||
})
|
||||
|
||||
const result = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result.error || result.message || 'Kayıt işlemi başarısız oldu.')
|
||||
}
|
||||
|
||||
Swal.fire({
|
||||
title: 'Başarılı!',
|
||||
text: 'Kayıt işlemi başarıyla tamamlandı. Lütfen e-posta adresinizi doğrulayın.',
|
||||
icon: 'success',
|
||||
confirmButtonText: 'Giriş Yap',
|
||||
}).then(() => {
|
||||
router.push('/auth/login')
|
||||
})
|
||||
|
||||
} catch (error: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
Swal.fire({
|
||||
title: 'Hata!',
|
||||
text: error.message || 'Bir sorun oluştu.',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'Tamam',
|
||||
})
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-gray-100 p-4 dark:bg-gray-900">
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="space-y-1">
|
||||
<CardTitle className="text-2xl font-bold text-center">Kayıt Ol</CardTitle>
|
||||
<CardDescription className="text-center">
|
||||
Yeni bir hesap oluşturmak için bilgilerinizi girin
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="username">Kullanıcı Adı</Label>
|
||||
<Input
|
||||
id="username"
|
||||
placeholder="johndoe"
|
||||
{...register('username')}
|
||||
className={errors.username ? 'border-red-500' : ''}
|
||||
/>
|
||||
{errors.username && (
|
||||
<p className="text-sm text-red-500">{errors.username.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">E-posta</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="ornek@domain.com"
|
||||
{...register('email')}
|
||||
className={errors.email ? 'border-red-500' : ''}
|
||||
/>
|
||||
{errors.email && (
|
||||
<p className="text-sm text-red-500">{errors.email.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">Şifre</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
placeholder="********"
|
||||
{...register('password')}
|
||||
className={errors.password ? 'border-red-500' : ''}
|
||||
/>
|
||||
{errors.password && (
|
||||
<p className="text-sm text-red-500">{errors.password.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="confirmPassword">Şifre Tekrar</Label>
|
||||
<Input
|
||||
id="confirmPassword"
|
||||
type="password"
|
||||
placeholder="********"
|
||||
{...register('confirmPassword')}
|
||||
className={errors.confirmPassword ? 'border-red-500' : ''}
|
||||
/>
|
||||
{errors.confirmPassword && (
|
||||
<p className="text-sm text-red-500">{errors.confirmPassword.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{siteKey && (
|
||||
<div className="flex justify-center my-4">
|
||||
<Turnstile
|
||||
siteKey={siteKey}
|
||||
onSuccess={(token) => setTurnstileToken(token)}
|
||||
onError={() => setTurnstileToken(null)}
|
||||
onExpire={() => setTurnstileToken(null)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Button type="submit" className="w-full" disabled={isLoading}>
|
||||
{isLoading ? 'Kaydediliyor...' : 'Kayıt Ol'}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
<CardFooter className="justify-center">
|
||||
<p className="text-sm text-gray-500">
|
||||
Zaten hesabınız var mı?{' '}
|
||||
<Link href="/auth/login" className="text-blue-600 hover:underline">
|
||||
Giriş Yap
|
||||
</Link>
|
||||
</p>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default RegisterPage
|
||||
126
frontend/app/auth/verify-email/page.tsx
Normal file
126
frontend/app/auth/verify-email/page.tsx
Normal file
@@ -0,0 +1,126 @@
|
||||
"use client"
|
||||
|
||||
import React, { useEffect, useState, Suspense } from 'react'
|
||||
import { useSearchParams } from 'next/navigation'
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Loader2, CheckCircle2, XCircle, AlertCircle } from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
|
||||
const VerifyEmailContent = () => {
|
||||
const searchParams = useSearchParams()
|
||||
const token = searchParams.get('token')
|
||||
const [status, setStatus] = useState<'loading' | 'success' | 'error' | 'invalid'>(token ? 'loading' : 'invalid')
|
||||
const [message, setMessage] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
|
||||
const verifyEmail = async () => {
|
||||
try {
|
||||
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080'
|
||||
const response = await fetch(`${apiUrl}/api/v1/auth/verify-email?token=${token}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
// Backend responses might modify status
|
||||
const data = await response.json().catch(() => ({}))
|
||||
|
||||
if (response.ok) {
|
||||
setStatus('success')
|
||||
setMessage(data.message || 'E-posta adresiniz başarıyla doğrulandı.')
|
||||
} else {
|
||||
setStatus('error')
|
||||
setMessage(data.error || data.message || 'Doğrulama işlemi başarısız oldu. Link süresi dolmuş veya geçersiz olabilir.')
|
||||
}
|
||||
} catch {
|
||||
setStatus('error')
|
||||
setMessage('Sunucu ile iletişim kurulurken bir hata oluştu.')
|
||||
}
|
||||
}
|
||||
|
||||
verifyEmail()
|
||||
}, [token])
|
||||
|
||||
return (
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="space-y-1">
|
||||
<CardTitle className="text-2xl font-bold text-center">E-posta Doğrulama</CardTitle>
|
||||
<CardDescription className="text-center">
|
||||
Hesap aktivasyon durumu
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col items-center justify-center py-6 space-y-4">
|
||||
{status === 'loading' && (
|
||||
<>
|
||||
<Loader2 className="h-16 w-16 animate-spin text-blue-500" />
|
||||
<p className="text-gray-500">Doğrulanıyor, lütfen bekleyin...</p>
|
||||
</>
|
||||
)}
|
||||
|
||||
{status === 'success' && (
|
||||
<>
|
||||
<CheckCircle2 className="h-16 w-16 text-green-500" />
|
||||
<div className="text-center space-y-2">
|
||||
<h3 className="text-xl font-semibold text-green-600">Başarılı!</h3>
|
||||
<p className="text-gray-600">{message}</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{status === 'error' && (
|
||||
<>
|
||||
<XCircle className="h-16 w-16 text-red-500" />
|
||||
<div className="text-center space-y-2">
|
||||
<h3 className="text-xl font-semibold text-red-600">Hata!</h3>
|
||||
<p className="text-gray-600">{message}</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{status === 'invalid' && (
|
||||
<>
|
||||
<AlertCircle className="h-16 w-16 text-amber-500" />
|
||||
<div className="text-center space-y-2">
|
||||
<h3 className="text-xl font-semibold text-amber-600">Geçersiz Bağlantı</h3>
|
||||
<p className="text-gray-600">Doğrulama bağlantısı geçersiz veya eksik.</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
<CardFooter className="justify-center">
|
||||
{status === 'loading' ? (
|
||||
<Button disabled variant="outline" className="w-full">İşlem Sürüyor</Button>
|
||||
) : (
|
||||
<Link href="/auth/login" className="w-full">
|
||||
<Button className="w-full">
|
||||
{status === 'success' ? 'Giriş Yap' : 'Giriş Sayfasına Dön'}
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</CardFooter>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
const VerifyEmailPage = () => {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-gray-100 p-4 dark:bg-gray-900">
|
||||
<Suspense fallback={
|
||||
<div className="flex items-center space-x-2">
|
||||
<Loader2 className="h-6 w-6 animate-spin" />
|
||||
<span>Yükleniyor...</span>
|
||||
</div>
|
||||
}>
|
||||
<VerifyEmailContent />
|
||||
</Suspense>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default VerifyEmailPage
|
||||
Reference in New Issue
Block a user