Exemplo n.º 1
0
        public void IsValidShouldReturnFalseWhenTheSpecifiedValueIsNotString()
        {
            EmailValidator emailValidator = new EmailValidator();

            Assert.AreEqual(false, emailValidator.IsValid(100));
            Assert.AreEqual(false, emailValidator.IsValid(new object()));
        }
Exemplo n.º 2
0
        public void EmailValidator_Test()
        {
            String passingValue = "*****@*****.**";
            String failingValue = "failString";

            EmailValidator emailCheck = new EmailValidator();

            Assert.IsTrue(emailCheck.IsValid(passingValue), "Assertion of positive case being true failed");
            Assert.IsFalse(emailCheck.IsValid(failingValue), "Assertion of negative case being false failed");
        }
        public static async Task <Customer> CreateNew(
            string email,
            string name,
            ICustomerUniquenessChecker customerUniquenessChecker)
        {
            if (!EmailValidator.IsValid(email))
            {
                throw new BusinessRuleValidationException($"This emailaddress is not valid: {email}");
            }

            if (!NameValidator.IsValid(name))
            {
                throw new BusinessRuleValidationException($"This name is not valid: {name}");
            }

            var customer = new Customer(email, name);
            var isUnique = await customerUniquenessChecker.IsUnique(customer).ConfigureAwait(false);

            if (!isUnique)
            {
                throw new BusinessRuleValidationException("Customer with this email already exists.");
            }

            return(customer);
        }
        private static bool ValidateEmail(EmailAddress emailToValidate, ref BrokenRuleCollection brokenRules)
        {
            //Set default return value to true
            bool returnValue = true;

            if (emailToValidate != null)
            {
                if (!string.IsNullOrEmpty(emailToValidate.EmailValue))
                {
                    if (!EmailValidator.IsValid(emailToValidate.EmailValue.Trim()))
                    {
                        brokenRules.Add("Email Address", emailToValidate.EmailValue.Trim() + " is an invalid email format.");
                        returnValue = false;
                    }
                }
                else
                {
                    brokenRules.Add("Email Address", "Email is required.");
                    returnValue = false;
                }
            }
            else
            {
                brokenRules.Add("Email Address", "Email class was not instantiated");
                returnValue = false;
            }
            return(returnValue);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> ChangeEmail(string password, string email)
        {
            email = email.Trim();

            if (!EmailValidator.IsValid(email))
            {
                return(BadRequest(new Error("EmailInvalid", "Email not valid", ErrorType.Soft)));
            }

            var user = await GetUserAsync();

            if (!await userManager.CheckPasswordAsync(user, password))
            {
                return(BadRequest(new Error("PasswordInvalid", "Password not valid", ErrorType.Soft)));
            }

            if (await userManager.CheckEmailInDbAsync(email, user.Id))
            {
                return(BadRequest(new Error("EmailAlreadyTaken", "Email already registered", ErrorType.Soft)));
            }

            await accountManager.SendChangeEmailConfirmationMessageByEmailAsync(user, email);

            return(Ok());
        }
Exemplo n.º 6
0
 public void EmailValidator_Test_Valid()
 {
     Assert.IsTrue(EmailValidator.IsValid("leo@leo"));
     Assert.IsTrue(EmailValidator.IsValid("131@3131"));
     Assert.IsTrue(EmailValidator.IsValid("*****@*****.**"));
     Assert.IsTrue(EmailValidator.IsValid("djfakçsjfdçaskjf@jfdçsjf.çsafljf"));
 }
Exemplo n.º 7
0
        private bool AreInputValid()
        {
            Errors.Clear();
            if (string.IsNullOrEmpty(this.UserName) || string.IsNullOrWhiteSpace(this.UserName))
            {
                UpdateError(true, "Email", "Email ID is required");
            }

            if (string.IsNullOrEmpty(this.Password) || string.IsNullOrWhiteSpace(this.Password))
            {
                UpdateError(true, "Password", "Password is required");
            }

            if (Errors.Count > 0)
            {
                return(false);                  //We dont need to validate anymore if Username or Password is empty;
            }
            if (!EmailValidator.IsValid(this.UserName))
            {
                UpdateError(true, "Email", "Enter the valid Email ID");
            }

            var passwordValidationResult = PasswordValidator.ValidateInput(this.Password);

            if (passwordValidationResult != null && passwordValidationResult.Count > 0)
            {
                foreach (var result in passwordValidationResult)
                {
                    UpdateError(true, result.Key, result.Value);
                }
            }

            return(Errors.Count() == 0);
        }
Exemplo n.º 8
0
        private async void OnForgotClick()
        {
            var result = await UserDialogService.Value.PromptAsync("Enter the Email ID", "Forgot Password", "Submit", "Cancel", "Type your Email ID", Acr.UserDialogs.InputType.Email);

            if (!result.Ok)
            {
                return;
            }

            if (!EmailValidator.IsValid(result.Text))
            {
                await UserDialogService.Value.AlertAsync("Invalid Email ID", "Error", "OK");

                return;
            }

            var credentials = CredentialService.Value.GetAllCredential();

            if (credentials == null || credentials.Count == 0 || credentials.Where(f => f.UserName.Trim().ToLower() == result.Text.Trim().ToLower()).FirstOrDefault() == null)
            {
                await UserDialogService.Value.AlertAsync("Email ID does not exists in our System", "Not Found!", "OK");

                return;
            }

            string recoveredPassword = credentials.Where(f => f.UserName.Trim().ToLower() == result.Text.Trim().ToLower()).FirstOrDefault().Password;

            await UserDialogService.Value.AlertAsync("Your Password is : " + recoveredPassword, "Note your Password", "Got it!");
        }
Exemplo n.º 9
0
 public void IsValid_False()
 {
     Assert.IsFalse(EmailValidator.IsValid("fdsa"));
     Assert.IsFalse(EmailValidator.IsValid("fdsa@"));
     Assert.IsFalse(EmailValidator.IsValid("fdsa@fdsa"));
     Assert.IsFalse(EmailValidator.IsValid("fdsa@fdsa."));
     Assert.IsFalse(EmailValidator.IsValid("plainaddress"));
     Assert.IsFalse(EmailValidator.IsValid("#@%^%#$@#$@#.com"));
     Assert.IsFalse(EmailValidator.IsValid("@example.com"));
     Assert.IsFalse(EmailValidator.IsValid("Joe Smith <*****@*****.**>"));
     Assert.IsFalse(EmailValidator.IsValid("email.example.com"));
     Assert.IsFalse(EmailValidator.IsValid("email@[email protected]"));
     Assert.IsFalse(EmailValidator.IsValid("*****@*****.**"));
     Assert.IsFalse(EmailValidator.IsValid("*****@*****.**"));
     Assert.IsFalse(EmailValidator.IsValid("*****@*****.**"));
     Assert.IsFalse(EmailValidator.IsValid("あいうえお@example.com"));
     Assert.IsFalse(EmailValidator.IsValid("[email protected] (Joe Smith)"));
     Assert.IsFalse(EmailValidator.IsValid("email@example"));
     Assert.IsFalse(EmailValidator.IsValid("*****@*****.**"));
     Assert.IsFalse(EmailValidator.IsValid("*****@*****.**"));
     Assert.IsFalse(EmailValidator.IsValid("*****@*****.**"));
     Assert.IsFalse(EmailValidator.IsValid("“(),:;<>[\\]@example.com"));
     Assert.IsFalse(EmailValidator.IsValid("just\"not\"*****@*****.**"));
     Assert.IsFalse(EmailValidator.IsValid("this\\ is\"really\"not\[email protected]"));
 }
Exemplo n.º 10
0
 public void EmailValidator_Test_Invalid()
 {
     Assert.IsFalse(EmailValidator.IsValid(""));
     Assert.IsFalse(EmailValidator.IsValid("leo@"));
     Assert.IsFalse(EmailValidator.IsValid("@3131"));
     Assert.IsFalse(EmailValidator.IsValid("jfdçsjf.çsafljf"));
 }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (!EmailValidator.IsValid(model.Email))
            {
                ModelState.AddModelError("Email", "Email kunne ikke valideres som værende korrekt email format.");
            }
            else
            {
                model.Email = EmailValidator.ParseEmail(model.Email);
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var callbackUrl = await GenerateEmailConfirmationEmail(user);

                    ViewBag.Link = callbackUrl;
                    return(View("DisplayEmail"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            if (!EmailValidator.IsValid(model.Email))
            {
                ModelState.AddModelError("Email", "Email kunne ikke valideres som værende korrekt email format.");
            }
            else
            {
                model.Email = EmailValidator.ParseEmail(model.Email);
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToAction("ResetPasswordConfirmation", "Account"));
            }
            var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("ResetPasswordConfirmation", "Account"));
            }
            AddErrors(result);
            return(View());
        }
        public void ShouldValidateEmail(string email, bool isValid)
        {
            var sut = new EmailValidator();

            var result = sut.IsValid(email);

            Assert.Equal(isValid, result);
        }
