feat: add captcha functionality to PublicDashboardPage and OrganizationSettings components

This commit is contained in:
Usman Baig
2026-01-24 23:29:59 +01:00
parent 1d104f2d8f
commit 5bc9c12fba
4 changed files with 73 additions and 8 deletions

View File

@@ -11,7 +11,7 @@ import TopReferrers from '@/components/dashboard/TopReferrers'
import Locations from '@/components/dashboard/Locations'
import TechSpecs from '@/components/dashboard/TechSpecs'
import PerformanceStats from '@/components/dashboard/PerformanceStats'
import { Select, DatePicker as DatePickerModal } from '@ciphera-net/ui'
import { Select, DatePicker as DatePickerModal, Captcha } from '@ciphera-net/ui'
import { ZapIcon } from '@ciphera-net/ui'
// Helper to get date ranges
@@ -37,6 +37,11 @@ export default function PublicDashboardPage() {
const [password, setPassword] = useState(passwordParam || '')
const [isPasswordProtected, setIsPasswordProtected] = useState(false)
// Captcha State
const [captchaId, setCaptchaId] = useState('')
const [captchaSolution, setCaptchaSolution] = useState('')
const [captchaToken, setCaptchaToken] = useState('')
// Date range state
const [dateRange, setDateRange] = useState(getDateRange(30))
const [isDatePickerOpen, setIsDatePickerOpen] = useState(false)
@@ -69,16 +74,29 @@ export default function PublicDashboardPage() {
dateRange.end,
10,
dateRange.start === dateRange.end ? todayInterval : multiDayInterval,
password
password,
{
captcha_id: captchaId,
captcha_solution: captchaSolution,
captcha_token: captchaToken
}
)
setData(dashboardData)
setIsPasswordProtected(false)
// Reset captcha
setCaptchaId('')
setCaptchaSolution('')
setCaptchaToken('')
} catch (error: any) {
if ((error.status === 401 || error.response?.status === 401) && (error.data?.is_protected || error.response?.data?.is_protected)) {
setIsPasswordProtected(true)
if (password) {
toast.error('Invalid password')
toast.error('Invalid password or captcha')
// Reset captcha on failure
setCaptchaId('')
setCaptchaSolution('')
setCaptchaToken('')
}
} else if (error.status === 404 || error.response?.status === 404) {
toast.error('Site not found')
@@ -126,6 +144,16 @@ export default function PublicDashboardPage() {
autoFocus
/>
</div>
<div className="mb-4">
<Captcha
onVerify={(id, solution, token) => {
setCaptchaId(id)
setCaptchaSolution(solution)
setCaptchaToken(token || '')
}}
apiUrl={process.env.NEXT_PUBLIC_CAPTCHA_API_URL}
/>
</div>
<button
type="submit"
className="w-full btn-primary"