示例#1
0
 public ValidationResult ConfirmPassword(string pass, string pass2, params string[] memberNames)
 {
     return
         (pass != pass2?
          TfValidationResult.Compose("ConfirmPassword", memberNames) :
              null);
 }
示例#2
0
        public override IEnumerable <ValidationResult> Validate()
        {
            if (this.Password != this.ConfirmPassword)
            {
                yield return(TfValidationResult.Compose("ConfirmPassword", nameof(this.Password), nameof(this.ConfirmPassword)));
            }

            if (CheckMember.CheckEmailExists(this.Email))
            {
                yield return(TfValidationResult.Compose("EmailExists", nameof(this.Email)));
            }

            if (CheckMember.CheckUsernameExists(this.Username))
            {
                yield return(TfValidationResult.Compose("UsernameExists", nameof(this.Username)));
            }

            yield return(TfValidationResult.FieldRequired(nameof(this.Username), this.Username));

            yield return(TfValidationResult.FieldRequired(nameof(this.Password), this.Password));

            yield return(TfValidationResult.FieldRequired(nameof(this.ConfirmPassword), this.ConfirmPassword));

            yield return(TfValidationResult.FieldRequired(nameof(this.Email), this.Email));

            yield return(TfValidationResult.FieldRequired(nameof(this.FirstName), this.FirstName));

            yield return(TfValidationResult.FieldRequired(nameof(this.LastName), this.LastName));
        }
示例#3
0
 public ValidationResult CheckUsernamePassword(params string[] memberNames)
 {
     return
         (this.Members.Count == 0 ?
          TfValidationResult.Compose("InvalidLogin", memberNames) :
          null);
 }
 public static ValidationResult ValidateURL(object value, string[] memberNames)
 {
     if (!Uri.IsWellFormedUriString(value.ToString(), UriKind.RelativeOrAbsolute))
     {
         return(TfValidationResult.Compose("InvalidInput", memberNames, memberNames));
     }
     return(null);
 }
 public static ValidationResult ValidateFilePath(object value, string[] memberNames)
 {
     if (!Directory.Exists(Path.GetDirectoryName(Convert.ToString(value))))
     {
         return(TfValidationResult.Compose("InvalidInput", memberNames, memberNames));
     }
     return(null);
 }
示例#6
0
 public ValidationResult ValidateCart(params string[] memberNames)
 {
     if (!this.Carts.HasRecords)
     {
         return(TfValidationResult.Compose("EmptyCart", memberNames));
     }
     return(null);
 }
示例#7
0
 public ValidationResult CheckActivity(params string[] memberNames)
 {
     this.Members.Case.Where(this.Members._(x => x.active), Is.EqualTo, 1);
     return
         (this.Members.Count == 0 ?
          TfValidationResult.Compose("InactiveAccount", memberNames) :
          null);
 }
 public static ValidationResult ValidateDateTime(object value, string[] memberNames)
 {
     if (!DateTime.TryParse(value?.ToString(), out DateTime dateTime))
     {
         TfValidationResult.Compose("InvalidInput", memberNames);
     }
     return(null);
 }
示例#9
0
        public ValidationResult ValidateWallet(string sessionId, params string[] memberNames)
        {
            var wallet = MemberStrategy.GetMemberWallet(this.Member.id);

            if (this.TotalPrice > wallet.amount)
            {
                return(TfValidationResult.Compose("InsufficientCash", memberNames));
            }
            return(null);
        }
示例#10
0
        public ValidationResult ConfirmEmail(string email, string memberName)
        {
            var members = _DB.Members;

            members.Case.Where(members._(x => x.email), Is.EqualTo, email);
            return
                (members.HasRecords ?
                 TfValidationResult.Compose("InvalidExistance", new[] { email }, memberName) :
                 null);
        }
示例#11
0
        public ValidationResult ConfirmUsername(string username, string memberName)
        {
            var members = _DB.Members;

            members.Case.Where(members._(x => x.username), Is.EqualTo, username);
            return
                (members.HasRecords ?
                 TfValidationResult.Compose("InvalidExistance", new[] { username }, memberName) :
                 null);
        }
示例#12
0
        public static ValidationResult ValidateItem(string itemCode, params string[] memberNames)
        {
            var items = _DB.Items;

            items.Entity.item_code = itemCode;
            if (!items.HasRecord)
            {
                return(TfValidationResult.Compose("NotExists", memberNames));
            }
            return(null);
        }