Exemplo n.º 14
0
        public void IsValid_ShouldBeFalse_WhenEmail_IsNull()
        {
            // Act
            var result = EmailValidator.IsValid(null);

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 15
0
        public void IsValid_ShouldBeFalse_WhenEmail_IsEmpty()
        {
            // Act
            var result = EmailValidator.IsValid(string.Empty);

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 16
0
        public void IsValid_Returns_True_For_Valid_Email()
        {
            var underTest = new EmailValidator();

            var result = underTest.IsValid("*****@*****.**");

            Assert.True(result.IsValid);
        }
Exemplo n.º 17
0
        public void IsValid_Returns_False_For_Empty_String()
        {
            var underTest = new EmailValidator();

            var result = underTest.IsValid("");

            Assert.False(result.IsValid);
        }
Exemplo n.º 18
0
        public void IsValid_Returns_IsRequired_Message()
        {
            var underTest = new EmailValidator();

            var result = underTest.IsValid("");

            Assert.True(result.ErrorMessages.Single() == "Email is required.");
        }
Exemplo n.º 19
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (!EmailValidator.IsValid(Email))
     {
         yield return(new ValidationResult(
                          $"Vul een e-mail adres in", new[] { "Email" }));
     }
 }
Exemplo n.º 20
0
        public void IsValid_ShouldBeFalse_WhenEmail_IsNotValid(string email)
        {
            // Act
            var result = EmailValidator.IsValid(email);

            // Assert
            result.Should().BeFalse();
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!EmailValidator.IsValid(model.Email))
            {
                ModelState.AddModelError("Email", "Email kunne ikke valideres som værende korrekt email format.");
            }
            else
            {
                model.Email = EmailValidator.ParseEmail(model.Email);
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ReturnUrl           = returnUrl;
                ViewBag.LiveDemoMemberships = Demo.GetLiveDemoMemberships();
                ViewBag.EnableDemo          = (ViewBag.LiveDemoMemberships != null && ViewBag.LiveDemoMemberships.Count > 0);
                ViewBag.EnableMobil         = UserManager.TwoFactorProviders.ContainsKey("PhoneCode");
                model.LoginState            = LoginViewModel.State.Login;
                return(View(model));
            }

            // This doen't count login failures towards lockout only two factor authentication
            // To enable password failures to trigger lockout, change to shouldLockout: true
            var result = await SignInHelper.PasswordSignIn(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:

                var cookie = new HttpCookie("LastEmailLogin", model.Email);
                cookie.Expires = DateTime.Now.AddMonths(1);
                Response.AppendCookie(cookie);

                return(RedirectToLocal(returnUrl));

            case SignInStatus.UnConfirmed:
                return(RedirectToAction("EmailNotConfirmed", new { email = model.Email }));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresTwoFactorAuthentication:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl }));

            case SignInStatus.Failure:
            default:
                ViewBag.ReturnUrl           = returnUrl;
                ViewBag.LiveDemoMemberships = Demo.GetLiveDemoMemberships();
                ViewBag.EnableDemo          = (ViewBag.LiveDemoMemberships != null && ViewBag.LiveDemoMemberships.Count > 0);
                ViewBag.EnableMobil         = UserManager.TwoFactorProviders.ContainsKey("PhoneCode");
                model.LoginState            = LoginViewModel.State.Login;
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Exemplo n.º 22
0
        public void Return_True_For_Valid_Email()
        {
            // Arrange
            string email = "*****@*****.**";

            // Act
            var result = EmailValidator.IsValid(email);

            // Assert
            Assert.IsTrue(result);
        }
