/*pour s'authentifier*/ public ActionResult AuthentificationUser(UTILISATEURViewModel model) { try { string pwdCrypte = model.userMotdepasse; redactapplicationEntities db = new Models.redactapplicationEntities(); UTILISATEUR utilisateur = null; HttpCookie currentTrigerAuths = Request.Cookies["trigerAuths"]; if (currentTrigerAuths != null) { pwdCrypte = currentTrigerAuths.Values["password"]; utilisateur = db.UTILISATEURs.SingleOrDefault(x => x.userMail == model.userMail.Trim() && x.userMotdepasse == pwdCrypte); } if (utilisateur == null) { pwdCrypte = Encryptor.EncryptPass(model.userMotdepasse); 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"] = utilisateur.userMail; Session["saveOnComputer"] = null; 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); Session["UserId"] = utilisateur.userId; HttpCookie trigerAuths = new HttpCookie("trigerAuths"); if (model.saveOnComputer) { Session["saveOnComputer"] = "1"; trigerAuths.Values["username"] = utilisateur.userMail; trigerAuths.Values["password"] = 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] == 2) //{ // //return RedirectToRoute("Home", new RouteValueDictionary { // // { "controller", "Commandes" }, // // { "action", "ListCommandes" } // //}); // return RedirectToRoute("Home", new RouteValueDictionary { // { "controller", "Home" }, // { "action", "Dashboard" } // }); //} if (data[0] == 3 || data[0] == 4 || data[0] == 1 || data[0] == 2) { return(RedirectToRoute("Home", new RouteValueDictionary { { "controller", "Home" }, { "action", "Dashboard" } })); } if (data[0] == 5 || data[0] == 6) { return(RedirectToRoute("Home", new RouteValueDictionary { { "controller", "Template" }, { "action", "ListTemplate" } })); } } } } catch (Exception ex) { Debug.WriteLine(ex); Debug.WriteLine("passe exception"); return(View("ErrorException")); } Debug.WriteLine("passe error final"); return(View("ErrorInvalidAccountOrPassword")); }
/*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> { "Vous n'êtes plus autorisé à changer votre mot de passe." }; 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")); }