Example #1
0
        /// <summary>
        /// Send an e-mail to the users that are subscribed to new account notifications. These are specified in the
        /// usersToNotifyWhenAccountIsCreated configuration setting. If RequireEmailValidationForSelfRegisteredUser
        /// is enabled, do not send an e-mail at this time. Instead, it is sent when the user clicks the confirmation
        /// link in the e-mail.
        /// </summary>
        /// <param name="user">An instance of <see cref="UserEntity"/> that represents the newly created account.</param>
        /// <param name="isSelfRegistration">Indicates when the user is creating his or her own account. Set to false when an
        /// administrator creates an account.</param>
        /// <param name="isEmailVerified">If set to <c>true</c> the e-mail has been verified to be a valid, active e-mail address.</param>
        private static void NotifyAdminsOfNewlyCreatedAccount(UserEntity user, bool isSelfRegistration, bool isEmailVerified)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (isSelfRegistration && !isEmailVerified && Config.GetCore().RequireEmailValidationForSelfRegisteredUser)
            {
                return;
            }

            EmailTemplate emailTemplate;

            if (isSelfRegistration && Config.GetCore().RequireApprovalForSelfRegisteredUser)
            {
                emailTemplate = EmailController.GetEmailTemplate(EmailTemplateForm.AdminNotificationAccountCreatedRequiresApproval, user);
            }
            else
            {
                emailTemplate = EmailController.GetEmailTemplate(EmailTemplateForm.AdminNotificationAccountCreated, user);
            }

            foreach (string accountName in Config.GetCore().UsersToNotifyWhenAccountIsCreated.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                UserEntity account = GetUser(accountName, true);

                if (!String.IsNullOrEmpty(account.Email))
                {
                    MailAddress admin = new MailAddress(account.Email, account.UserName);
                    try
                    {
                        EmailController.SendEmail(admin, emailTemplate.Subject, emailTemplate.Body);
                    }
                    catch (WebException ex)
                    {
                        AppErrorController.LogError(ex);
                    }
                    catch (SmtpException ex)
                    {
                        AppErrorController.LogError(ex);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Send an e-mail to the user associated with the new account. This will be a verification e-mail if e-mail verification
        /// is enabled; otherwise it is a welcome message. The calling method should ensure that the <paramref name="user"/>
        /// has a valid e-mail configured before invoking this function.
        /// </summary>
        /// <param name="user">An instance of <see cref="UserEntity"/> that represents the newly created account.</param>
        private static void NotifyUserOfNewlyCreatedAccount(UserEntity user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            bool enableEmailVerification = Config.GetCore().RequireEmailValidationForSelfRegisteredUser;
            bool requireAdminApproval    = Config.GetCore().RequireApprovalForSelfRegisteredUser;

            if (enableEmailVerification)
            {
                EmailController.SendNotificationEmail(user, EmailTemplateForm.UserNotificationAccountCreatedNeedsVerification);
            }
            else if (requireAdminApproval)
            {
                EmailController.SendNotificationEmail(user, EmailTemplateForm.UserNotificationAccountCreatedNeedsApproval);
            }
            else
            {
                EmailController.SendNotificationEmail(user, EmailTemplateForm.UserNotificationAccountCreated);
            }
        }