Compare commits
3 Commits
ba7082897f
...
auth
| Author | SHA1 | Date | |
|---|---|---|---|
| 0678fdcaa7 | |||
| 36f352de58 | |||
| 734dbfe24b |
10
.env.example
10
.env.example
@@ -2,3 +2,13 @@ DB_HOST=localhost
|
||||
DB_USER=root
|
||||
DB_PASSWORD=your_password
|
||||
DB_NAME=RXF
|
||||
|
||||
# Authentication Configuration
|
||||
# Format: username:passwordHash,username2:passwordHash2 (max 5 users)
|
||||
# Use 'node scripts/generate-password.js [password]' to generate hashes
|
||||
# Leave empty to disable authentication
|
||||
# Example hashes below (passwords: admin123, pass1):
|
||||
AUTH_USERS=admin:$2b$10$DKLO7uQPmdAw9Z64NChro.8mOsnqZQaRZjctWDojIkK926ROBVyJW,user1:$2b$10$K613Z70Hodr6xyEh10Mw2uoRZMV3U4LIB09929JUWw2n/pXKoUqaW
|
||||
|
||||
# Secret key for JWT session encryption (change in production!)
|
||||
AUTH_SECRET=your-super-secret-key-change-this-in-production
|
||||
|
||||
51
app/api/ausgaben/autocomplete/route.ts
Normal file
51
app/api/ausgaben/autocomplete/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getDbPool } from '@/lib/db';
|
||||
import { RowDataPacket } from 'mysql2';
|
||||
|
||||
// GET /api/ausgaben/autocomplete - Fetch unique Wo and Was values for autocomplete
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const typ = searchParams.get('typ');
|
||||
|
||||
const pool = getDbPool();
|
||||
|
||||
let query = 'SELECT DISTINCT Wo, Was FROM Ausgaben';
|
||||
const params: any[] = [];
|
||||
|
||||
if (typ !== null && typ !== undefined) {
|
||||
query += ' WHERE TYP = ?';
|
||||
params.push(parseInt(typ));
|
||||
}
|
||||
|
||||
query += ' ORDER BY Wo, Was';
|
||||
|
||||
const [rows] = await pool.query<RowDataPacket[]>(query, params);
|
||||
|
||||
// Extract unique Wo and Was values
|
||||
const woSet = new Set<string>();
|
||||
const wasSet = new Set<string>();
|
||||
|
||||
rows.forEach((row) => {
|
||||
if (row.Wo) woSet.add(row.Wo);
|
||||
if (row.Was) wasSet.add(row.Was);
|
||||
});
|
||||
|
||||
const wo = Array.from(woSet).sort();
|
||||
const was = Array.from(wasSet).sort();
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: {
|
||||
wo,
|
||||
was,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Database error:', error);
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Database error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,10 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
|
||||
const [year, setYear] = useState('');
|
||||
const [isLoadingStats, setIsLoadingStats] = useState(false);
|
||||
|
||||
// Autocomplete data
|
||||
const [autoCompleteWo, setAutoCompleteWo] = useState<string[]>([]);
|
||||
const [autoCompleteWas, setAutoCompleteWas] = useState<string[]>([]);
|
||||
|
||||
const fetchStats = useCallback(async (y: string, m: string) => {
|
||||
if (!y || !m) return;
|
||||
|
||||
@@ -49,6 +53,19 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
|
||||
}
|
||||
}, [typ]);
|
||||
|
||||
const fetchAutoComplete = useCallback(async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/ausgaben/autocomplete?typ=${typ}`);
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
setAutoCompleteWo(data.data.wo);
|
||||
setAutoCompleteWas(data.data.was);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching autocomplete data:', error);
|
||||
}
|
||||
}, [typ]);
|
||||
|
||||
// Initialize month/year on first load
|
||||
useEffect(() => {
|
||||
const now = new Date();
|
||||
@@ -65,6 +82,11 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
|
||||
}
|
||||
}, [month, year, typ, fetchStats]);
|
||||
|
||||
// Fetch autocomplete data when typ changes
|
||||
useEffect(() => {
|
||||
fetchAutoComplete();
|
||||
}, [typ, fetchAutoComplete]);
|
||||
|
||||
const handleMonthChange = (newMonth: string) => {
|
||||
setMonth(newMonth);
|
||||
};
|
||||
@@ -248,8 +270,14 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
|
||||
onChange={(e) => setFormData({ ...formData, Wo: e.target.value })}
|
||||
className="w-full px-2 py-1 text-base rounded border-2 border-gray-400 bg-white focus:border-blue-500 focus:outline-none"
|
||||
placeholder="Geschäft/Ort"
|
||||
list="wo-suggestions"
|
||||
required
|
||||
/>
|
||||
<datalist id="wo-suggestions">
|
||||
{autoCompleteWo.map((wo, index) => (
|
||||
<option key={index} value={wo} />
|
||||
))}
|
||||
</datalist>
|
||||
</td>
|
||||
<td className="p-2">
|
||||
<input
|
||||
@@ -258,8 +286,14 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
|
||||
onChange={(e) => setFormData({ ...formData, Was: e.target.value })}
|
||||
className="w-full px-2 py-1 text-base rounded border-2 border-gray-400 bg-white focus:border-blue-500 focus:outline-none"
|
||||
placeholder="Beschreibung"
|
||||
list="was-suggestions"
|
||||
required
|
||||
/>
|
||||
<datalist id="was-suggestions">
|
||||
{autoCompleteWas.map((was, index) => (
|
||||
<option key={index} value={was} />
|
||||
))}
|
||||
</datalist>
|
||||
</td>
|
||||
<td className="p-2 w-24">
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user