コード例 #1
0
ファイル: AccountControllerTest.cs プロジェクト: madstt/Boku
        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");
        }
コード例 #2
0
ファイル: AccountControllerTest.cs プロジェクト: madstt/Boku
        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);
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: madstt/Boku
 public ActionResult Login(User loginModel)
 {
     ViewBag.UserName = loginModel.UserName;
     ViewBag.Email = loginModel.Email;
     return View("Index");
 }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: madstt/Boku
        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);
        }
コード例 #5
0
ファイル: AccountController.cs プロジェクト: madstt/Boku
        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);
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: madstt/Boku
        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() });
        }
コード例 #7
0
ファイル: AccountController.cs プロジェクト: madstt/Boku
        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() });
        }