示例#13
0
        public override IEnumerable <ValidationResult> Validate()
        {
            yield return(TfValidationResult.CheckSessionActivity(this.SessionId, this.SessionKey));

            yield return(TfValidationResult.FieldRequired(nameof(this.Username), this.Username));

            if (CheckAdd.CheckContactExists(this.SessionId, this.Username))
            {
                yield return(TfValidationResult.Compose("ContactExists", nameof(this.Username)));
            }
        }
示例#14
0
 public override IEnumerable <ValidationResult> Validate()
 {
     if (this.IsValid(nameof(this.Key)))
     {
         this.Request.Entity.activation_key = this.Key;
         this.Request.Entity.active         = 0;
         if (!this.Request.HasRecord)
         {
             yield return(TfValidationResult.Compose("InvalidActivationKey", nameof(this.Key)));
         }
     }
 }
        public ValidationResult ValidateAdmin(IAdmin admin)
        {
            var member = _Schemas.Members;

            member.Entity.username = admin.SessionIdValue;
            member.Entity.admin    = EnumAdmin.Admin;
            if (member.Count == 1)
            {
                return(null);
            }
            return(TfValidationResult.Compose("SessionExpired"));
        }
 public static ValidationResult ValidateBoolean(object value, string[] memberNames)
 {
     if (value is bool ||
         (value as string) == "true" ||
         (value as string) == "false" ||
         (value as int?) == 1 ||
         (value as int?) == 0)
     {
         return(null);
     }
     return(TfValidationResult.Compose("InvalidInput", memberNames, memberNames));
 }
示例#17
0
        public ValidationResult ValidateAdmin(IAdmin admin)
        {
            var accounts = _DB.Accounts;

            accounts.Entity.username = admin.SessionIdValue;
            accounts.Entity.admin    = Enums.EnumAdmin.Admin;
            if (accounts.Count == 0)
            {
                return(TfValidationResult.Compose("SessionExpired", nameof(admin.SessionId)));
            }
            return(null);
        }
示例#18
0
        public ValidationResult ValidateRequestId(IGetDetailsBase getDetails)
        {
            var requests = _Schemas.Requests;

            requests.Entity.id = getDetails.RequestId;
            if (requests.Count == 0)
            {
                return(TfValidationResult.Compose(
                           "DataNotFound",
                           nameof(getDetails.RequestId)));
            }
            return(null);
        }
示例#19
0
        private static ValidationResult Validate(string pattern, object value, string[] memberNames)
        {
            var regex = new Regex(pattern, RegexOptions.IgnoreCase);

            if (!regex.IsMatch(value?.ToString() ?? ""))
            {
                return(TfValidationResult.Compose(
                           message: "InvalidInput",
                           values: memberNames,
                           memberNames: memberNames));
            }
            return(null);
        }
示例#20
0
        public ValidationResult ValidatePraiseId(IGetReport getReport)
        {
            var praises = _Schemas.Praises;

            praises.Entity.id = getReport.PraiseId;
            if (praises.Count == 0)
            {
                return(TfValidationResult.Compose(
                           "DataNotFound",
                           nameof(getReport.PraiseId)));
            }
            return(null);
        }
示例#21
0
 public override IEnumerable <ValidationResult> Validate()
 {
     if (this.IsValid(this.Key))
     {
         var members = _Schemas.Members;
         members.Entity.activation_key = this.Key;
         members.Entity.active         = (int)EnumActive.Inactive;
         if (members.Count == 0)
         {
             yield return(TfValidationResult.Compose("InvalidActivation", nameof(this.Key)));
         }
     }
 }
示例#22
0
        public ValidationResult ValidatePoints(string sessionId, params string[] memberNames)
        {
            var memberPoints = TokensStrategy.GetPoints(sessionId);

            if (this.Campaign.SelectToEntity() == null)
            {
                return(TfValidationResult.Compose("NotExists", memberNames));
            }
            if (this.Campaign.Entity.price > memberPoints)
            {
                return(TfValidationResult.Compose("InsufficientPoints", memberNames));
            }
            return(null);
        }
