예제 #1
0
        private void ValidateUserLoginRequest(UserSignInRequest request)
        {
            ValidationException exception = new ValidationException();

            if (request == null)
            {
                exception.Add(new ValidationError("common.invalidRequest"));
            }

            if (string.IsNullOrWhiteSpace(request.Email))
            {
                exception.Add(new ValidationError("registration.signin.validation.emailRequired"));
            }

            if (string.IsNullOrWhiteSpace(request.Pwd))
            {
                exception.Add(new ValidationError("registration.signin.validation.pwdRequired"));
            }

            IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>();
            User            userProfile    = userRepository.GetByEmail(request.Email);

            if (userProfile == null || EncodeHelper.EncodePassword(request.Pwd) != userProfile.Password)
            {
                exception.Add(new ValidationError("registration.signin.validation.invalidEmailOrPwd"));
            }

            exception.ThrowIfError();
        }
        public static IValidationException Validate(object obj)
        {
            IValidationException ex = new ValidationException();

            if (obj == null)
            {
                ex.Add(new ValidationError("common.error.objectIsNull"));
                return(ex);
            }

            foreach (ValidationRequest request in ObjectHelper.GetPropertyAttributes <BaseAttribute>(obj))
            {
                if (request.Validator == null || request.Validator.IsValid(request))
                {
                    continue;
                }
                ex.Add(new ValidationError(request.Validator.MessageKey));
            }

            return(ex);
        }
        public async Task <IActionResult> AuthenticateUser(string UserName, string Password)
        {
            ValidationException validationException = new ValidationException();

            validationException.Add(nameof(UserName), UserName, ValidationReason.Required);
            validationException.Add(nameof(Password), Password, ValidationReason.Required);
            validationException.Add(nameof(UserName), UserName, ValidationReason.Username);
            validationException.Add(nameof(Password), Password, ValidationReason.PasswordFormat);
            if (validationException.HasErrors)
            {
                throw validationException;
            }

            var result = await _userService.Authenticate(UserName, Password, new int[] { (int)UserRoleEnum.Vendor });

            if (result.NoContent)
            {
                return(Unauthorized());
            }

            return(Ok(result));
        }
        public async Task <IActionResult> RegisterVendor(RegisterVendorRequestModel vendorDetailsRequestModel)
        {
            ValidationException validationException = new ValidationException();

            validationException.Add(nameof(vendorDetailsRequestModel.VendorName), vendorDetailsRequestModel.VendorName, ValidationReason.Required);
            validationException.Add(nameof(vendorDetailsRequestModel.VendorEmail), vendorDetailsRequestModel.VendorEmail, ValidationReason.Required);
            validationException.Add(nameof(vendorDetailsRequestModel.VendorMobile), vendorDetailsRequestModel.VendorMobile, ValidationReason.Required);
            validationException.Add(nameof(vendorDetailsRequestModel.AddressLine), vendorDetailsRequestModel.AddressLine, ValidationReason.Required);
            validationException.Add(nameof(vendorDetailsRequestModel.City), vendorDetailsRequestModel.City, ValidationReason.Required);
            validationException.Add(nameof(vendorDetailsRequestModel.State), vendorDetailsRequestModel.State, ValidationReason.Required);
            validationException.Add(nameof(vendorDetailsRequestModel.PinCode), vendorDetailsRequestModel.PinCode, ValidationReason.Required);
            validationException.Add(nameof(vendorDetailsRequestModel.VendorEmail), vendorDetailsRequestModel.VendorEmail, ValidationReason.EmailFormat);
            validationException.Add(nameof(vendorDetailsRequestModel.VendorMobile), vendorDetailsRequestModel.VendorMobile, ValidationReason.PhoneNumber);
            validationException.Add(nameof(vendorDetailsRequestModel.PinCode), vendorDetailsRequestModel.PinCode, ValidationReason.PinCode);

            if (validationException.HasErrors)
            {
                throw validationException;
            }

            return(Ok(await _vendorAuthenticationManager.RegisterVendor(vendorDetailsRequestModel)));
        }
        //[TypeFilter(typeof(AccessAttribute), Arguments = new object[] { ModuleName.VendorRequestedRegistration, ModuleActionType.Edit })]
        public async Task <IActionResult> ConfirmRegistration(int vendorId)
        {
            ValidationException validationException = new ValidationException();

            validationException.Add(nameof(vendorId), vendorId, ValidationReason.GreaterThanZero);

            if (validationException.HasErrors)
            {
                throw validationException;
            }

            return(Ok(await _vendorManager.ConfirmRegistration(vendorId)));
        }
예제 #6
0
        public async Task <IActionResult> AuthenticateUser([ModelBinder(typeof(FromEncryptedRouteAttribute))] string UserName, [ModelBinder(typeof(FromEncryptedRouteAttribute))] string Password)
        {
            ValidationException validationException = new ValidationException();

            validationException.Add(nameof(UserName), UserName, ValidationReason.Required);
            validationException.Add(nameof(Password), Password, ValidationReason.Required);
            validationException.Add(nameof(UserName), UserName, ValidationReason.Username);
            validationException.Add(nameof(Password), Password, ValidationReason.PasswordFormat);
            if (validationException.HasErrors)
            {
                throw validationException;
            }

            int[] roles  = new int[] { (int)UserRoleEnum.Admin, (int)UserRoleEnum.SuperAdmin };
            var   result = await _userService.Authenticate(UserName, Password, roles);

            if (result.NoContent)
            {
                return(Unauthorized());
            }

            return(Ok(result));
        }