public ActionResult Authentification(LoginModel model, String returnUrl) { var LanguageData = PageLanguageHelper.GetLanguageContent("Public", "UserCtrl/Auth"); try { Data.Model.User user; //string ipAddress = Request.UserHostAddress; if (ModelState.IsValid) { //Check password rules /*if (!UserBL.ValidatePassword(model.Password)) { ModelState.AddModelError("", "Veuillez vérifier votre mot de passe !"); } else*/ { //Authentification : check in DB if (UserBL.Authenticate(model.Email, model.Password, "USER", out user)) { if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("", "Home"); } } else { ModelState.AddModelError("", LanguageData.GetContent("ua_auth_erreur")); } } } } catch (Exception ex) { ViewBag.Info = LanguageData.GetContent("ua_catch_erreur") + ex.Message; } return View(model); }
/// <summary> /// Do the authentification to the extranet user. Post the Email and password to its url login /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult AuthentificationExtranetUser() { string extranetUserLoginUrl = string.Format("{0}/User/Login", System.Configuration.ConfigurationManager.AppSettings["ExtranetUser_Url"]); try { Guid idUser; bool isOk = SessionManager.Get<Guid>(UserBL.UserIdSessionKey, out idUser); User user = UserBL.GetUserById(idUser); if (user != null) { LoginModel loginModel = new LoginModel() { Email = user.UserEmail, Password = user.UserPassword, //NB : it's an encrypted password ExtranetUserLoginUrl = extranetUserLoginUrl }; return View(loginModel); } return View(new LoginModel()); } catch { return RedirectToAction(extranetUserLoginUrl); } finally { SessionManager.Clear(UserBL.UserIdSessionKey); } }