Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

feat(webui): open account page to OAuth users, edit display name, consistent forms

Sergey Kozyrenko273592ec29bb
diff --git a/frontend/src/components/layouts/main-sidebar.tsx b/frontend/src/components/layouts/main-sidebar.tsx
index 54e28a0b..b12b0fa1 100644
--- a/frontend/src/components/layouts/main-sidebar.tsx
+++ b/frontend/src/components/layouts/main-sidebar.tsx
@@ -358,7 +358,7 @@ export function MainSidebar() {
<DropdownMenuItem asChild>
<Link to="/settings/account">
<UserIcon className="mr-2 size-4" />
- My Profile
+ Profile
</Link>
</DropdownMenuItem>
</>
diff --git a/frontend/src/components/layouts/settings-layout.tsx b/frontend/src/components/layouts/settings-layout.tsx
index 5d584264..28a34274 100644
--- a/frontend/src/components/layouts/settings-layout.tsx
+++ b/frontend/src/components/layouts/settings-layout.tsx
@@ -17,12 +17,10 @@ import {
SidebarProvider,
SidebarTrigger,
} from '@/components/ui/sidebar';
-import { useUser } from '@/providers/user-provider';
export interface MenuItem {
icon?: React.ReactNode;
id: string;
- isLocalOnly?: boolean;
path: string;
title: string;
}
@@ -35,7 +33,6 @@ const menuItems: readonly MenuItem[] = [
{
icon: <User className="size-4" />,
id: 'account',
- isLocalOnly: true,
path: '/settings/account',
title: 'Account',
},
@@ -116,10 +113,6 @@ function SettingsLayout() {
}
function SettingsSidebar() {
- const { authInfo } = useUser();
- const isLocal = authInfo?.user?.type === 'local';
- const visibleItems = menuItems.filter((item) => !item.isLocalOnly || isLocal);
-
return (
<Sidebar collapsible="icon">
<SidebarHeader>
@@ -138,7 +131,7 @@ function SettingsSidebar() {
<SidebarGroup>
<SidebarGroupContent>
<SidebarMenu>
- {visibleItems.map((item) => (
+ {menuItems.map((item) => (
<SettingsSidebarMenuItem
item={item}
key={item.id}
diff --git a/frontend/src/features/authentication/email-change-form.tsx b/frontend/src/features/authentication/email-change-form.tsx
index d6dedcb6..10ed0aaa 100644
--- a/frontend/src/features/authentication/email-change-form.tsx
+++ b/frontend/src/features/authentication/email-change-form.tsx
@@ -9,7 +9,6 @@ import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '
import { FormSubmitButton } from '@/components/ui/form-submit-button';
import { Input } from '@/components/ui/input';
import { InputPassword } from '@/components/ui/input-password';
-import { Label } from '@/components/ui/label';
import { api, getApiErrorCode, getApiErrorMessage } from '@/lib/axios';
import { useUser } from '@/providers/user-provider';
@@ -40,8 +39,7 @@ type EmailChangeFormValues = z.infer<typeof emailChangeSchema>;
export function EmailChangeForm({ isModal = true, onCancel, onSuccess }: EmailChangeFormProps) {
const [error, setError] = useState<null | string>(null);
- const { authInfo, refreshAuthInfo } = useUser();
- const currentEmail = authInfo?.user?.mail || '';
+ const { refreshAuthInfo } = useUser();
const form = useForm<EmailChangeFormValues>({
defaultValues: {
@@ -78,26 +76,16 @@ export function EmailChangeForm({ isModal = true, onCancel, onSuccess }: EmailCh
className="flex flex-col gap-4"
onSubmit={form.handleSubmit(handleSubmit)}
>
- <div className="flex flex-col gap-2">
- <Label htmlFor="current-email">Current Email</Label>
- <Input
- disabled
- id="current-email"
- value={currentEmail}
- />
- </div>
-
<FormField
control={form.control}
- name="newEmail"
+ name="currentPassword"
render={({ field }) => (
<FormItem>
- <FormLabel>New Email</FormLabel>
+ <FormLabel>Current Password</FormLabel>
<FormControl>
- <Input
+ <InputPassword
{...field}
- placeholder="Enter new email address"
- type="email"
+ placeholder="Enter your current password"
/>
</FormControl>
<FormMessage />
@@ -107,14 +95,15 @@ export function EmailChangeForm({ isModal = true, onCancel, onSuccess }: EmailCh
<FormField
control={form.control}
- name="currentPassword"
+ name="newEmail"
render={({ field }) => (
<FormItem>
- <FormLabel>Current Password</FormLabel>
+ <FormLabel>New Email</FormLabel>
<FormControl>
- <InputPassword
+ <Input
{...field}
- placeholder="Enter your current password to confirm"
+ placeholder="Enter your new email address"
+ type="email"
/>
</FormControl>
<FormMessage />
@@ -128,13 +117,14 @@ export function EmailChangeForm({ isModal = true, onCancel, onSuccess }: EmailCh
{isModal && (
<Button
onClick={onCancel}
+ size="sm"
type="button"
variant="outline"
>
Cancel
</Button>
)}
- <FormSubmitButton>
+ <FormSubmitButton size="sm">
<span>Update Email</span>
</FormSubmitButton>
</div>
diff --git a/frontend/src/features/authentication/name-change-form.tsx b/frontend/src/features/authentication/name-change-form.tsx
new file mode 100644
index 00000000..1a87e03d
--- /dev/null
+++ b/frontend/src/features/authentication/name-change-form.tsx
@@ -0,0 +1,107 @@
+import { zodResolver } from '@hookform/resolvers/zod';
+import { useState } from 'react';
+import { useForm } from 'react-hook-form';
+import { toast } from 'sonner';
+import * as z from 'zod';
+
+import { Button } from '@/components/ui/button';
+import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
+import { FormSubmitButton } from '@/components/ui/form-submit-button';
+import { Input } from '@/components/ui/input';
+import { api, getApiErrorCode, getApiErrorMessage } from '@/lib/axios';
+import { useUser } from '@/providers/user-provider';
+
+const nameChangeSchema = z.object({
+ name: z
+ .string()
+ .trim()
+ .min(1, { message: 'Name is required' })
+ .max(70, { message: 'Name must not exceed 70 characters' }),
+});
+
+const ERROR_BY_CODE: Record<string, string> = {
+ AuthRequired: 'Authentication required',
+ 'Users.ChangeNameCurrentUser.InvalidName': 'New name does not meet requirements',
+ 'Users.NotFound': 'User not found',
+};
+
+interface NameChangeFormProps {
+ isModal?: boolean;
+ onCancel?: () => void;
+ onSuccess?: () => void;
+}
+
+type NameChangeFormValues = z.infer<typeof nameChangeSchema>;
+
+export function NameChangeForm({ isModal = true, onCancel, onSuccess }: NameChangeFormProps) {
+ const [error, setError] = useState<null | string>(null);
+ const { authInfo, refreshAuthInfo } = useUser();
+
+ const form = useForm<NameChangeFormValues>({
+ defaultValues: {
+ name: authInfo?.user?.name ?? '',
+ },
+ resolver: zodResolver(nameChangeSchema),
+ });
+
+ const handleSubmit = async (values: NameChangeFormValues) => {
+ setError(null);
+
+ try {
+ await api.put('/user/name', { name: values.name });
+
+ toast.success('Name successfully updated');
+
+ await refreshAuthInfo();
+
+ onSuccess?.();
+ } catch (err: unknown) {
+ const code = getApiErrorCode(err);
+ setError((code && ERROR_BY_CODE[code]) ?? getApiErrorMessage(err, 'Failed to update name'));
+ }
+ };
+
+ return (
+ <Form {...form}>
+ <form
+ className="flex flex-col gap-4"
+ onSubmit={form.handleSubmit(handleSubmit)}
+ >
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Display name</FormLabel>
+ <FormControl>
+ <Input
+ {...field}
+ placeholder="Enter your display name"
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {error && <div className="text-destructive text-sm">{error}</div>}
+
+ <div className="flex justify-end gap-2 pt-2">
+ {isModal && (
+ <Button
+ onClick={onCancel}
+ size="sm"
+ type="button"
+ variant="outline"
+ >
+ Cancel
+ </Button>
+ )}
+ <FormSubmitButton size="sm">
+ <span>Update Name</span>
+ </FormSubmitButton>
+ </div>
+ </form>
+ </Form>
+ );
+}
diff --git a/frontend/src/features/authentication/password-change-form.tsx b/frontend/src/features/authentication/password-change-form.tsx
index 3ab553ce..b81c4b46 100644
--- a/frontend/src/features/authentication/password-change-form.tsx
+++ b/frontend/src/features/authentication/password-change-form.tsx
@@ -135,7 +135,7 @@ export function PasswordChangeForm({
<FormControl>
<InputPassword
{...field}
- placeholder="Enter new password"
+ placeholder="Enter your new password"
/>
</FormControl>
<FormDescription className="text-xs">
@@ -156,7 +156,7 @@ export function PasswordChangeForm({
<FormControl>
<InputPassword
{...field}
- placeholder="Confirm new password"
+ placeholder="Confirm your new password"
/>
</FormControl>
<FormMessage />
@@ -171,6 +171,7 @@ export function PasswordChangeForm({
<Button
className="text-muted-foreground"
onClick={onSkip}
+ size="sm"
type="button"
variant="ghost"
>
@@ -180,13 +181,14 @@ export function PasswordChangeForm({
{isModal && (
<Button
onClick={onCancel}
+ size="sm"
type="button"
variant="outline"
>
Cancel
</Button>
)}
- <FormSubmitButton>
+ <FormSubmitButton size="sm">
<span>Update Password</span>
</FormSubmitButton>
</div>
diff --git a/frontend/src/models/user.ts b/frontend/src/models/user.ts
index 75306bbf..42f41994 100644
--- a/frontend/src/models/user.ts
+++ b/frontend/src/models/user.ts
@@ -5,7 +5,7 @@ export interface User {
mail: string;
name: string;
password_change_required: boolean;
- provide: string;
+ provider?: string;
role_id: number;
status: 'active' | 'blocked' | 'created';
type: 'local' | 'oauth';
diff --git a/frontend/src/pages/settings/settings-account.tsx b/frontend/src/pages/settings/settings-account.tsx
index 6b82e910..973b3b3b 100644
--- a/frontend/src/pages/settings/settings-account.tsx
+++ b/frontend/src/pages/settings/settings-account.tsx
@@ -1,32 +1,33 @@
import { format } from 'date-fns';
import { enUS } from 'date-fns/locale';
-import { Lock, Mail } from 'lucide-react';
+import { Lock, Mail, User } from 'lucide-react';
import { useState } from 'react';
-import { Navigate } from 'react-router-dom';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { EmailChangeForm } from '@/features/authentication/email-change-form';
+import { NameChangeForm } from '@/features/authentication/name-change-form';
import { PasswordChangeForm } from '@/features/authentication/password-change-form';
import { useUser } from '@/providers/user-provider';
-type EditingSection = 'email' | 'password' | null;
+type EditingSection = 'email' | 'name' | 'password' | null;
+
+const PROVIDER_LABELS: Record<string, string> = {
+ github: 'GitHub',
+ google: 'Google',
+};
function SettingsAccount() {
const { authInfo } = useUser();
const user = authInfo?.user;
const [editing, setEditing] = useState<EditingSection>(null);
- if (user?.type !== 'local') {
- return (
- <Navigate
- replace
- to="/settings/providers"
- />
- );
+ if (!user) {
+ return null;
}
+ const isLocal = user.type === 'local';
const stopEditing = () => setEditing(null);
const displayName = user.name?.trim() || user.mail;
@@ -34,6 +35,11 @@ function SettingsAccount() {
const createdAt = user.created_at ? new Date(user.created_at) : null;
const memberSince =
createdAt && !Number.isNaN(createdAt.getTime()) ? format(createdAt, 'MMMM yyyy', { locale: enUS }) : null;
+ const accountLabel = isLocal
+ ? 'Local account'
+ : user.provider
+ ? (PROVIDER_LABELS[user.provider] ?? user.provider)
+ : 'OAuth account';
return (
<div className="mx-auto flex max-w-2xl flex-col gap-4">
@@ -46,19 +52,19 @@ function SettingsAccount() {
<CardTitle className="truncate">{displayName}</CardTitle>
{memberSince && <CardDescription>Member since {memberSince}</CardDescription>}
</div>
- <Badge variant="secondary">Local account</Badge>
+ <Badge variant="secondary">{accountLabel}</Badge>
</CardHeader>
</Card>
<Card>
<CardHeader className="flex-row items-start justify-between gap-4">
<div className="grid gap-1.5">
- <CardTitle>Email address</CardTitle>
- <CardDescription>The email you use to sign in.</CardDescription>
+ <CardTitle>Display name</CardTitle>
+ <CardDescription>The name shown across the app.</CardDescription>
</div>
- {editing !== 'email' && (
+ {editing !== 'name' && (
<Button
- onClick={() => setEditing('email')}
+ onClick={() => setEditing('name')}
size="sm"
variant="outline"
>
@@ -67,15 +73,15 @@ function SettingsAccount() {
)}
</CardHeader>
<CardContent>
- {editing === 'email' ? (
- <EmailChangeForm
+ {editing === 'name' ? (
+ <NameChangeForm
onCancel={stopEditing}
onSuccess={stopEditing}
/>
) : (
<div className="text-muted-foreground flex items-center gap-2 text-sm">
- <Mail className="size-4 shrink-0" />
- <span className="truncate">{user.mail}</span>
+ <User className="size-4 shrink-0" />
+ <span className="truncate">{displayName}</span>
</div>
)}
</CardContent>
@@ -84,12 +90,14 @@ function SettingsAccount() {
<Card>
<CardHeader className="flex-row items-start justify-between gap-4">
<div className="grid gap-1.5">
- <CardTitle>Password</CardTitle>
- <CardDescription>Change your account password.</CardDescription>
+ <CardTitle>Email address</CardTitle>
+ <CardDescription>
+ {isLocal ? 'The email you use to sign in.' : `Linked from your ${accountLabel}.`}
+ </CardDescription>
</div>
- {editing !== 'password' && (
+ {isLocal && editing !== 'email' && (
<Button
- onClick={() => setEditing('password')}
+ onClick={() => setEditing('email')}
size="sm"
variant="outline"
>
@@ -98,19 +106,52 @@ function SettingsAccount() {
)}
</CardHeader>
<CardContent>
- {editing === 'password' ? (
- <PasswordChangeForm
+ {isLocal && editing === 'email' ? (
+ <EmailChangeForm
onCancel={stopEditing}
onSuccess={stopEditing}
/>
) : (
<div className="text-muted-foreground flex items-center gap-2 text-sm">
- <Lock className="size-4 shrink-0" />
- <span>••••••••••••</span>
+ <Mail className="size-4 shrink-0" />
+ <span className="truncate">{user.mail}</span>
</div>
)}
</CardContent>
</Card>
+
+ {isLocal && (
+ <Card>
+ <CardHeader className="flex-row items-start justify-between gap-4">
+ <div className="grid gap-1.5">
+ <CardTitle>Password</CardTitle>
+ <CardDescription>Change your account password.</CardDescription>
+ </div>
+ {editing !== 'password' && (
+ <Button
+ onClick={() => setEditing('password')}
+ size="sm"
+ variant="outline"
+ >
+ Change
+ </Button>
+ )}
+ </CardHeader>
+ <CardContent>
+ {editing === 'password' ? (
+ <PasswordChangeForm
+ onCancel={stopEditing}
+ onSuccess={stopEditing}
+ />
+ ) : (
+ <div className="text-muted-foreground flex items-center gap-2 text-sm">
+ <Lock className="size-4 shrink-0" />
+ <span>••••••••••••</span>
+ </div>
+ )}
+ </CardContent>
+ </Card>
+ )}
</div>
);
}