Implements email-related tools.
Beispiel #1
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            lblSendResult.Text     = "";
            lblSendResult.CssClass = "";

            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            UserInfo loggedUser = SessionFacade.GetCurrentUser();

            Log.LogEntry("Sending Email to " + currentUser.Username, EntryType.General, loggedUser.Username);
            EmailTools.AsyncSendEmail(currentUser.Email,
                                      "\"" + Users.GetDisplayName(loggedUser) + "\" <" + Settings.SenderEmail + ">",
                                      txtSubject.Text,
                                      Users.GetDisplayName(loggedUser) + " sent you this message from " + Settings.WikiTitle + ". To reply, please go to " + Settings.MainUrl + "User.aspx?Username="******"&Subject=" + Tools.UrlEncode("Re: " + txtSubject.Text) + "\nPlease do not reply to this Email.\n\n------------\n\n" + txtBody.Text,
                                      false);
            lblSendResult.Text     = Properties.Messages.MessageSent;
            lblSendResult.CssClass = "resultok";

            txtSubject.Text = "";
            txtBody.Text    = "";
        }
Beispiel #2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Retrieve last error and log it, redirecting to Error.aspx (avoiding infinite loops)

            Exception ex = Server.GetLastError( );

            HttpException httpEx = ex as HttpException;

            if (httpEx != null)
            {
                // Try to redirect an inexistent .aspx page to a probably existing .ashx page
                if (httpEx.GetHttpCode( ) == 404)
                {
                    string page = Path.GetFileNameWithoutExtension(Request.PhysicalPath);
                    UrlTools.Redirect(page + Settings.PageExtension);
                    return;
                }
            }

            LogError(ex);
            string url = "";

            try
            {
                url = Tools.GetCurrentUrlFixed( );
            }
            catch { }
            EmailTools.NotifyError(ex, url);
            Session["LastError"] = Server.GetLastError( );
            if (!Request.PhysicalPath.ToLowerInvariant( ).Contains("error.aspx"))
            {
                UrlTools.Redirect("Error.aspx");
            }
        }
Beispiel #3
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (!Settings.UsersCanRegister)
            {
                return;
            }

            lblResult.Text     = "";
            lblResult.CssClass = "";

            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            // Ready to save the user
            Log.LogEntry("Account creation requested for " + txtUsername.Text, EntryType.General, Log.SystemUsername);
            Users.AddUser(txtUsername.Text, txtDisplayName.Text, txtPassword1.Text, txtEmail1.Text,
                          Settings.AccountActivationMode == AccountActivationMode.Auto, null);

            UserInfo newUser = Users.FindUser(txtUsername.Text);

            // Set membership to default Users group
            Users.SetUserMembership(newUser, new string[] { Settings.UsersGroup });

            if (Settings.AccountActivationMode == AccountActivationMode.Email)
            {
                string body = Settings.Provider.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null);
                body = body.Replace("##WIKITITLE##", Settings.WikiTitle).Replace("##USERNAME##", newUser.Username).Replace("##EMAILADDRESS##", Settings.ContactEmail);
                body = body.Replace("##ACTIVATIONLINK##", Settings.MainUrl + "Login.aspx?Activate=" + Tools.ComputeSecurityHash(newUser.Username, newUser.Email, newUser.DateTime) + "&Username="******"Account Activation - " + Settings.WikiTitle, body, false);
            }

            lblResult.CssClass  = "resultok";
            lblResult.Text      = "<br /><br />" + Properties.Messages.AccountCreated;
            btnRegister.Enabled = false;
            pnlRegister.Visible = false;
        }
Beispiel #4
0
        protected void btnSendBulkEmail_Click(object sender, EventArgs e)
        {
            lblEmailResult.CssClass = "";
            lblEmailResult.Text     = "";

            Page.Validate("email");
            if (!Page.IsValid)
            {
                return;
            }

            string        currentWiki = DetectWiki();
            List <string> emails      = new List <string>();

            foreach (ListItem item in lstGroups.Items)
            {
                if (item.Selected)
                {
                    UserGroup group = Users.FindUserGroup(currentWiki, item.Value);
                    if (group != null)
                    {
                        foreach (string user in group.Users)
                        {
                            UserInfo u = Users.FindUser(currentWiki, user);
                            if (u != null)
                            {
                                emails.Add(u.Email);
                            }
                        }
                    }
                }
            }

            EmailTools.AsyncSendMassEmail(emails.ToArray(), GlobalSettings.SenderEmail,
                                          txtSubject.Text, txtBody.Text, false);

            lblEmailResult.CssClass = "resultok";
            lblEmailResult.Text     = Properties.Messages.MassEmailSent;
        }