Exemplo n.º 23
0
        public ValidationOutputDto ValidateRegisterData(RegisterInputDto inputDto)
        {
            if (!EmailValidator.IsValid(inputDto.Email))
            {
                return(new ValidationOutputDto(false, "Podany email nie jest poprawny"));
            }

            return(!PasswordValidator.IsValid(inputDto.Password, inputDto.PasswordConfirm) ?
                   new ValidationOutputDto(false, "Hasło nie spełnia naszych wymagań lub nie jest takie same jak") :
                   new ValidationOutputDto(true, "Rejestracja zakończona poprawnie!"));
        }
Exemplo n.º 24
0
        public void Return_False_For_Invalid_Email()
        {
            // Arrange
            string email = "invalid";

            // Act
            var result = EmailValidator.IsValid(email);

            // Assert
            Assert.IsFalse(result);
        }
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                if (!EmailValidator.IsValid(model.Email))
                {
                    ViewBag.Message = string.Format("Unable to validate email '{0}' as email.", model.Email);
                    return(View("ExternalLoginFailure"));
                }
                else
                {
                    model.Email = EmailValidator.ParseEmail(model.Email);
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        // We dont log the user in until there email has been validated.
                        //await SignInHelper.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                        // Generete token email
                        var callbackUrl = GenerateEmailConfirmationEmail(user);
                        ViewBag.Link = callbackUrl;

                        return(RedirectToAction("DisplayEmail"));
                        //return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
        private void ValidateInput(ContactUs data)
        {
            if (string.IsNullOrWhiteSpace(data.Email) || string.IsNullOrWhiteSpace(data.Comments) || string.IsNullOrWhiteSpace(data.Name))
            {
                throw new ValidationException("Input not valid");
            }

            if (!EmailValidator.IsValid(data.Email))
            {
                throw new ValidationException("Email not valid");
            }
        }
        public Tuple <bool, string> Validate(CapRedV2UserSignUpDTO entity)
        {
            var message = string.Empty;

            var result = EmailValidator.IsValid(entity.Email);

            if (!result)
            {
                message = "The email has an invalid format";
            }

            return(new Tuple <bool, string>(result, message));
        }
Exemplo n.º 28
0
 private void RegisterButton_Click(object sender, RoutedEventArgs e)
 {
     if (!EmailValidator.IsValid(RegisterEmailTextBox.Text))
     {
         MessageBox.Show("Adres email niepoprawny!");
         return;
     }
     if (!PasswordValidator.ValidatePassword(RegisterPasswordTextBox.Password))
     {
         MessageBox.Show("Hasło jest za słabe!");
         return;
     }
     Register();
 }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            var  nameValidator     = new NameValidator();
            var  documentValidator = new DocumentValidator();
            var  emailValidator    = new EmailValidator();
            bool isValid;

            Console.WriteLine("Please insert required data below.");

            do
            {
                Console.Write("Name: ");
                var name = Console.ReadLine();
                isValid = nameValidator.IsValid(name);

                if (!isValid)
                {
                    Console.WriteLine("Name is invalid.");
                }
            } while (!isValid);


            do
            {
                Console.Write("Document: ");
                var document = Console.ReadLine();
                isValid = documentValidator.IsValid(document);

                if (!isValid)
                {
                    Console.WriteLine("Document is invalid.");
                }
            } while (!isValid);

            do
            {
                Console.Write("Email: ");
                var email = Console.ReadLine();
                isValid = emailValidator.IsValid(email);

                if (!isValid)
                {
                    Console.WriteLine("Email is invalid.");
                }
            } while (!isValid);

            Console.WriteLine("Registration completed.");
        }
