Exemplo n.º 1
0
        /// <summary>
        /// Sends the user registered notification.
        /// </summary>
        /// <param name="user">The user.</param>
        public static void SendUserRegisteredNotification(string userName)
        {
            if (userName == "")
                throw new ArgumentNullException("user");

            EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text);
            MembershipUser user = ITUser.GetUser(userName);
            WebProfile profile = new WebProfile().GetProfile(user.UserName);

            //load notification plugins
            NotificationManager nm = new NotificationManager(type);
            nm.LoadNotificationTypes();

            //load template and replace the tokens
            string template = nm.LoadEmailNotificationTemplate("UserRegistered");
            string subject = nm.LoadNotificationTemplate("UserRegisteredSubject");
            Dictionary<string, object> data = new Dictionary<string, object>();

            ITUser u = new ITUser()
            {
                CreationDate = user.CreationDate,
                Email = user.Email,
                UserName = user.UserName,
                DisplayName = new WebProfile().GetProfile(user.UserName).DisplayName,
                IsApproved = user.IsApproved
            };

            data.Add("User", u);
            template = nm.GenerateNotificationContent(template, data);

            //all admin notifications sent to admin user defined in host settings,
            string AdminNotificationUsername = HostSetting.GetHostSetting("AdminNotificationUsername");

            nm.SendNotification(AdminNotificationUsername, subject, template);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the user new password notification.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="newPassword">The new password.</param>
        public static void SendUserNewPasswordNotification(MembershipUser user, string newPassword)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text);
            NotificationManager nm = new NotificationManager(type);
            nm.LoadNotificationTypes();

            //load template and replace the tokens
            string template = nm.LoadEmailNotificationTemplate("PasswordReset");
            string subject = nm.LoadNotificationTemplate("PasswordResetSubject");
            string displayname = ITUser.GetUserDisplayName(user.UserName);
            Dictionary<string, object> data = new Dictionary<string, object>();

            ITUser u = new ITUser()
            {
                CreationDate = user.CreationDate,
                Email = user.Email,
                UserName = user.UserName,
                DisplayName = new WebProfile().GetProfile(user.UserName).DisplayName,
                IsApproved = user.IsApproved
            };

            data.Add("User", u);
            data.Add("Password", newPassword);
            template = nm.GenerateNotificationContent(template, data);
            nm.SendNotification(user.UserName, subject, template);
        }