Add admin user management in settings panel (username and password change)
This commit is contained in:
@@ -30,13 +30,21 @@ function Settings() {
|
||||
ollama_server_url: '',
|
||||
ollama_model: '',
|
||||
});
|
||||
const [adminInfo, setAdminInfo] = useState({
|
||||
username: '',
|
||||
current_password: '',
|
||||
new_password: '',
|
||||
confirm_password: '',
|
||||
});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [testLoading, setTestLoading] = useState({ mail: false, telegram: false, ollama: false });
|
||||
const [alerts, setAlerts] = useState({ mail: null, telegram: null, ollama: null });
|
||||
const [alerts, setAlerts] = useState({ mail: null, telegram: null, ollama: null, admin: null });
|
||||
const [ollamaModels, setOllamaModels] = useState([]);
|
||||
const [adminSaving, setAdminSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadSettings();
|
||||
loadAdminInfo();
|
||||
}, []);
|
||||
|
||||
const loadSettings = async () => {
|
||||
@@ -73,6 +81,24 @@ function Settings() {
|
||||
}
|
||||
};
|
||||
|
||||
const loadAdminInfo = async () => {
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/api/settings/admin`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
if (response.data.success && response.data.data) {
|
||||
setAdminInfo({
|
||||
username: response.data.data.username || '',
|
||||
current_password: '',
|
||||
new_password: '',
|
||||
confirm_password: '',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load admin info:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
await Promise.all([
|
||||
@@ -189,6 +215,60 @@ function Settings() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveAdmin = async () => {
|
||||
setAdminSaving(true);
|
||||
setAlerts({ ...alerts, admin: null });
|
||||
|
||||
try {
|
||||
const updateData = {};
|
||||
|
||||
// Only include fields that are being changed
|
||||
if (adminInfo.username && adminInfo.username.trim() !== '') {
|
||||
updateData.username = adminInfo.username.trim();
|
||||
}
|
||||
|
||||
if (adminInfo.new_password) {
|
||||
updateData.new_password = adminInfo.new_password;
|
||||
updateData.confirm_password = adminInfo.confirm_password;
|
||||
updateData.current_password = adminInfo.current_password;
|
||||
}
|
||||
|
||||
const response = await axios.put(
|
||||
`${API_URL}/api/settings/admin`,
|
||||
updateData,
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
if (response.data.success) {
|
||||
setAlerts({
|
||||
...alerts,
|
||||
admin: { severity: 'success', message: response.data.message || 'Admin bilgileri güncellendi' },
|
||||
});
|
||||
|
||||
// Clear password fields
|
||||
setAdminInfo({
|
||||
...adminInfo,
|
||||
current_password: '',
|
||||
new_password: '',
|
||||
confirm_password: '',
|
||||
});
|
||||
|
||||
// Reload admin info to get updated username
|
||||
await loadAdminInfo();
|
||||
}
|
||||
} catch (error) {
|
||||
setAlerts({
|
||||
...alerts,
|
||||
admin: {
|
||||
severity: 'error',
|
||||
message: error.response?.data?.error || 'Admin bilgileri güncellenemedi',
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
setAdminSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Box display="flex" justifyContent="center" alignItems="center" minHeight="400px">
|
||||
@@ -389,6 +469,87 @@ function Settings() {
|
||||
</Paper>
|
||||
</Grid>
|
||||
|
||||
{/* Admin User Settings */}
|
||||
<Grid size={12}>
|
||||
<Paper sx={{ p: 3 }}>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
🔐 Admin Kullanıcı Bilgileri
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary" gutterBottom>
|
||||
Kullanıcı adı ve şifrenizi değiştirebilirsiniz
|
||||
</Typography>
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Kullanıcı Adı"
|
||||
value={adminInfo.username}
|
||||
onChange={(e) =>
|
||||
setAdminInfo({ ...adminInfo, username: e.target.value })
|
||||
}
|
||||
helperText="En az 3 karakter olmalıdır"
|
||||
/>
|
||||
|
||||
<Divider sx={{ my: 2 }} />
|
||||
<Typography variant="subtitle2" gutterBottom>
|
||||
Şifre Değiştir (Opsiyonel)
|
||||
</Typography>
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Mevcut Şifre"
|
||||
type="password"
|
||||
value={adminInfo.current_password}
|
||||
onChange={(e) =>
|
||||
setAdminInfo({ ...adminInfo, current_password: e.target.value })
|
||||
}
|
||||
helperText="Yeni şifre belirlemek için mevcut şifrenizi girin"
|
||||
/>
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Yeni Şifre"
|
||||
type="password"
|
||||
value={adminInfo.new_password}
|
||||
onChange={(e) =>
|
||||
setAdminInfo({ ...adminInfo, new_password: e.target.value })
|
||||
}
|
||||
helperText="En az 8 karakter olmalıdır"
|
||||
/>
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Yeni Şifre (Tekrar)"
|
||||
type="password"
|
||||
value={adminInfo.confirm_password}
|
||||
onChange={(e) =>
|
||||
setAdminInfo({ ...adminInfo, confirm_password: e.target.value })
|
||||
}
|
||||
helperText="Yeni şifreyi tekrar girin"
|
||||
/>
|
||||
|
||||
{alerts.admin && (
|
||||
<Alert severity={alerts.admin.severity} sx={{ mt: 2 }}>
|
||||
{alerts.admin.message}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Box mt={2}>
|
||||
<Button
|
||||
variant="contained"
|
||||
startIcon={adminSaving ? <CircularProgress size={20} /> : <Save />}
|
||||
onClick={handleSaveAdmin}
|
||||
disabled={adminSaving}
|
||||
>
|
||||
{adminSaving ? 'Kaydediliyor...' : 'Admin Bilgilerini Kaydet'}
|
||||
</Button>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Grid>
|
||||
|
||||
{/* Ollama Settings */}
|
||||
<Grid size={12}>
|
||||
<Paper sx={{ p: 3 }}>
|
||||
|
||||
Reference in New Issue
Block a user