public ActionResult ServeurDomaine()
        {
            DomainServerConfiguration domainServerConfiguration = new DomainServerConfiguration();

            if (System.IO.File.Exists(Path.Combine(Server.MapPath("~").ToString(), "serveurDomaine.bin")))
            {
                domainServerConfiguration = DomainServerConfiguration.Charger(Path.Combine(Server.MapPath("~").ToString(), "serveurDomaine.bin"));
            }

            return(View(domainServerConfiguration));
        }
        public ActionResult ServeurDomaine(DomainServerConfiguration domainServerConfiguration)
        {
            if (!ModelState.IsValid)
            {
                return(View(domainServerConfiguration));
            }

            ViewBag.Information = "Les informations ont bien été sauvegardées.";

            domainServerConfiguration.Sauvegarder(Path.Combine(Server.MapPath("~").ToString(), "serveurDomaine.bin"));

            return(View());
        }
        public LDAPInformations()
        {
            InitializeComponent();

            domainServerConfiguration = new DomainServerConfiguration();

            DataContext = domainServerConfiguration;

            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "serveurDomaine.bin")))
            {
                DomainServerConfiguration informationsServeurDomaine = DomainServerConfiguration.Charger();
                IPAddressTextBox.Text = informationsServeurDomaine.IPAddress;
                DomainTextBox.Text    = informationsServeurDomaine.DomainName;
            }
        }
        private void ConnectionButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsValid())
            {
                try
                {
                    DomainServerConfiguration informationsServeurDomaine = DomainServerConfiguration.Charger();

                    string   ipDomaine = informationsServeurDomaine.IPAddress + "/";
                    string[] domaines  = informationsServeurDomaine.DomainName.Split('.');

                    foreach (string domaine in domaines)
                    {
                        ipDomaine += "DC=" + domaine + ",";
                    }

                    ipDomaine = ipDomaine.TrimEnd(',');

                    Ldap ldap = new Ldap(ipDomaine, UtilisateurWatermarkTextBox.Text, MotDePasseWatermarkTextBox.Password);

                    if (ldap.Authentification())
                    {
                        List <string> groups = ldap.GetGroup();

                        string group = groups[0];

                        teacher.FirstName = ldap.GetFirstName();
                        teacher.LastName  = ldap.GetLastName();
                        teacher.Subject   = Teacher.GetSubject(ldap.GetGroup()[0]);

                        if (teacher.Subject == "Anglais")
                        {
                            Ldap.IsAuthificated = true;
                            Close();
                        }
                        else
                        {
                            InformationsTextBlock.Text = "Vous ne disposez pas des autorisations nécessaires pour continuer. Veuillez vérifier vos identifants avant de réessayer.";

                            teacher.Save(Path.Combine(Directory.GetCurrentDirectory(), teacher.FirstName + ".credential"));
                        }
                    }
                    else
                    {
                        InformationsTextBlock.Text = "Nom d'utilisateur ou mot de passe invalide. Veuillez vérifier vos identifants avant de réessayer.";

                        teacher.Save(Path.Combine(Directory.GetCurrentDirectory(), teacher.FirstName + ".credential"));
                    }
                }
                catch (Exception ex)
                {
                    InformationsTextBlock.Text = "L'erreur suivante s'est produite : " + ex.Message;

                    using (FileStream fileStream = File.Create(Path.Combine(Directory.GetCurrentDirectory(), "AuthentificationErreur" + DateTime.Now + ".txt")))
                    {
                        byte[] info = new UTF8Encoding(true).GetBytes("Message : " + ex.Message + Environment.NewLine + ex.StackTrace);
                        fileStream.Write(info, 0, info.Length);
                    }

                    teacher.Save(Path.Combine(Directory.GetCurrentDirectory(), teacher.FirstName + ".credential"));
                }
            }
        }
Esempio n. 5
0
        public SignInStatus CheckCredential(LoginViewModel model)
        {
            if (!System.IO.File.Exists(Path.Combine(Server.MapPath("~"), "users.local.credential")) && model.Username.Equals("Administrateur", StringComparison.CurrentCultureIgnoreCase) && model.Password == "admin")
            {
                FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);

                return(SignInStatus.ChangePasswordFirstUse);
            }
            else if (System.IO.File.Exists(Path.Combine(Server.MapPath("~"), "users.local.credential")))
            {
                Users users = Users.Load(Path.Combine(Server.MapPath("~").ToString(), "users.local.credential"));

                foreach (User user in users)
                {
                    if (user.Username.Equals(model.Username, StringComparison.CurrentCultureIgnoreCase) && user.Password == Hash.SHA512(model.Password))
                    {
                        FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);

                        return(SignInStatus.AdminAccount);
                    }
                }
            }

            if (System.IO.File.Exists(Path.Combine(Server.MapPath("~"), "serveurDomaine.bin")))
            {
                DomainServerConfiguration informationsServeurDomaine = DomainServerConfiguration.Charger(Path.Combine(Server.MapPath("~").ToString(), "serveurDomaine.bin"));

                string   ipDomaine = informationsServeurDomaine.IPAddress + "/";
                string[] domaines  = informationsServeurDomaine.DomainName.Split('.');

                foreach (string domaine in domaines)
                {
                    ipDomaine += "DC=" + domaine + ",";
                }

                ipDomaine = ipDomaine.TrimEnd(',');

                Ldap ldap = new Ldap(ipDomaine, model.Username, model.Password);

                if (ldap.Authentification())
                {
                    Session["User"] = new User()
                    {
                        FirstName = ldap.GetFirstName(), Groups = ldap.GetGroup(), LastName = ldap.GetLastName(), Username = model.Username
                    };

                    //if ((Session["User"] as User).FirstName == "")
                    FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);

                    /*else
                     *  FormsAuthentication.SetAuthCookie((Session["User"] as User).FirstName, false);*/

                    if (!Directory.Exists(Path.Combine(Server.MapPath("~"), "credential")))
                    {
                        Directory.CreateDirectory(Path.Combine(Server.MapPath("~"), "credential"));
                    }

                    new Users {
                        (Session["User"] as User)
                    }.Save(Path.Combine(Server.MapPath("~"), "credential", model.Username + ".credential"));

                    return(SignInStatus.Success);
                }
            }

            return(SignInStatus.Failure);
        }