Exemple #1
0
        public static ValidationFormat GetRegularExpressionByStateId(int StateId)
        {
            int validationRuleId = StateHelper.GetStateById(StateId).ValidationRuleId.Value;

            ValidationRule   validationRule   = LicenseValidationHelper.GetValidationRuleById(validationRuleId);
            ValidationFormat validationFormat = new ValidationFormat();

            validationFormat.RegularExpression = validationRule.RegularExpression;
            validationFormat.IsSSN             = validationRule.IsSSN;
            validationFormat.IsUserLoggedIn    = false;
            validationFormat.SSN          = string.Empty;
            validationFormat.ErrorMessage = validationRule.Description;

            if (SessionWrapper.LoggedUser != null)
            {
                validationFormat.IsUserLoggedIn = true;

                User user = UserHelper.GetUserById(SessionWrapper.LoggedUser.UserId);

                if (validationFormat.IsSSN)
                {
                    if (!string.IsNullOrEmpty(user.IdentificationValue))
                    {
                        validationFormat.SSN = EncryptionHelper.Decryptdata(user.IdentificationValue);
                    }
                }

                if (validationRule.IsLastCharcter)
                {
                    validationFormat.RegularExpression = validationFormat.RegularExpression.Replace("[a-zA-Z]", user.LastName[0].ToString());
                }
            }
            return(validationFormat);
        }
        public void WhenMatchesHasExpressionAndIsTooLong_ThenReturnsFalse()
        {
            var validationFormat = new ValidationFormat(@"^a*$", 1, 1);

            var result = validationFormat.Matches("aaaaaaa");

            result.Should().BeFalse();
        }
        public void WhenMatchesHasExpression_ThenReturnsTrue()
        {
            var validationFormat = new ValidationFormat(@"^avalue$");

            var result = validationFormat.Matches("avalue");

            result.Should().BeTrue();
        }
        public void WhenMatchesHasFunction_ThenReturnsFalse()
        {
            var validationFormat = new ValidationFormat(x => false);

            var result = validationFormat.Matches("avalue");

            result.Should().BeFalse();
        }
Exemple #5
0
        private string GetRegExForExpectedFormat(ValidationFormat expectedFormat)
        {
            string regexPattern = string.Empty;

            switch (expectedFormat)
            {
            case ValidationFormat.None:
                return(string.Empty);

            case ValidationFormat.AlphaNumeric:
                regexPattern = Validator.AlphaNumericRegexPattern;
                break;

            case ValidationFormat.Currency:
                regexPattern = Validator.CurrencyRegexPattern;
                break;

            case ValidationFormat.EmailAddress:
                regexPattern = Validator.EmailAddressRegexPattern;
                break;

            case ValidationFormat.Integer:
                regexPattern = Validator.IntegerRegexPattern;
                break;

            case ValidationFormat.InternetUrl:
                regexPattern = Validator.InternetUrlRegexPattern;
                break;

            case ValidationFormat.NonAlphaNumeric:
                regexPattern = Validator.NonAlphaNumericRegexPattern;
                break;

            case ValidationFormat.Numeric:
                regexPattern = Validator.NumericRegexPattern;
                break;

            case ValidationFormat.Percentage:
                regexPattern = Validator.PercentRegexPattern;
                break;

            case ValidationFormat.USSocialSecurityNumber:
                regexPattern = Validator.USSocialSecurityRegexPattern;
                break;

            case ValidationFormat.USZipCode:
                regexPattern = Validator.USZipCodeRegexPattern;
                break;

            case ValidationFormat.Custom:
                throw new ArgumentException("You must specify a valid RegularExpression.");
            }

            return(regexPattern);
        }
