Example #1
0
        public async Task <bool> VerifyOptCode(AppUser AppUser)
        {
            AppUser oldData = (await UOW.AppUserRepository.List(new AppUserFilter
            {
                Skip = 0,
                Take = 1,
                Email = new StringFilter {
                    Equal = AppUser.Email
                },
                Selects = AppUserSelect.ALL
            })).FirstOrDefault();

            if (oldData == null)
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Email), ErrorCode.EmailNotExisted);
            }
            if (oldData.OtpCode != AppUser.OtpCode)
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.OtpCode), ErrorCode.OtpCodeInvalid);
            }
            if (DateTime.Now > oldData.OtpExpired)
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.OtpExpired), ErrorCode.OtpExpired);
            }

            return(AppUser.IsValidated);
        }
Example #2
0
        public async Task <bool> ChangePassword(AppUser AppUser)
        {
            List <AppUser> AppUsers = await UOW.AppUserRepository.List(new AppUserFilter
            {
                Skip = 0,
                Take = 1,
                Id   = new IdFilter {
                    Equal = AppUser.Id
                },
                Selects = AppUserSelect.ALL,
            });

            if (AppUsers.Count == 0)
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.IdNotExisted);
            }
            else
            {
                AppUser appUser = AppUsers.FirstOrDefault();
                bool    verify  = VerifyPassword(appUser.Password, AppUser.Password);
                if (verify == false)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Password), ErrorCode.PasswordNotMatch);
                }
            }
            return(AppUser.IsValidated);
        }
Example #3
0
 public async Task <bool> ValidatePhone(AppUser AppUser)
 {
     if (string.IsNullOrEmpty(AppUser.Phone))
     {
         AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Phone), ErrorCode.PhoneEmpty);
     }
     else if (AppUser.Phone.Length > 255)
     {
         AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Phone), ErrorCode.PhoneOverLength);
     }
     return(AppUser.IsValidated);
 }
Example #4
0
 public async Task <bool> ValidateDisplayName(AppUser AppUser)
 {
     if (string.IsNullOrWhiteSpace(AppUser.DisplayName))
     {
         AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.DisplayName), ErrorCode.DisplayNameEmpty);
     }
     else if (AppUser.DisplayName.Length > 255)
     {
         AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.DisplayName), ErrorCode.DisplayNameOverLength);
     }
     return(AppUser.IsValidated);
 }
Example #5
0
 private async Task <bool> ValidateSex(AppUser AppUser)
 {
     if (AppUser.SexId != Enums.SexEnum.MALE.Id && AppUser.SexId != Enums.SexEnum.FEMALE.Id)
     {
         AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Sex), ErrorCode.SexEmpty);
     }
     return(AppUser.IsValidated);
 }
Example #6
0
        public async Task <bool> ValidateUsername(AppUser AppUser)
        {
            if (string.IsNullOrWhiteSpace(AppUser.Username))
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameEmpty);
            }
            else
            {
                var Code = AppUser.Username;
                if (AppUser.Username.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(AppUser.Username))
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameHasSpecialCharacter);
                }
                else if (AppUser.Username.Length > 255)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameOverLength);
                }
                AppUserFilter AppUserFilter = new AppUserFilter
                {
                    Skip = 0,
                    Take = 10,
                    Id   = new IdFilter {
                        NotEqual = AppUser.Id
                    },
                    Username = new StringFilter {
                        Equal = AppUser.Username
                    },
                    Selects = AppUserSelect.Username
                };

                int count = await UOW.AppUserRepository.Count(AppUserFilter);

                if (count != 0)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameExisted);
                }
            }

            return(AppUser.IsValidated);
        }
Example #7
0
        public async Task <bool> ValidateEmail(AppUser AppUser)
        {
            if (string.IsNullOrWhiteSpace(AppUser.Email))
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Email), ErrorCode.EmailEmpty);
            }
            else if (!IsValidEmail(AppUser.Email))
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Email), ErrorCode.EmailInvalid);
            }
            else
            {
                if (AppUser.Email.Length > 255)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Email), ErrorCode.EmailOverLength);
                }
                AppUserFilter AppUserFilter = new AppUserFilter
                {
                    Skip = 0,
                    Take = 10,
                    Id   = new IdFilter {
                        NotEqual = AppUser.Id
                    },
                    Email = new StringFilter {
                        Equal = AppUser.Email
                    },
                    Selects = AppUserSelect.Email
                };

                int count = await UOW.AppUserRepository.Count(AppUserFilter);

                if (count != 0)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Email), ErrorCode.EmailExisted);
                }
            }
            return(AppUser.IsValidated);
        }
Example #8
0
        public async Task <bool> Login(AppUser AppUser)
        {
            if (string.IsNullOrWhiteSpace(AppUser.Username))
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameNotExisted);
                return(false);
            }
            List <AppUser> AppUsers = await UOW.AppUserRepository.List(new AppUserFilter
            {
                Skip     = 0,
                Take     = 1,
                Username = new StringFilter {
                    Equal = AppUser.Username
                },
                Selects = AppUserSelect.ALL,
            });

            if (AppUsers.Count == 0)
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameNotExisted);
            }
            else
            {
                AppUser appUser = AppUsers.FirstOrDefault();
                bool    verify  = VerifyPassword(appUser.Password, AppUser.Password);
                if (verify == false)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Password), ErrorCode.PasswordNotMatch);
                }
                else
                {
                    AppUser.Id = appUser.Id;
                }
            }
            return(AppUser.IsValidated);
        }
Example #9
0
        public async Task <bool> ValidateOrganization(AppUser AppUser)
        {
            if (AppUser.ERouteScopeId.HasValue)
            {
                OrganizationFilter OrganizationFilter = new OrganizationFilter
                {
                    Id = new IdFilter {
                        Equal = AppUser.ERouteScopeId
                    }
                };

                var count = await UOW.OrganizationRepository.Count(OrganizationFilter);

                if (count == 0)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.ERouteScope), ErrorCode.ERouteScopeNotExisted);
                }
            }
            return(AppUser.IsValidated);
        }
Example #10
0
        private async Task <bool> ValidateId(AppUser AppUser)
        {
            AppUserFilter AppUserFilter = new AppUserFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = AppUser.Id
                },
                Selects = AppUserSelect.Id
            };

            int count = await UOW.AppUserRepository.Count(AppUserFilter);

            if (count == 0)
            {
                AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Id), ErrorCode.IdNotExisted);
            }
            return(AppUser.IsValidated);
        }
Example #11
0
        public async Task <bool> ForgotPassword(AppUser AppUser)
        {
            if (AppUser != null && !string.IsNullOrWhiteSpace(AppUser.Email))
            {
                AppUserFilter AppUserFilter = new AppUserFilter
                {
                    Email = new StringFilter {
                        Equal = AppUser.Email
                    },
                };

                int count = await UOW.AppUserRepository.Count(AppUserFilter);

                if (count == 0)
                {
                    AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Email), ErrorCode.EmailNotExisted);
                }
            }

            return(AppUser.IsValidated);
        }