/*pour modifier le mot de passe*/
        public ActionResult ConfirmUpdatePassword(Guid?token, UTILISATEURViewModel model)
        {
            if (Session["tokenPass"] != null)
            {
                token = (Guid)Session["tokenPass"];
                Session["tokenPass"] = null;
            }
            string        patternNoAplha    = "[\\W]";
            string        patternDigit      = "[0-9]";
            string        patternAlphaUpper = "[A-Z]";
            string        patternAlphaLower = "[a-z]";
            List <string> Error             = new List <string>();

            ViewBag.ErrorPassWord = "";

            if (model.userMotdepasse == "")
            {
                Error.Add("The password entered is empty.");
            }
            if (model.userMotdepasseConfirme == "")
            {
                Error.Add("The confirmation password is empty.");
            }
            if (model.userMotdepasse != model.userMotdepasseConfirme)
            {
                Error.Add("The password entered and the confirmation password are not the same.");
            }
            if ((model.userMotdepasse.ToString().Length >= 8) == false)
            {
                Error.Add("The password must contain at least 8 characters.");
            }
            if ((Regex.IsMatch(model.userMotdepasse.ToString(), patternNoAplha)) == false)
            {
                Error.Add("The password must contain at least 1 non-alphanumeric character.");
            }
            if ((Regex.IsMatch(model.userMotdepasse.ToString(), patternDigit)) == false)
            {
                Error.Add("The password must contain at least 1 digit character.");
            }
            if ((Regex.IsMatch(model.userMotdepasse.ToString(), patternAlphaUpper)) == false)
            {
                Error.Add("The password must contain at least 1 uppercase character.");
            }
            if ((Regex.IsMatch(model.userMotdepasse.ToString(), patternAlphaLower)) == false)
            {
                Error.Add("The password must contain at least 1 lowercase character.");
            }
            if (Error.Count != 0)
            {
                Session["tokenPass"]  = token;
                ViewBag.userId        = token;
                ViewBag.ErrorPassWord = Error;
                return(View("ErrrorForgotPassword"));
            }
            redactapplicationEntities db = new Models.redactapplicationEntities();
            UTILISATEUR utilisateur      = db.UTILISATEURs.SingleOrDefault(x => x.token == token);

            if (utilisateur == null)
            {
                Error = new List <string> {
                    "You are no longer allowed to change your password."
                };
                Session["tokenPass"]  = token;
                ViewBag.userId        = token;
                ViewBag.ErrorPassWord = Error;
                return(View("ErrrorForgotPassword"));
            }
            utilisateur.userMotdepasse = Encryptor.EncryptPass(model.userMotdepasse);
            utilisateur.token          = null;
            utilisateur.dateToken      = null;
            db.SaveChanges();
            return(RedirectToAction("UpdatePasswordSuccess", "Login"));
        }
        /*pour s'authentifier*/
        public ActionResult AuthentificationUser(UTILISATEURViewModel model)
        {
            try
            {
                string pwdCrypte             = model.userMotdepasse.Trim();
                redactapplicationEntities db = new Models.redactapplicationEntities();
                UTILISATEUR utilisateur      = null;
                if (model.saveOnComputer)
                {
                    utilisateur = db.UTILISATEURs.SingleOrDefault(x => x.userMail == model.userMail.Trim() && x.userMotdepasse == pwdCrypte);
                    if (utilisateur == null)
                    {
                        pwdCrypte = Encryptor.EncryptPass(pwdCrypte);
                    }
                }
                else
                {
                    pwdCrypte = Encryptor.EncryptPass(pwdCrypte);
                }


                utilisateur = db.UTILISATEURs.SingleOrDefault(x => x.userMail == model.userMail.Trim() && x.userMotdepasse == pwdCrypte);

                if (utilisateur != null)
                {
                    FormsAuthentication.SetAuthCookie(utilisateur.userId.ToString(), model.saveOnComputer);/*CREATION COOKIES*/
                    //Session["mail"] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(utilisateur.userMail);
                    //Session["pass"] = pwdCrypte;
                    Session["logoUrl"] = utilisateur.logoUrl;
                    Session["name"]    = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(utilisateur.userNom);
                    Session["surname"] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(utilisateur.userPrenom);
                    Session["role"]    = (new Utilisateurs()).GetUtilisateurRoleToString(utilisateur.userId);
                    if (model.saveOnComputer)
                    {
                        HttpCookie trigerAuths = new HttpCookie("trigerAuths");
                        trigerAuths.Values["username"] = utilisateur.userMail;
                        trigerAuths.Values["password"] = Encryptor.Decrypt(utilisateur.userMotdepasse);
                        trigerAuths.Expires            = DateTime.Now.AddDays(Convert.ToInt32(ConfigurationManager.AppSettings["cookiesValidity"]));
                        Response.Cookies.Add(trigerAuths);
                    }
                }
                else
                {
                    return(View("ErrorInvalidAccountOrPassword"));
                }
                var data = (new Utilisateurs()).GetUtilisateurRole(utilisateur.userId).ToList();
                {
                    if (data.Count == 1)
                    {
                        if (data[0] == 1)
                        {
                            return(RedirectToRoute("Home", new RouteValueDictionary
                            {
                                { "controller", "Contact" },
                                { "action", "ListeContact" }
                            }));
                        }
                        if (data[0] == 2)
                        {
                            return(RedirectToRoute("Home", new RouteValueDictionary {
                                { "controller", "Commandes" },
                                { "action", "ListCommandes" }
                            }));
                        }

                        if (data[0] == 4)
                        {
                            return(RedirectToRoute("Home", new RouteValueDictionary
                            {
                                { "controller", "Contact" },
                                { "action", "ListeContact" }
                            }));
                        }

                        if (data[0] == 3 || data[0] == 5)
                        {
                            return(RedirectToRoute("Home", new RouteValueDictionary {
                                { "controller", "Home" },
                                { "action", "ListeUser" },
                                { "numpage", 1 },
                                { "nbrow", 10 }
                            }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Debug.WriteLine("passe exception");
                return(View("ErrorException"));
            }
            Debug.WriteLine("passe error final");
            return(View("ErrorInvalidAccountOrPassword"));
        }