Exemple #6
0
        public ActionResult ChangePassword(FormCollection Fields)
        {
            //declare Form values
            string oldPassword    = Fields["oldPassword"];
            string newPassword    = Fields["newPassword"];
            string re_newPassword = Fields["re_newPassword"];
            string user           = (string)Session["username"];

            AccountManagement am = new AccountManagement();

            //check conditions to change password
            if (oldPassword == null || newPassword == null || re_newPassword == null)
            {
                return(View());
            }
            else if (oldPassword.Equals("") || newPassword.Equals("") || re_newPassword.Equals(""))
            {
                //send error message
                ModelState.AddModelError("", "Any fields can not be blank!!!!");
                return(View());
            }
            else if (!am.isOldPassword(user, oldPassword))
            {
                //send error message
                ModelState.AddModelError("", "The old password is not correct!!!!");
                return(View());
            }
            else if (!ValidationFormat.isPasswordFormat(newPassword))
            {
                //send error message
                ModelState.AddModelError("", "Password must be between 4 to 20 characters!!!!");
                return(View());
            }
            else
            {
                if (!newPassword.Equals(re_newPassword))
                {
                    //send error message
                    ModelState.AddModelError("", "Confirm password is not same with new password!!!!");
                    return(View());
                }
                else
                {
                    //send error message
                    //ModelState.AddModelError("", "Change successfull");
                    //return View();
                    //change password
                    am.ChangePassword(user, newPassword);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }
Exemple #7
0
        private string GetRegExForExpectedFormat(ValidationFormat expectedFormat)
        {
            switch (expectedFormat)
            {
            case ValidationFormat.AlphaNumeric:
                return(Validator.AlphaNumericRegexPattern);

            case ValidationFormat.Currency:
                return(Validator.CurrencyRegexPattern);

            case ValidationFormat.EmailAddress:
                return(Validator.EmailAddressRegexPattern);

            case ValidationFormat.Integer:
                return(Validator.IntegerRegexPattern);

            case ValidationFormat.InternetUrl:
                return(Validator.InternetUrlRegexPattern);

            case ValidationFormat.NonAlphaNumeric:
                return(Validator.NonAlphaNumericRegexPattern);

            case ValidationFormat.Numeric:
                return(Validator.NumericRegexPattern);

            case ValidationFormat.Percentage:
                return(Validator.PercentRegexPattern);

            case ValidationFormat.USSocialSecurityNumber:
                return(Validator.USSocialSecurityRegexPattern);

            case ValidationFormat.USZipCode:
                return(Validator.USZipCodeRegexPattern);

            default:
                return(string.Empty);
            }
        }
Exemple #8
0
 public ValidatorFormatValidator(ValidationFormat format)
     : base(Resources.ValidationFormatValidator_InvalidFormat)
 {
     this.format = format;
 }
Exemple #9
0
 public static IRuleBuilderOptions <T, TProperty> Matches <T, TProperty>(
     this IRuleBuilder <T, TProperty> ruleBuilder, ValidationFormat format)
 {
     return(ruleBuilder.SetValidator(new ValidatorFormatValidator(format)));
 }
Exemple #10
0
        //[HttpGet]
        //public ActionResult Create()
        //{
        //    return View("Index");
        //}

        public ActionResult Create(Account account, FormCollection Fields)
        {
            //declare variables and get value from Sign Up form
            string            fullname = Fields["fullName"];
            string            addr     = Fields["address"];
            string            email    = Fields["email"];
            string            phone    = Fields["phone"];
            string            gender   = Fields["gender"];
            string            username = account.ac_userName.ToString();
            string            password = account.ac_pwd.ToString();
            AccountManagement am       = new AccountManagement();

            //Check validation format
            if (fullname.Equals("") || addr.Equals("") || email.Equals("") || phone.Equals("") ||
                username.Equals("") || password.Equals(""))    //Check all fields has been fill
            {
                //send error message
                ModelState.AddModelError("", "Any fields can not be blank!!!!");
                return(View("Index"));
            }
            else if (!ValidationFormat.isEmailValid(email)) //Check email format
            {
                //send error message
                ModelState.AddModelError("", "Email is not correct format!!!!");
                return(View("Index"));
            }
            else if (!ValidationFormat.isPhoneFormat(phone)) //Check phone format
            {
                //send error message
                ModelState.AddModelError("", "Phone number must be 10 digits!!!!");
                return(View("Index"));
            }
            else if (am.isAccountExists(username))
            {
                //send error message
                ModelState.AddModelError("", "The username has already exists!!!!");
                return(View("Index"));
            }
            else if (!ValidationFormat.isPasswordFormat(password)) //Check password format
            {
                //send error message
                ModelState.AddModelError("", "Password must be between 4 to 20 characters!!!!");
                return(View("Index"));
            }
            else    //If don't have fields is blank
            {
                //send error message
                //ModelState.AddModelError("", "Sign Up Successful!");
                //return View("Index");

                //Insert Account and return account ID
                var pwdEncrypt = Encryptor.SHA256_Encrypt(account.ac_pwd);
                account.ac_pwd    = pwdEncrypt;
                account.ac_status = "Active";
                account.r_id      = 3;
                int acID = am.InsertAccount(account);
                //If insert Account successful then insert User
                if (acID > 0)
                {
                    //Insert User
                    UserManagement um = new UserManagement();
                    um.InsertUser(fullname, gender, email, phone, addr, acID);
                    var user = um.getUserByAccountID(acID);
                    //var user = db.User.LastOrDefault();
                    //Create session
                    Session["username"]  = account.ac_userName;
                    Session["userLogin"] = user;
                    //Redirect to Action Index on HomeController
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View("Index"));
        }