コード例 #1
0
        public ActionResult CompleteRegister([FromBody] CompleteRegisterModel value)
        {
            if (!string.IsNullOrWhiteSpace(value.DeviceResponse) &&
                !string.IsNullOrWhiteSpace(value.UserName))
            {
                try
                {
                    value.DeviceResponse = _memeberShipService.CompleteRegistration(value.UserName.Trim(),
                                                                                    value.DeviceResponse.Trim())
                        ? "Registration was successful."
                        : "Registration failed.";

                    return(View("CompletedRegister", new CompleteRegisterModel {
                        UserName = value.UserName, DeviceResponse = value.DeviceResponse
                    }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ModelState.AddModelError("CustomError", e.Message);

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

            ModelState.AddModelError("CustomError", "bad username/device response");
            return(View("FinishRegister", value));
        }
コード例 #2
0
        public void HomeController_CompleteRegisterNoDeviceTokenOrUsername()
        {
            HomeController        homeController = new HomeController(_memeberShipService.Object);
            CompleteRegisterModel registerModel  = new CompleteRegisterModel();

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

            Assert.IsNotNull(result);
            Assert.IsFalse(homeController.ModelState.IsValid);
            Assert.AreEqual("FinishRegister", result.ViewName);
        }
コード例 #3
0
        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       = "******",
                DeviceResponse = "DeviceResponse"
            };

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

            Assert.IsNotNull(result);
            Assert.IsFalse(homeController.ModelState.IsValid);
            Assert.AreEqual("FinishRegister", result.ViewName);
        }
コード例 #4
0
        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       = "******",
                DeviceResponse = "notreallydevicetoken"
            };

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

            Assert.IsNotNull(result);
            Assert.IsTrue(homeController.ModelState.IsValid);
            Assert.AreEqual("CompletedRegister", result.ViewName);
        }
コード例 #5
0
        public JsonResult GetChallenge()
        {
            ServerRegisterResponse serverRegisterResponse = _memeberShipService.GenerateServerChallenge(HttpContext.User.Identity.Name);
            CompleteRegisterModel  registerModel          = new CompleteRegisterModel
            {
                UserName  = HttpContext.User.Identity.Name,
                AppId     = serverRegisterResponse.AppId,
                Challenge = serverRegisterResponse.Challenge,
                Version   = serverRegisterResponse.Version
            };

            JsonResult result = new JsonResult
            {
                Data = registerModel
            };

            return(result);
        }
コード例 #6
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);
        }
コード例 #7
0
        public ActionResult BeginRegister([FromBody] RegisterModel value)
        {
            if (!string.IsNullOrWhiteSpace(value.Password) &&
                !string.IsNullOrWhiteSpace(value.UserName) &&
                value.Password.Equals(value.ConfirmPassword))
            {
                ServerRegisterResponse serverRegisterResponse = _memeberShipService.GenerateServerRegistration(value.UserName.Trim(), value.Password.Trim());
                CompleteRegisterModel  registerModel          = new CompleteRegisterModel
                {
                    UserName  = value.UserName,
                    AppId     = serverRegisterResponse.AppId,
                    Challenge = serverRegisterResponse.Challenge,
                    Version   = serverRegisterResponse.Version
                };

                return(View("FinishRegister", registerModel));
            }

            ModelState.AddModelError("CustomError", "invalid input");
            return(View("Register"));
        }
コード例 #8
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));
        }