public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { try { var email = model.UserName.Contains("@") ? model.UserName : null; var loginData = _member.Login(model.UserName, email, model.Password); switch (loginData.Code) { case "1": { SessionManager.IsLoggedIn = true; SessionManager.UserLogged = new UserProfile() { FacebookId = loginData.FacebookId, UserId = loginData.MemberId, FirstName = loginData.MemberFirstName, LastName = loginData.MemberLastName, UserName = loginData.MemberUserName, Avatar = loginData.Avatar, AvatarMedium = loginData.AvatarMedium, Gender = loginData.MemberGender }; if (model.RememberMe) { System.Web.Security.FormsAuthentication.SetAuthCookie("username", false); var cookie = new HttpCookie("User"); cookie.Values.Add("username", model.UserName); cookie.Values.Add("password", model.Password); cookie.Expires = DateTime.Now.AddDays(360); Response.Cookies.Add(cookie); } if (!string.IsNullOrEmpty(returnUrl)) return Redirect(returnUrl); return RedirectToAction("Index", "Home"); } case "-1": ModelState.AddModelError("", loginData.Message); return View(model); } } catch (Exception ex) { Logger.Error(ex.Message); } } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { try { var email = model.UserName.Contains("@") ? model.UserName : null; var loginData = MemberRepository.Login(new LoginRequestModel {MemberEmail = email, ApiKey = null, MemberUserName = model.UserName, Password = model.Password}); switch (loginData.Code) { case "1": { SessionManager.IsLoggedIn = true; SessionManager.UserLogged = new UserProfile() { FacebookId = loginData.FacebookId, UserId = loginData.MemberId, FirstName = loginData.MemberFirstName, LastName = loginData.MemberLastName, UserName = loginData.MemberUserName, Avatar = loginData.Avatar, AvatarMedium = loginData.AvatarMedium, Gender = loginData.MemberGender }; if (model.RememberMe) { FormsAuthentication.SetAuthCookie("username", true); var cookie = new HttpCookie("UserAuthorize") { Value = CommonLib.EncryptString(new JavaScriptSerializer().Serialize(model)), Expires = DateTime.Now.AddDays(360) }; Response.Cookies.Add(cookie); } if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) return Redirect(returnUrl); return RedirectToAction("Index", "Home"); } case "-1": ModelState.AddModelError("", loginData.Message); return View(model); } } catch (Exception ex) { Logger.Error(ex.Message); } } // If we got this far, something failed, redisplay form return View(model); }