public void Register_Positive_Test() { // Arrange var registerModel = new User { UserName = "******", Email = "TestEmail", Password = "******", }; MembershipCreateStatus outParam; membershipServiceMock.Setup( ms => ms.CreateUser(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<object>(), out outParam)).Returns(It.IsAny<MembershipUser>); // Act accountController.Register(registerModel); // Assert var res = documentSession.Query<User>().Where(x => x.UserName == "TestUser").ToList(); Assert.IsTrue(res.Count == 1); Assert.IsTrue(res[0].UserName == "TestUser"); }
public void Register_Validate_User_Already_Exists() { // Arrange var registerModel = new User { UserName = "******", Email = "TestEmail", Password = "******", }; MembershipCreateStatus outParam = MembershipCreateStatus.Success; membershipServiceMock.Setup( ms => ms.CreateUser(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<object>(), out outParam)).Returns(It.IsAny<MembershipUser>); // Act accountController.Register(registerModel); }
public ActionResult Login(User loginModel) { ViewBag.UserName = loginModel.UserName; ViewBag.Email = loginModel.Email; return View("Index"); }
public ActionResult Register(User model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; _membershipService.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey:Guid.NewGuid(), status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { //_formsAuthenticationService.SetAuthCookie(model.UserName, createPersistentCookie: false); //_documentSession.Store(model); _documentSession.SaveChanges(); RedirectToAction("Post", "Accounts", model); return RedirectToAction("Index", "Home"); } ModelState.AddModelError("", ErrorCodeToString(createStatus)); } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Login(User model, string returnUrl) { if (ModelState.IsValid) { if (_membershipService.ValidateUser(model.UserName, model.Password)) { _formsAuthenticationService.SetAuthCookie(model.UserName, false); var user = _membershipService.GetUser(model.UserName, userIsOnline: true); model.Email = user.Email; model.UserName = user.UserName; LoggedInUser = model; if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } return RedirectToAction("Login", "Home", model); } else { ModelState.AddModelError("", ""); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult JsonRegister(User model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; _membershipService.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { _formsAuthenticationService.SetAuthCookie(model.UserName, createPersistentCookie: false); RedirectToAction("POST", "Accounts"); return Json(new { success = true }); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed return Json(new { errors = GetErrorsFromModelState() }); }
public JsonResult JsonLogin(User model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { // _formsAuthenticationService.SetAuthCookie(model.UserName, model.RememberMe); return Json(new { success = true, redirect = returnUrl }); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed return Json(new { errors = GetErrorsFromModelState() }); }