Exemplo n.º 30
0
        private void EditEmailButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!EmailValidator.IsValid(EmailTextBox.Text))
                {
                    MessageBox.Show("Adres email niepoprawny!");
                    return;
                }

                VoiceChatDBEntities serverDB = new VoiceChatDBEntities();
                var queryEmailResult         = serverDB.Users.FirstOrDefault(u => u.Email == EmailTextBox.Text);
                if (queryEmailResult != null)
                {
                    MessageBox.Show("Podany adres email jest już zajęty!");
                    return;
                }
                if (server.OnlineUsers.Any(u => u.Id == user.UserId))
                {
                    MessageBox.Show("Nie można edytować użytkownika, który jest online!");
                    return;
                }

                user.Email = EmailTextBox.Text;
                manager.EditUser(user);

                //n !!! trzeba wyslac wszystkim userom online info, zeby zaktualizowali sobie tego usera
                var onlineUsers = server.OnlineUsers;
                foreach (var singleUser in onlineUsers)
                {
                    server.SendNewFriendUserEncrypted(singleUser.Client,
                                                      new cscprotocol.CscChangeFriendData {
                        Id = user.UserId
                    }, singleUser.DH.Key);
                }

                if (UserControl != null)
                {
                    UserControl.RefreshDataGrid();
                }

                MessageBox.Show("Zaktualizowano dane użytkownika.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }