modification requirements.txt
Build and Push Docker Image / build-and-push (push) Successful in 1m17s
Build and Push Docker Image / build-and-push (push) Successful in 1m17s
This commit is contained in:
1 parent
8d00a751af
commit
b1983077cb
4 files changed
+144
-4
No files matched your search
+33
-3
@@ -6,8 +6,8 @@ import os
|
||||
# Importation de nos modules locaux
|
||||
from .database import engine, Base, get_db
|
||||
from .models import User
|
||||
from .auth import get_password_hash, generate_totp_secret, get_totp_uri
|
||||
from .schemas import AdminCreate
|
||||
from .auth import get_password_hash, generate_totp_secret, get_totp_uri, verify_password, verify_totp
|
||||
from .schemas import AdminCreate, LoginRequest
|
||||
|
||||
# Création des tables dans la base de données
|
||||
Base.metadata.create_all(bind=engine)
|
||||
@@ -43,7 +43,12 @@ def login_page(db: Session = Depends(get_db)):
|
||||
"""Affiche la page de connexion sécurisée."""
|
||||
if is_setup_required(db):
|
||||
return RedirectResponse(url="/setup")
|
||||
return {"message": "Page de connexion (Interface Vue.js à venir)."}
|
||||
|
||||
frontend_path = os.path.join(os.getcwd(), "frontend", "login.html")
|
||||
if not os.path.exists(frontend_path):
|
||||
raise HTTPException(status_code=404, detail="Interface de connexion introuvable.")
|
||||
|
||||
return FileResponse(frontend_path)
|
||||
|
||||
@app.post("/api/setup")
|
||||
def create_admin(admin_data: AdminCreate, db: Session = Depends(get_db)):
|
||||
@@ -78,3 +83,28 @@ def create_admin(admin_data: AdminCreate, db: Session = Depends(get_db)):
|
||||
"totp_secret": totp_secret,
|
||||
"totp_uri": totp_uri
|
||||
}
|
||||
|
||||
@app.post("/api/login")
|
||||
def login(login_data: LoginRequest, db: Session = Depends(get_db)):
|
||||
"""Vérifie les identifiants et le code 2FA."""
|
||||
user = db.query(User).filter(User.username == login_data.username).first()
|
||||
|
||||
# Vérification de l'utilisateur et du mot de passe
|
||||
if not user or not verify_password(login_data.password, user.hashed_password):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Nom d'utilisateur ou mot de passe incorrect."
|
||||
)
|
||||
|
||||
# Vérification du code 2FA
|
||||
if not verify_totp(user.totp_secret, login_data.totp_code):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Code 2FA invalide."
|
||||
)
|
||||
|
||||
return {"message": "Connexion réussie"}
|
||||
|
||||
@app.get("/dashboard")
|
||||
def dashboard():
|
||||
return {"message": "Bienvenue sur le tableau de bord de l'Orchestrateur AETHAS38 ! (Interface à venir)"}
|
||||
@@ -4,3 +4,9 @@ class AdminCreate(BaseModel):
|
||||
email: EmailStr
|
||||
username: str
|
||||
password: str
|
||||
|
||||
# NOUVEAU : Schéma pour la connexion
|
||||
class LoginRequest(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
totp_code: str
|
||||
@@ -0,0 +1,104 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" class="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>AETHAS38 - Connexion</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script>
|
||||
tailwind.config = {
|
||||
darkMode: 'class',
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
aethas: {
|
||||
dark: '#0f172a', panel: '#1e293b', cyan: '#06b6d4', purple: '#a855f7'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
||||
<style>
|
||||
body { background-color: #0f172a; color: #f8fafc; font-family: 'Inter', sans-serif; }
|
||||
.glass-panel {
|
||||
background: rgba(30, 41, 59, 0.7); backdrop-filter: blur(10px);
|
||||
border: 1px solid rgba(6, 182, 212, 0.2); box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.neon-text { background: linear-gradient(to right, #06b6d4, #a855f7); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="flex items-center justify-center min-h-screen p-4 sm:p-8">
|
||||
|
||||
<div id="app" class="w-full max-w-md transition-all duration-500">
|
||||
<div class="text-center mb-8">
|
||||
<img src="https://via.placeholder.com/150x150/0f172a/06b6d4?text=Logo+A38" alt="AETHAS38 Logo" class="w-24 h-24 mx-auto mb-4 rounded-full border-2 border-aethas-cyan shadow-[0_0_15px_rgba(6,182,212,0.5)]">
|
||||
<h1 class="text-3xl font-bold tracking-wider neon-text">AETHAS38</h1>
|
||||
<p class="text-gray-400 text-sm mt-2">Authentification Sécurisée</p>
|
||||
</div>
|
||||
|
||||
<div class="glass-panel rounded-2xl p-6 sm:p-8">
|
||||
<form @submit.prevent="submitLogin" class="space-y-5">
|
||||
<div v-if="errorMessage" class="p-3 bg-red-900/50 border border-red-500 rounded text-red-200 text-sm text-center">
|
||||
{{ errorMessage }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Nom d'utilisateur</label>
|
||||
<input v-model="form.username" type="text" required class="w-full bg-aethas-dark border border-gray-600 rounded-lg px-4 py-2.5 focus:outline-none focus:border-aethas-cyan focus:ring-1 focus:ring-aethas-cyan transition-colors" placeholder="Admin">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Mot de passe</label>
|
||||
<input v-model="form.password" type="password" required class="w-full bg-aethas-dark border border-gray-600 rounded-lg px-4 py-2.5 focus:outline-none focus:border-aethas-cyan focus:ring-1 focus:ring-aethas-cyan transition-colors" placeholder="••••••••">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Code 2FA (6 chiffres)</label>
|
||||
<input v-model="form.totp_code" type="text" inputmode="numeric" pattern="[0-9]{6}" required maxlength="6" class="w-full bg-aethas-dark border border-gray-600 rounded-lg px-4 py-2.5 focus:outline-none focus:border-aethas-cyan focus:ring-1 focus:ring-aethas-cyan transition-colors text-center tracking-widest text-lg" placeholder="123456">
|
||||
</div>
|
||||
|
||||
<button type="submit" :disabled="isSubmitting" class="w-full bg-gradient-to-r from-aethas-cyan to-aethas-purple hover:opacity-90 text-white font-semibold py-3 px-4 rounded-lg transition-all shadow-[0_0_10px_rgba(168,85,247,0.4)] flex justify-center items-center mt-6">
|
||||
<span v-if="isSubmitting">Vérification...</span>
|
||||
<span v-else>Se connecter</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const { createApp, reactive, ref } = Vue;
|
||||
createApp({
|
||||
setup() {
|
||||
const form = reactive({ username: '', password: '', totp_code: '' });
|
||||
const isSubmitting = ref(false);
|
||||
const errorMessage = ref('');
|
||||
|
||||
const submitLogin = async () => {
|
||||
isSubmitting.value = true;
|
||||
errorMessage.value = '';
|
||||
try {
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form)
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.detail || "Erreur de connexion");
|
||||
|
||||
// Redirection vers le tableau de bord une fois connecté
|
||||
window.location.href = "/dashboard";
|
||||
} catch (error) {
|
||||
errorMessage.value = error.message;
|
||||
} finally {
|
||||
isSubmitting.value = false;
|
||||
}
|
||||
};
|
||||
return { form, isSubmitting, errorMessage, submitLogin };
|
||||
}
|
||||
}).mount('#app');
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
fastapi
|
||||
uvicorn
|
||||
sqlalchemy
|
||||
psycopg2-binary
|
||||
psycopg[binary]
|
||||
requests
|
||||
pyotp
|
||||
qrcode
|
||||
|
||||
Reference in new issue
Block a user