Exemplo n.º 1
0
        private void OnConfirmButton_TouchUpInside(object sender, EventArgs e)
        {
            if (_inputType == InputType.Email)
            {
                _textField.Text = StringUtils.RemoveWhiteSpaces(_textField.Text);

                if (EmailUtils.IsValidEmail(_textField.Text))
                {
                    _positiveButton.Invoke(_textField.Text);
                    Dismiss();
                }
                else
                {
                    _indicatorView.BackgroundColor = Colors.Red;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(_textField.Text))
                {
                    _positiveButton.Invoke(_textField.Text);
                    Dismiss();
                }
                else
                {
                    _indicatorView.BackgroundColor = Colors.Red;
                }
            }
        }
Exemplo n.º 2
0
        public async Task SendEmail([FromRoute] EmailSend parameters)
        {
            var emlNode = await _alfrescoHttpClient.GetNodeInfo(parameters.NodeId, ImmutableList <Parameter> .Empty
                                                                .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

            if (emlNode?.Entry?.Path?.Name.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomEmail, StringComparison.OrdinalIgnoreCase) == false)
            {
                throw new BadRequestException("", "Node is not in Mailroom");
            }

            var emailProperties = emlNode.Entry.Properties.As <JObject>().ToDictionary();

            if (emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailSender) == null)
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_NO_SENDER);
            }

            if (emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailRecipient) == null)
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_NO_RECIPIENT);
            }

            string senderEmail    = emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailSender).ToString();
            string recipientEmail = emailProperties.GetNestedValueOrDefault(SpisumNames.Properties.EmailRecipient).ToString();

            if (!EmailUtils.IsValidEmail(senderEmail))
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_INVALID_SENDER);
            }
            if (!EmailUtils.IsValidEmail(recipientEmail))
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_INVALID_RECIPIENT);
            }

            var emailConfiguration = (await _emailHttpClient.Accounts())?.FirstOrDefault(x => x?.Username?.ToLower() == recipientEmail?.ToLower());

            if (emailConfiguration == null)
            {
                throw new BadRequestException(ErrorCodes.V_EMAIL_NO_CONFIGURATION);
            }

            if (emlNode?.Entry?.Path?.Name?.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomEmailUnprocessed) != true)
            {
                throw new BadRequestException("", "Node is not in expected path");
            }

            await _emailHttpClient.Send(senderEmail, emailConfiguration.Username, parameters.Subject, parameters.Body, parameters.Files);

            // Move eml and children
            await _nodesService.MoveChildrenByPath(emlNode.Entry.Id, SpisumNames.Paths.MailRoomEmailNotRegistered);

            await _alfrescoHttpClient.UpdateNode(parameters.NodeId, new NodeBodyUpdate
            {
                Properties = new Dictionary <string, object>
                {
                    { SpisumNames.Properties.EmailNotRegisteredReason, "EM_VAL_01" }
                }
            }
                                                 );
        }
Exemplo n.º 3
0
        public static Usuario LlenarUsuario(Usuario usuario)
        {
            Console.Write("Correo: ");
            string cor = usuario.Correo = Console.ReadLine();

            if (EmailUtils.IsValidEmail(cor))
            {
                Console.WriteLine("Correo valido");
            }
            else
            {
                Console.Clear();
                LlenarUsuarioInvalido();
            }
            Console.WriteLine("Escriba una contraseña con al menos un numero y minimo 8 caracteres");
            Console.Write("Contraseña: ");
            string c = usuario.Contrasena = Console.ReadLine();

            if (ContraseñaUtils.IsValiPassword(c) == true)
            {
                Console.Clear();
                LlenarUsuarioInvalido();
            }
            usuario.Contrasena = Seguridad.Encriptar(usuario.Contrasena);
            return(usuario);
        }
