Ejemplo n.º 1
0
        /// <summary>
        /// Validates the name of the user.
        /// </summary>
        /// <param name="value">Name of the user.</param>
        /// <param name="idValue">id value of the entity. It will be used in update mode to check duplicate</param>
        /// <param name="fnName">Business rule function if it is insert or update</param>
        /// <param name="errors">The errors.</param>
        /// <param name="throwIfErrors">Throw BRException if an error happened</param>
        public bool ValidateUserName(string value, long?idValue, BusinessRuleErrorList errors, RuleFunctionSEnum fnName, bool throwIfErrors)
        {
            int errCount = errors.Count;

            if (CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.UserName, value, errors) == false)
            {
                if (throwIfErrors && errors.Count > errCount)
                {
                    throw new BRException(errors);
                }
                else
                {
                    return(false);
                }
            }

            string colName = vUser.ColumnNames.UserName;

            //Must consist at least two characters that are alpha characters a-zA-Z
            //Must consist only ONE underscore or dash allowed anywhere AFTER the first check,
            //the dash/underscore cannot be at the end as the same rule to apply as the first step
            //Must be alpha-numeric characters.

            //var colInfo = this.Entity.EntityColumns[User.ColumnNames.UserName];

            if (fnName == RuleFunctionSEnum.Delete)
            {
                return(true);
            }

            // DEVELOPER NOTE: Change this pattern with pattern specified in UI in FWHtml.cs file for editor
            // format check
            // http://stackoverflow.com/questions/3588623/c-sharp-regex-for-a-username-with-a-few-restrictions
            string valuePattern = @"^(?=.{5,50}$)([A-Za-z0-9][._]?)*$";

            //(?=.{5,50}$)                   Must be 5-50 characters in the string
            //([A-Za-z0-9][._()\[\]-]?)*   The string is a sequence of alphanumerics,
            //                              each of which may be followed by a symbol
            if (System.Text.RegularExpressions.Regex.IsMatch(
                    value, valuePattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase) == false)
            {
                errors.Add(colName, BusinessErrorStrings.User.UserName_RegularExpressionCheck
                           );
            }

            // duplicate check
            if (errors.Count == 0)       // Perfomance: We check database only if no error is there.
            {
                value = value.ToLower(); // we store all user names in lower case
                CheckUtils.CheckDuplicateValueNotToBeExists(colName, value, idValue, errors, null, fnName == RuleFunctionSEnum.Insert, BusinessErrorStrings.User.UserName_DuplicateUserName);
            }

            if (errors.Count > 0 && throwIfErrors)
            {
                throw new BRException(errors);
            }

            return(errors.Count == 0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates the phone number
        /// </summary>
        /// <param name="value">Phone Number</param>
        /// <param name="idValue">id value of the entity. It will be used in update mode to check duplicate</param>
        /// <param name="fnName">Business rule function if it is insert or update</param>
        /// <param name="canBeNull">See if Phone number can be null or empty</param>
        /// <param name="errors">The errors.</param>
        /// <param name="throwIfErrors">Throw BRException if an error happened</param>
        public bool ValidatePhoneNumber(string value, long?idValue, bool canBeNull, BusinessRuleErrorList errors, RuleFunctionSEnum fnName, bool throwIfErrors)
        {
            int errCount = errors.Count;

            // To simplify Signup, we removed Phone number as mandatory
            // in addition, RegisterAndLogin option doesn't need to have a phone number
            // However, if a phone number is provided, we need to check its format
            if (string.IsNullOrEmpty(value) && canBeNull)
            {
                return(true);
            }

            if (CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.PhoneNumber, value, errors) == false)
            {
                if (throwIfErrors && errors.Count > errCount)
                {
                    throw new BRException(errors);
                }
                else
                {
                    return(false);
                }
            }

            string colName = vUser.ColumnNames.PhoneNumber;

            if (fnName == RuleFunctionSEnum.Delete)
            {
                return(true);
            }

            if (IsValidPhoneNumberE164(value) == false)
            {
                errors.Add(colName, BusinessErrorStrings.User.PhoneNumber_NotE164);
            }



            // duplicate check
            if (errors.Count == 0)       // Perfomance: We check database only if no error is there.
            {
                value = value.ToLower(); // we store all user names in lower case
                CheckUtils.CheckDuplicateValueNotToBeExists(colName, value, idValue, errors, null, fnName == RuleFunctionSEnum.Insert, BusinessErrorStrings.User.PhoneNumber_DuplicatePhoneNumber);
            }

            if (errors.Count > 0 && throwIfErrors)
            {
                throw new BRException(errors);
            }

            return(errors.Count == 0);
        }
Ejemplo n.º 3
0
        public void UpdatePaykeyInDatabase(string payKey)
        {
            BusinessRuleErrorList errors = new BusinessRuleErrorList();

            if (CheckUtils.CheckStringShouldNotBeNullOrEmpty(vPayment.ColumnNames.PayKey, payKey, errors) == false)
            {
                throw new BRException(errors);
            }

            // check if pay key is not duplicated in database
            FilterExpression filter = new FilterExpression();

            filter.AddFilter(new Filter(vPayment.ColumnNames.PaymentStatusID, (int)EntityEnums.PaymentStatusEnum.PendingWithPayKey));
            if (CheckUtils.CheckDuplicateValueNotToBeExists(vPayment.ColumnNames.PayKey, payKey, null, errors, null, true, null) == false)
            {
                throw new BRException(errors[0].ErrorDescription);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check business rules for continuing quick registration
        /// </summary>
        /// <param name="p"></param>
        public void ContinueQReg(UserContinueQRegSP p)
        {
            BusinessRuleErrorList errors = new BusinessRuleErrorList();

            if (p.Password != p.ConfirmPassword)
            {
                errors.Add(vUser.ColumnNames.PasswordHash, BusinessErrorStrings.User.PasswordAndConfirmPasswordDoesntMatch);
            }

            CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.Email, p.Email, errors);
            CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.UserName, p.UserName, errors);
            CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.PasswordHash, p.Password, errors);
            CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.PhoneNumber, p.PhoneNumber, errors);

            if (errors.Count > 0)
            {
                throw new BRException(errors);
            }
        }
Ejemplo n.º 5
0
        public bool ValidatePassword(string value, BusinessRuleErrorList errors, bool throwIfException)
        {
            string colName = vUser.ColumnNames.PasswordHash;

            if (CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.PasswordHash, value, errors))
            {
                // Pattern obtained from
                //http://regexlib.com/(A(13E-t-BjvZ-WvDNI3kEXWexqe-dnRabCLhUJT4HCwiq39cFxk1bCp2xTgMv4ZLuwh4z02qwn-LwirPbo_Y1NF6Tnx6zEJKJ9ukU7WXcOnRM1))/Search.aspx?k=password&c=-1&m=-1&ps=20
                string valuePattern = @"(?=^.{6,64}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&amp;*()_+}{&quot;:;'?/&gt;.&lt;,])(?!.*\s).*$";
                if (System.Text.RegularExpressions.Regex.IsMatch(
                        value, valuePattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase) == false)
                {
                    errors.Add(colName, BusinessErrorStrings.User.Password_RegularExpression
                               );
                }
            }
            if (errors.Count > 0 && throwIfException)
            {
                throw new BRException(errors);
            }

            return(errors.Count == 0);
        }