Example #1
0
        public JsonResult GetChallenge(string username)
        {
            ServerRegisterResponse serverRegisterResponse = _memeberShipService.GenerateServerChallenge(username);
            CompleteRegisterModel registerModel = new CompleteRegisterModel
            {
                UserName = username,
                AppId = serverRegisterResponse.AppId,
                Challenge = serverRegisterResponse.Challenge,
                Version = serverRegisterResponse.Version
            };

            JsonResult result = new JsonResult
            {
                Data = registerModel
            };
            return result;
        }
        public void HomeController_CompleteRegisterWithUsernameNoDeviceToken()
        {
            HomeController homeController = new HomeController(_memeberShipService.Object);
            CompleteRegisterModel registerModel = new CompleteRegisterModel { UserName = "tester" };

            ViewResult result = homeController.CompleteRegister(registerModel) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsFalse(homeController.ModelState.IsValid);
            Assert.AreEqual("FinishRegister", result.ViewName);
        }
        public void HomeController_CompleteRegisterWithUsernameAndDeviceToken()
        {
            _memeberShipService.Setup(
                e => e.CompleteRegistration(It.Is<string>(p => p == "tester"), It.Is<string>(p => p == "notreallydevicetoken"))).Returns(true);
            HomeController homeController = new HomeController(_memeberShipService.Object);
            CompleteRegisterModel registerModel = new CompleteRegisterModel
                                                  {
                                                      UserName = "tester",
                                                      DeviceResponse = "notreallydevicetoken"
                                                  };

            ViewResult result = homeController.CompleteRegister(registerModel) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(homeController.ModelState.IsValid);
            Assert.AreEqual("CompletedRegister", result.ViewName);
        }
        public void HomeController_CompleteRegisterExceptionThrown()
        {
            _memeberShipService.Setup(s => s.CompleteRegistration(It.IsAny<string>(), It.IsAny<string>())).Throws(new Exception());
            HomeController homeController = new HomeController(_memeberShipService.Object);
            CompleteRegisterModel registerModel = new CompleteRegisterModel
                                                  {
                                                      UserName = "username",
                                                      DeviceResponse = "DeviceResponse"
                                                  };

            ViewResult result = homeController.CompleteRegister(registerModel) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsFalse(homeController.ModelState.IsValid);
            Assert.AreEqual("FinishRegister", result.ViewName);
        }
Example #5
0
        public ActionResult BeginRegister([FromBody] RegisterModel value)
        {
            if (_memeberShipService.IsUserRegistered(value.UserName))
            {
                ModelState.AddModelError("CustomError", "User is already registered.");
                return View("Register", value);
            }

            if (!string.IsNullOrWhiteSpace(value.Password)
                && !string.IsNullOrWhiteSpace(value.UserName)
                && value.Password.Equals(value.ConfirmPassword))
            {
                try
                {
                    _memeberShipService.SaveNewUser(value.UserName, value.Password);
                    ServerRegisterResponse serverRegisterResponse = _memeberShipService.GenerateServerChallenge(value.UserName.Trim());
                    CompleteRegisterModel registerModel = new CompleteRegisterModel
                    {
                        UserName = value.UserName,
                        AppId = serverRegisterResponse.AppId,
                        Challenge = serverRegisterResponse.Challenge,
                        Version = serverRegisterResponse.Version
                    };

                    return View("FinishRegister", registerModel);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ModelState.AddModelError("CustomError", e.Message);

                    return View("Register", value);
                }
            }

            ModelState.AddModelError("CustomError", "invalid input");
            return View("Register", value);
        }