Exemplo n.º 4
0
        private bool CheckForm(UserRegistrationRequestModel user)
        {
            if (ReflectionHelper.HasEmptyOrNullValues(user))
            {
                _dialogService.ShowAlert(EmptyForm, AlertType.Error);
                return(false);
            }

            if (!StringUtils.CheckForEmojis(user.Password) || !StringUtils.CheckForEmojis(user.FirstName) || !StringUtils.CheckForEmojis(user.LastName))
            {
                _dialogService.ShowAlert(DamnEmojis, AlertType.Error, 6f);
                return(false);
            }

            if (!StringUtils.IsLettersOnly(user.FirstName) || !StringUtils.IsLettersOnly(user.LastName))
            {
                _dialogService.ShowAlert(InvalidString, AlertType.Error, 6.5f);
                return(false);
            }

            if (!EmailUtils.IsValidEmail(StringUtils.RemoveWhiteSpaces(user.Email)))
            {
                _dialogService.ShowAlert(InvalidEmail, AlertType.Error);
                return(false);
            }

            if (user.Password.Length < 8)
            {
                _dialogService.ShowAlert(PasswordWeak, AlertType.Error, 6f);
                return(false);
            }

            if (user.Password != FormModelList[4].TextFieldValue)
            {
                _dialogService.ShowAlert(PasswordMatch, AlertType.Error, 3.5f);
                return(false);
            }

            if (user.Phone.Length > 16 || user.Phone.Length < 8)
            {
                _dialogService.ShowAlert(AlertPhoneNumber, AlertType.Error, 3.5f);
                return(false);
            }

            if (!_userAgreed)
            {
                _dialogService.ShowAlert(UserAgreement, AlertType.Error);
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        private bool ValidateInputs()
        {
            if (usernameTextBox.Text.Trim().Length < 4)
            {
                OnValidating("* Username must be a least 4 chars");
                return(false);
            }

            if (userPasswordTextBox.Text.Trim().Length < 6)
            {
                OnValidating("* StoredPassword must be a least 6 chars");
                return(false);
            }

            if (string.IsNullOrWhiteSpace(userCinTextBox.Text))
            {
                OnValidating("* CIN is required");
                return(false);
            }

            if (string.IsNullOrWhiteSpace(userFirstNameTextBox.Text))
            {
                OnValidating("* First Name is required");
                return(false);
            }

            if (string.IsNullOrWhiteSpace(userFirstNameTextBox.Text))
            {
                OnValidating("* Last Name is required");
                return(false);
            }

            if (!EmailUtils.IsValidEmail(userEmailTextBox.Text))
            {
                OnValidating("* Email address not valid");
                return(false);
            }

            if (userPhoneTextBox.Text.Trim().Length != 14)
            {
                OnValidating("*Phone number is not valid");
                return(false);
            }


            return(true);
        }
Exemplo n.º 6
0
        public ShipmentUpdateEmailValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService, IEmailHttpClient emailHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _nodeParents = await nodesService.GetParentsByAssociation(context.NodeId, new List <string>
                {
                    SpisumNames.Associations.ShipmentsCreated,
                    SpisumNames.Associations.ShipmentsToReturn,
                    SpisumNames.Associations.ShipmentsToDispatch
                });
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                try { _accounts = await emailHttpClient.Accounts(); } catch { }


                if (_nodeParents?.Any(x => x?.Entry?.Association?.AssocType == SpisumNames.Associations.ShipmentsToDispatch) ?? false)
                {
                    _groupToDispatch = await alfrescoHttpClient.GetGroupMembers(SpisumNames.Groups.DispatchGroup,
                                                                                ImmutableList <Parameter> .Empty.Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));
                }

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null && _nodeParents != null && _accounts != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.ShipmentEmail)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.ShipmentEmail}");

                RuleFor(x => x)
                .Must(y => _nodeParents?.Any(q => q.Entry.NodeType == SpisumNames.NodeTypes.Document) ?? false)
                .WithName(x => "Parent")
                .WithMessage($"Provided shipment does not have a parent type of {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x)
                .Must(y => CheckDispatchGroup(identityUser.RequestGroup))
                .WithMessage(x => "Dispatch group")
                .WithMessage($"Requested group in not part of {SpisumNames.Groups.DispatchGroup}");

                RuleFor(x => x)
                .Must(x => _accounts.Count > 0)
                .WithMessage(x => "No email configuration on email server");

                RuleFor(x => x.Body.Sender)
                .Must(y => _accounts?.Any(x => x.Username == y) ?? false)
                .WithMessage(x => "Sender was not found in email configuration on email server");
            });

            RuleFor(x => x.Body.Recipient)
            .Must(x => EmailUtils.IsValidEmail(x))
            .When(x => x.Body != null)
            .WithName(x => "Recipient")
            .WithMessage("Recipient is not a valid email address");

            RuleFor(x => x.Body.Subject)
            .Must(x => CheckLength(x, 255))
            .When(x => x.Body != null)
            .WithName(x => "Subject")
            .WithMessage("Subject is too long");

            RuleFor(x => x.Body.Recipient)
            .Must(x => CheckLength(x, 254))
            .When(x => x.Body != null)
            .WithName(x => "Recipient")
            .WithMessage("Recipient is too long");

            RuleFor(x => x.Body.Components)
            .Must(y => y.Count > 0)
            .WithName(x => "Components")
            .WithMessage("Components cannot be empty");
        }
        public ShipmentCreateEmailValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, IEmailHttpClient emailHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                try { _accounts = await emailHttpClient.Accounts(); } catch { }

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null && _accounts != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));

                RuleFor(x => x)
                .Must(x => _accounts.Count > 0)
                .WithMessage(x => "No email configuration on email server");

                RuleFor(x => x.Body.Sender)
                .Must(y => _accounts?.Any(x => x.Username == y) ?? false)
                .WithMessage(x => "Sender was not found in email configuration on email server");
            });

            RuleFor(x => x.Body.Recipient)
            .Must(x => EmailUtils.IsValidEmail(x))
            .When(x => x.Body != null)
            .WithName(x => "Recipient")
            .WithMessage("Recipient is not a valid email address");

            RuleFor(x => x.Body.Subject)
            .Must(x => CheckSubjectLenght(x))
            .When(x => x.Body != null)
            .WithName(x => "Subject")
            .WithMessage("Subject is too long");

            RuleFor(x => x.Body.Recipient)
            .Must(x => CheckRecipientLenght(x))
            .When(x => x.Body != null)
            .WithName(x => "Recipient")
            .WithMessage("Recipient is too long");

            RuleFor(x => x.Body.Components)
            .Must(y => y?.Count > 0)
            .When(x => x.Body != null)
            .WithName(x => "Components")
            .WithMessage("Components cannot be empty");
        }