示例#23
0
        protected bool Authorize(bool validate)
        {
            if (!validate)
            {
                return(true);
            }

            var accesses = Schemas.Accesses;

            if (TfSettings.System.Debug)
            {
                accesses.Case.Where(accesses._(x => x.key), Is.EqualTo, TfSettings.System.DefaultKey);
                accesses.Case.Where(accesses._(x => x.secret), Is.EqualTo, TfSettings.System.DefaultSecret);
                if (accesses.Count == 0)
                {
                    var uri = new Uri(TfSettings.Web.ApiUrl);
                    accesses.Entity.key    = TfSettings.System.DefaultKey;
                    accesses.Entity.secret = TfSettings.System.DefaultSecret;
                    accesses.Entity.host   = $"{uri.Host}:{uri.Port}";
                    accesses.Insert();
                }
            }

            accesses.ClearCase();
            accesses.Case.Where("CONCAT(key, secret, host) = {0}", Encryption.Decrypt(this.Request.Headers["Authorization"].ToString()));
            //accesses.Case.Where(accesses._(x => x.host), Is.EqualTo, this.Request.Host.ToString());
            accesses.Case.Where(accesses._(x => x.active), Is.EqualTo, 1);

            if (accesses.Count == 0 || (TfSettings.Web.RequireHttps && this.Request.Scheme != "https"))
            {
                var validationDictionary = new Dictionary <string, object>();
                var validationError      = TfValidationResult.Compose("Unauthorized", "system");

                this.ControllerContext.ModelState.AddModelError("system", validationError.ErrorMessage);

                var jsonDictionary = new Dictionary <string, object>
                {
                    { "is_valid", false },
                    { "message", new Dictionary <string, object> {
                          { validationError.MemberNames.First(), validationError.ErrorMessage }
                      } }
                };

                this.JsonResult = base.Json(jsonDictionary, this.JsonSettings);

                return(false);
            }

            return(true);
        }
        public ValidationResult ValidateUsername(IInsertMember insertMember)
        {
            var members = _Schemas.Members;

            members.Entity.username = insertMember.Member.username;
            members.Entity.active   = EnumActive.Active;
            if (members.Count > 0)
            {
                return(TfValidationResult.Compose(
                           "InvalidDuplicate",
                           new[] { insertMember.Member.username },
                           nameof(insertMember.Member.username)));
            }
            return(null);
        }
        public static ValidationResult ValidateEnum(object value, string[] memberNames)
        {
            var list = new List <int>();

            foreach (var item in Enum.GetValues(value.GetType()))
            {
                list.Add((int)item);
            }

            if (!list.Contains((int)value))
            {
                return(TfValidationResult.Compose("InvalidInput", memberNames, memberNames));
            }
            return(null);
        }
示例#26
0
        public ValidationResult ValidateUsernamePassword(ILoginMember loginMember)
        {
            var members = _Schemas.Members;

            members.Entity.username = loginMember.Username;
            members.Entity.password = loginMember.Password;
            if (members.Count == 0)
            {
                return(TfValidationResult.Compose(
                           "InvalidUsernamePassword",
                           nameof(loginMember.Username),
                           nameof(loginMember.Password)));
            }
            return(null);
        }
示例#27
0
        public ValidationResult ValidateUsernameSession(ILoginMember loginMember)
        {
            var members = _Schemas.Members;

            members.Entity.username = loginMember.SessionIdValue;
            members.Entity.active   = EnumActive.Active;
            if (members.Count == 0)
            {
                return(TfValidationResult.Compose(
                           "SessionExpired",
                           nameof(loginMember.Username),
                           nameof(loginMember.Password)));
            }
            return(null);
        }
示例#28
0
        public ValidationResult ValidateLogin(ILogin login)
        {
            var accounts = _DB.Accounts;

            accounts.Entity.username = login.username;
            accounts.Entity.password = login.password;
            accounts.Entity.admin    = Enums.EnumAdmin.Admin;
            if (accounts.Count == 0)
            {
                return(TfValidationResult.Compose(
                           "InvalidUsernamePassword",
                           nameof(login.username),
                           nameof(login.password)));
            }
            return(null);
        }
示例#29
0
        public ValidationResult ValidateRequestId(IGetDetails getDetails)
        {
            var requests = _Schemas.Requests;

            requests.Entity.id = getDetails.RequestId;
            if (!this.IsAdmin(getDetails))
            {
                requests.Entity.publicity = EnumPublic.Public;
            }
            if (requests.Count == 0)
            {
                return(TfValidationResult.Compose(
                           "DataNotFound",
                           nameof(getDetails.RequestId)));
            }
            return(null);
        }
示例#30
0
        public override IEnumerable <ValidationResult> Validate()
        {
            yield return(this.ValidateSession());

            if (this.IsValidRequireInputs())
            {
                var admins = _DB.Admins;
                if (admins.Count < 2)
                {
                    yield return(TfValidationResult.Compose("Cannot delete remaining account.", nameof(this.Id)));
                }
                admins.Entity.id = this.Id;
                if (admins.Count == 0)
                {
                    yield return(TfValidationResult.Compose("DataNotFound", nameof(this.Id)));
                }
            }
        }