Beispiel #1
0
        public void ValidateTrue()
        {
            var signup = new SignupData {
                Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "password", TimeZone = -5
            };
            var controller = GetController();

            _userManager.SetupAllProperties();
            signup.Validate(controller.ModelState, _userManager.Object, String.Empty);
            Assert.IsTrue(controller.ModelState.IsValid);
            Assert.AreEqual(0, controller.ModelState.Keys.Count);
        }
Beispiel #2
0
        public void ValidateFalsePasswordsTooShort()
        {
            var signup = new SignupData {
                Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "pword", TimeZone = -5
            };
            var controller = GetController();

            _userManager.SetupAllProperties();
            _userManager.Setup(u => u.IsPasswordValid(signup.Password, controller.ModelState)).Returns(false).Callback(() => controller.ModelState.AddModelError("Password", "whatever"));
            signup.Validate(controller.ModelState, _userManager.Object, String.Empty);
            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.AreEqual(1, controller.ModelState.Keys.Count);
            Assert.IsTrue(controller.ModelState.ContainsKey("Password"));
        }
Beispiel #3
0
        public void ValidateFalseBannedIP()
        {
            var signup = new SignupData {
                Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = "Diana", Password = "******", PasswordRetype = "password", TimeZone = -5
            };
            var          controller = GetController();
            const string bannedIP   = "127.0.0.1";

            _userManager.SetupAllProperties();
            _userManager.Setup(u => u.IsIPBanned(bannedIP)).Returns(true);
            signup.Validate(controller.ModelState, _userManager.Object, bannedIP);
            Assert.False(controller.ModelState.IsValid);
            Assert.AreEqual(1, controller.ModelState.Keys.Count);
            Assert.IsTrue(controller.ModelState.ContainsKey("Email"));
        }
Beispiel #4
0
        public void ValidateFalseNameInUse()
        {
            const string name   = "Diana";
            var          signup = new SignupData {
                Email = "*****@*****.**", IsCoppa = true, IsDaylightSaving = true, IsSubscribed = true, IsTos = true, Name = name, Password = "******", PasswordRetype = "password", TimeZone = -5
            };
            var controller = GetController();

            _userManager.SetupAllProperties();
            _userManager.Setup(u => u.IsNameInUse(name)).Returns(true);
            signup.Validate(controller.ModelState, _userManager.Object, String.Empty);
            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.AreEqual(1, controller.ModelState.Keys.Count);
            Assert.IsTrue(controller.ModelState.ContainsKey("Name"));
            _userManager.Verify(u => u.IsNameInUse(name), Times.Once());
        }
Beispiel #5
0
        public async Task <ViewResult> Create(SignupData signupData)
        {
            signupData.Validate(ModelState, _userService, HttpContext.Request.UserHostAddress);
            if (ModelState.IsValid)
            {
                var user = _userService.CreateUser(signupData, HttpContext.Request.UserHostAddress);
                _profileService.Create(user, signupData);
                var verifyUrl = this.FullUrlHelper("Verify", "Account");
                var result    = _newAccountMailer.Send(user, verifyUrl);
                if (result != System.Net.Mail.SmtpStatusCode.Ok)
                {
                    ViewData["EmailProblem"] = Resources.EmailProblemAccount + result + ".";
                }
                if (_settingsManager.Current.IsNewUserApproved)
                {
                    ViewData["Result"] = Resources.AccountReady;
                    _userService.Login(user.Email, signupData.Password, false, HttpContext);
                }
                else
                {
                    ViewData["Result"] = Resources.AccountReadyCheckEmail;
                }

                var authentication = _owinContext.Authentication;
                var authResult     = await _externalAuthentication.GetAuthenticationResult(authentication);

                if (authResult != null)
                {
                    _userAssociationManager.Associate(user, authResult, HttpContext.Request.UserHostAddress);
                }

                return(View("AccountCreated"));
            }
            SetupCreateData();
            return(View(signupData));
        }