Esempio n. 1
0
        /// <summary>
        /// Executes the confirmation email job
        /// </summary>
        /// <param name="priorityEmailCargo">Cargo for confirmation email</param>
        public void Handle(PriorityEmailCargo priorityEmailCargo)
        {
            ConfirmationEmailCargo confirmationEmailCargo = priorityEmailCargo as ConfirmationEmailCargo;

            if (confirmationEmailCargo != null)
            {
                Log.Verbose("Starting Confirmation email job : {0}", confirmationEmailCargo.ToString());
                EnvironmentType azureEnvironment;
                if (Enum.TryParse(_environment, true, out azureEnvironment))
                {
                    EmailConfirmationContract emailConfirmationContract = new EmailConfirmationContract();
                    EmailRenderingClient <EmailConfirmationContract> emailRenderingClient = new EmailRenderingClient <EmailConfirmationContract>();
                    switch (confirmationEmailCargo.EntityType)
                    {
                    case EntityType.AuthenticatedEmailAddress:
                        emailConfirmationContract.ConfirmationUrl     = ConfirmationLinkGenerator.GetLink(confirmationEmailCargo.UserIdHash, confirmationEmailCargo.ConfirmationCode, EntityType.AuthenticatedEmailAddress, azureEnvironment).AbsoluteUri;
                        emailRenderingClient.EmailRenderingServiceUrl = this._authenticatedEmailConfirmationTemplateUrl;
                        break;

                    case EntityType.UnAuthenticatedEmailAddress:
                        emailConfirmationContract.ConfirmationUrl     = ConfirmationLinkGenerator.GetLink(confirmationEmailCargo.UserIdHash, confirmationEmailCargo.ConfirmationCode, EntityType.UnAuthenticatedEmailAddress, azureEnvironment).AbsoluteUri;
                        emailRenderingClient.EmailRenderingServiceUrl = this._unauthenticatedEmailConfirmationTemplateUrl;
                        break;

                    case EntityType.AccountLink:
                        emailConfirmationContract.ConfirmationUrl     = ConfirmationLinkGenerator.GetLink(confirmationEmailCargo.UserIdHash, confirmationEmailCargo.ConfirmationCode, EntityType.AccountLink, azureEnvironment).AbsoluteUri;
                        emailRenderingClient.EmailRenderingServiceUrl = this._linkEmailAccountTemplateUrl;
                        break;

                    default:
                        throw new InvalidEntityTypeException("Unknown entity type in Confirmation Emailcargo");
                    }
                    EmailContent emailContent = new EmailContent
                    {
                        From        = this._confirmationFromAddress,
                        FromDisplay = this._confirmationFromDisplayName,
                        Subject     = confirmationEmailCargo.EntityType == EntityType.AccountLink ? this._alinkConfirmationSubject : this._confirmationEmailSubject,
                        HtmlBody    = emailRenderingClient.RenderHtml(emailConfirmationContract),
                        Category    = this._confirmationEmailCategory
                    };
                    SendEmailRequest request = new SendEmailRequest
                    {
                        Content = emailContent,
                        ToList  = new List <string> {
                            confirmationEmailCargo.EmailAddress
                        }
                    };

                    Log.Verbose("Sending email for the email job : {0}", confirmationEmailCargo.ToString());

                    // Send the email
                    this._userServicesClient.SendEmail(confirmationEmailCargo.Id, request, null);

                    Log.Verbose("Successfully sent email for the email job : {0}", confirmationEmailCargo.ToString());
                }
            }
            else
            {
                Log.Error("Error in executing confirmation email job : Invalid priority email cargo");
            }
        }
        /// <summary>
        /// Get the link to be embedded in auth email if necessary.
        /// </summary>
        /// <param name="entityType">
        /// Entity Type for link generation
        /// </param>
        /// <param name="user">
        /// User object
        /// </param>
        /// <param name="environmentType">
        /// Environment Type
        /// </param>
        /// <returns>
        /// Returns the Uri.
        /// </returns>
        private static Uri LinkingOrVerificationUrl(EntityType entityType, User user, IUsersDal dal, EnvironmentType environmentType)
        {
            Tuple <string, int> confirmationCodeTuple = dal.CreateConfirmationCode(user, entityType);

            return(ConfirmationLinkGenerator.GetLink(confirmationCodeTuple.Item1, confirmationCodeTuple.Item2, entityType, environmentType));
        }