public ActionResult SignUp(ComboSignupLoginModel model, string returnUrl) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserNew.UserName, model.UserNew.Password, model.UserNew.Email); if (createStatus == MembershipCreateStatus.Success) { try { //finish the registration that the MembershipProvider did not handle. User user = UserRepository.CompleteRegistration(_db, model.UserNew.UserName, model.UserNew.FirstName, model.UserNew.LastName); //log that user registered. _log.LogIt(user.UserId, "User registered"); this.FlashInfo("Thank you for signing up!"); FormsAuthService.SignIn(user.UserId, user.Username, false /* createPersistentCookie */); //cache user data. CacheHelper.CacheUserData(FormsAuthService, user); return Redirect(user, returnUrl); } catch (Exception exp) { ModelState.AddModelError("", exp.Message); this.FlashValidationSummaryErrors(); } } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); this.FlashValidationSummaryErrors(); } } else { this.FlashValidationSummaryErrors(); } // If we got this far, something failed, redisplay form return View("login", model); }
public ActionResult Login(ComboSignupLoginModel model, string returnUrl) { if (ModelState.IsValid) { if (MembershipService.ValidateUser(model.UserLogin.LoginName, model.UserLogin.Password)) { //get user. User user = UserRepository.GetUser(_db, model.UserLogin.LoginName); if (user != null) { //log that the user logged in. _log.LogIt(user.UserId, "User Logged In"); FormsAuthService.SignIn(user.UserId, user.Username, model.UserLogin.RememberMe); //cache user data. CacheHelper.CacheUserData(FormsAuthService, user); return Redirect(user, returnUrl); } else { ModelState.AddModelError("", "User info could not be found."); this.FlashValidationSummaryErrors(); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); this.FlashValidationSummaryErrors(); } } else { this.FlashValidationSummaryErrors(); } // If we got this far, something failed, redisplay form return View(model); }