/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package testForms;

import bdd.SalarieMySQL;
import jakarta.servlet.http.HttpServletRequest;
import javabeans.User;

/**
 *
 * @author famille Thevenot
 */
public class AuthentifForm {
    private String resultat;

    public String getResultat() {
        return resultat;
    }

    public void setResultat(String resultat) {
        this.resultat = resultat;
    }
    
    public boolean existeUser(HttpServletRequest request)
    {
        SalarieMySQL userSaisi = new SalarieMySQL();
        //test du compte admin
        User leSalarie=new User();
        leSalarie=userSaisi.lireSalarie(request.getParameter("ztPseudo"),request.getParameter("ztMDP"));
        if (leSalarie.getId()>-1){
            return true; 
        }
        else {
                return false;
            }
    }
    
    
    public boolean controlerAdmin(HttpServletRequest request)
    {
        SalarieMySQL userSaisi = new SalarieMySQL();
        //test du compte admin
        User leSalarie=new User();;
        leSalarie=userSaisi.lireSalarie(request.getParameter("ztPseudo"),request.getParameter("ztMDP"));
        
        boolean isAdmin = leSalarie.getRole();
        
        //mise à jour de l'attribut resultat
        setResultat(isAdmin?"Vous êtes administrateur":"Vous n'êtes pas administrateur");
        return isAdmin;
    }

    
}
