Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Organization.setCurrent())
            {
                Response.Redirect(LiftContext.Redirect);
            }
            //-------------------------------------------------------------------------
            //-- do the language setting for the SUBMIT button here
            //-- (unable to place <%=LiftDomain.Language.Current.SHARED_SUBMIT %> in asp:Button Text field)
            //-------------------------------------------------------------------------
            this.submitBtn.Text = LiftDomain.Language.Current.SHARED_SUBMIT;

            if (IsPostBack)
            {
                try
                {
                    //TODO: ??? HOW DO WE VALIDATE THE FORM FIELD DATA (required, max length, valid e-mail address, dangerous content?, etc.)

                    //-------------------------------------------------------------------------
                    //-- get the information entered on the web form
                    //-- and send it in an e-mail to the organization point of contact
                    //-------------------------------------------------------------------------
                    //-- (org_email and org_appearance will specify recipients and smtp settings)
                    //-------------------------------------------------------------------------

                    //YOUR NAME: = contact_from.Text;
                    //YOUR EMAIL: = contact_from_email.Text;
                    //SUBJECT: = contact_subject.Text;
                    //MESSAGE: = contact_message.Text;

                    Organization currentOrganization = Organization.Current;

                    LiftCommon.Email emailHelper = new LiftCommon.Email();

                    //email.replyTo = thisOrgEmail.emailReplyTo;  // not supported yet

                    emailHelper.from = "*****@*****.**";

                    //-------------------------------------------------------------------------
                    //-- get list of all users for the current organization
                    //-------------------------------------------------------------------------
                    LiftDomain.User thisUserList = new LiftDomain.User();
                    thisUserList["search"] = currentOrganization.id.Value;
                    DataSet userListSet = thisUserList.doQuery("SearchUsersByOrg");

                    foreach (DataRow dr in userListSet.Tables[0].Rows)
                    {
                        string email = dr["email"].ToString();

                        if (!String.IsNullOrEmpty(email))
                        {
                            //TODO: ??? VALIDATE THAT THE EMAIL ADDRESS IS A VALID EMAIL ADDRESS FORMAT ???

                            emailHelper.addTo(email);
                        }
                    }

                    emailHelper.subject = email_subject.Text;   // field from the form
                    emailHelper.Body    = email_message.Text;   // field from the form

                    //email.MIME = MIME.Text | MIME.HTML;  // just supposing that it supports multiple formats. May not be necessary

                    emailHelper.send();

                    //TODO: ??? WHERE DO WE REDIRECT TO ???
                    //Response.Redirect("Requests.aspx");
                }
                catch (Exception x)
                {
                    //TODO: ??? WHAT DO WE DO IF THE E-MAIL PROCESS FAILS
                    string m = x.Message;
                    System.Diagnostics.Debug.Print("[" + DateTime.Now.ToString() + "] *** ERROR SENDING E-MAIL: " + m);
                }
                finally
                {
                }
            }
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Organization.setCurrent())
            {
                Response.Redirect(LiftContext.Redirect);
            }
            //-------------------------------------------------------------------------
            //-- do the language setting for the SUBMIT button here
            //-- (unable to place <%=LiftDomain.Language.Current.SHARED_SUBMIT %> in asp:Button Text field)
            //-------------------------------------------------------------------------
            this.submitBtn.Text = LiftDomain.Language.Current.SHARED_SUBMIT;

            string emailMessageBody = string.Empty;

            if (IsPostBack)
            {
                try
                {
                    //TODO: ??? HOW DO WE VALIDATE THE FORM FIELD DATA (required, max length, valid e-mail address, dangerous content?, etc.)

                    //-------------------------------------------------------------------------
                    //-- get the information entered on the web form
                    //-- and send it in an e-mail to the organization point of contact
                    //-------------------------------------------------------------------------
                    //-- (org_email and org_appearance will specify recipients and smtp settings)
                    //-------------------------------------------------------------------------

                    //YOUR NAME: = contact_from.Text;
                    //YOUR EMAIL: = contact_from_email.Text;
                    //SUBJECT: = contact_subject.Text;
                    //MESSAGE: = contact_message.Text;

                    Organization currentOrganization = Organization.Current;
                    OrgEmail     thisOrgEmail        = currentOrganization.getOrgEmail("email.contact_us");

                    LiftCommon.Email emailHelper = new LiftCommon.Email();


                    //email.replyTo = thisOrgEmail.emailReplyTo;  // not supported yet

                    //TODO: ??? THIS NEEDS TO BE A VALID E-MAIL ADDRESS
                    if (Email.IsValidEmailAddress(contact_from_email.Text))
                    {
                        emailHelper.from = contact_from_email.Text;  // field from the form
                    }
                    else
                    {
                        //TODO: ??? HOW DO WE NOTIFY THE USER
                        Logger.log(Logger.Level.ERROR, this, "E-mail address '" + contact_from_email.Text + "' is not in a correct format [Contact.aspx].");
                        throw new ApplicationException("E-mail address '" + contact_from_email.Text + "' is not in a correct format [Contact.aspx].");
                    }

                    emailHelper.addTo(thisOrgEmail.email_to);
                    emailHelper.subject = contact_subject.Text;  // field from the form

                    emailMessageBody  = LiftDomain.Language.Current.CONTACTUS_YOUR_NAME + ":  " + contact_from.Text + "\r\n";
                    emailMessageBody += LiftDomain.Language.Current.CONTACTUS_YOUR_EMAIL + ":  " + contact_from_email.Text + "\r\n";
                    emailMessageBody += LiftDomain.Language.Current.CONTACTUS_MESSAGE + ":  \r\n";
                    emailMessageBody += contact_message.Text;   // field from the form

                    emailHelper.Body = emailMessageBody;

                    //email.MIME = MIME.Text | MIME.HTML;  // just supposing that it supports multiple formats. May not be necessary

                    emailHelper.send();

                    Response.Redirect("Requests.aspx");
                }
                catch (Exception x)
                {
                    //TODO: ??? WHAT DO WE DO IF THE E-MAIL PROCESS FAILS
                    string m = x.Message;
                    System.Diagnostics.Debug.Print("[" + DateTime.Now.ToString() + "] *** ERROR SENDING E-MAIL: " + m);
                }
                finally
                {
                }
            }
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string randomPassword = string.Empty;
            string saltValue      = string.Empty;
            int    ok             = 0;
            string targetEmail    = string.Empty;

            EmailValidator.ErrorMessage = LiftDomain.Language.Current.SHARED_MUST_BE_A_VALID_EMAIL_ADDRESS;

            if (!Organization.setCurrent())
            {
                Response.Redirect(LiftContext.Redirect);
            }

            try
            {
                //-------------------------------------------------------------------------
                //-- do the language setting for the SUBMIT button here
                //-- (unable to place <%=LiftDomain.Language.Current.SHARED_SUBMIT %> in asp:Button Text field)
                //-------------------------------------------------------------------------
                this.submitBtn.Text = LiftDomain.Language.Current.SHARED_SUBMIT.Value;

                string email = Request["email"];
                if (!string.IsNullOrEmpty(email))
                {
                    user_email.Text = email;
                }

                //-------------------------------------------------------------------------
                //-- do other language settings
                //-------------------------------------------------------------------------
                forgot_password_fieldset_legend = LiftDomain.Language.Current.FORGOT_PASSWORD_INSTRUCTIONS.Value;

                if (IsPostBack)
                {
                    //TODO: ???what if CAPTCHA validation fails???
                    //TODO: ???should we be doing validation checking in Page_Load or submitBtn_Click???
                    //if (Page.IsValid && (txtCaptcha.Text.ToString() == Session["captchaValue"].ToString()))
                    if (txtCaptcha.Text.ToString().Trim().ToUpper() == Session["captchaValue"].ToString().Trim().ToUpper())
                    {
                        //Response.Write("CAPTCHA verification succeeded");


                        //-------------------------------------------------------------------------
                        //-- validate given e-mail (required, valid e-mail)
                        //-------------------------------------------------------------------------

                        //-------------------------------------------------------------------------
                        //-- determine if user exists for given e-mail
                        //-------------------------------------------------------------------------
                        LiftDomain.User thisUserList = new LiftDomain.User();
                        thisUserList["search"] = user_email.Text;
                        userListSet            = thisUserList.doQuery("SearchUsersByEmail");

                        //TODO: ???what if multiple user records are found for the given email address???
                        if (userListSet.Tables[0].Rows.Count > 0)
                        {
                            LiftDomain.User thisUser = new LiftDomain.User();

                            thisUser.id.Value = Convert.ToInt32(userListSet.Tables[0].Rows[0]["id"]);
                            string username = userListSet.Tables[0].Rows[0]["username"].ToString();

                            //-------------------------------------------------------------------------
                            //-- create new random password for user
                            //-------------------------------------------------------------------------
                            randomPassword = LiftDomain.User.generatePassword();

                            //-------------------------------------------------------------------------
                            //-- update user record with new password
                            //-------------------------------------------------------------------------
                            thisUser.password_hash_type.Value = "md5";
                            saltValue = LiftDomain.User.generateRandomSalt();
                            thisUser.password_salt.Value              = saltValue;
                            thisUser.crypted_password.Value           = LiftDomain.User.hash(randomPassword, saltValue);
                            thisUser.last_password_changed_date.Value = LiftTime.CurrentTime;
                            thisUser.updated_at.Value = LiftTime.CurrentTime;

                            thisUser.id.Value = Convert.ToInt32(thisUser.doCommand("save"));

                            //-------------------------------------------------------------------------
                            //-- send new randomly-generated password to the given e-mail address
                            //-------------------------------------------------------------------------
                            LiftCommon.Email emailHelper = new LiftCommon.Email();
                            //email.replyTo = thisOrgEmail.emailReplyTo;  // not supported yet

                            emailHelper.from = Organization.Current.getFromEmail();

                            if (LiftCommon.Email.IsValidEmailAddress(user_email.Text))
                            {
                                targetEmail = user_email.Text;
                                try
                                {
                                    StringBuilder body = new StringBuilder();
                                    emailHelper.addTo(targetEmail);

                                    emailHelper.subject = LiftDomain.Language.Current.FORGOT_PASSWORD_NOTIFICATION_SUBJECT.Value;
                                    body.Append(LiftDomain.Language.Current.FORGOT_PASSWORD_NOTIFICATION_MESSAGE.Value);
                                    body.Append("\r\n");
                                    body.Append(LiftDomain.Language.Current.USER_EMAIL);
                                    body.Append("\t");
                                    body.Append(targetEmail);
                                    body.Append("\r\n");
                                    body.Append(LiftDomain.Language.Current.LOGIN_THE_NEW_PASSWORD);
                                    body.Append("\t");
                                    body.Append(randomPassword);
                                    body.Append("\r\n");
                                    emailHelper.Body = body.ToString();

                                    //email.MIME = MIME.Text | MIME.HTML;  // just supposing that it supports multiple formats. May not be necessary

                                    emailHelper.send();
                                    ok = 1;
                                }
                                catch
                                {
                                    ok = 0;
                                }
                            }
                        }
                    }
                    //-------------------------------------------------------------------------
                    //-- redirect to the "password has been reset, you should receive an e-mail" page
                    //-------------------------------------------------------------------------
                    Response.Redirect("PasswordReset.aspx?ok=" + ok.ToString() + "&e=" + targetEmail);
                }
                else
                {
                    //-------------------------------------------------------------------------
                    //-- first time on this page, so ...???
                    //-------------------------------------------------------------------------
                }
            }
            catch (Exception x)
            {
                //TODO: ??? WHAT DO WE DO IF THERE IS AN ERROR ???
                string m = x.Message;
                System.Diagnostics.Debug.Print("[" + DateTime.Now.ToString() + "] *** ERROR IN ForgotPassword.aspx.cs::Page_Load(): " + m);
                Logger.log("ForgotPassword.aspx.cs", x, "[" + DateTime.Now.ToString() + "] *** ERROR IN ForgotPassword.aspx.cs::Page_Load(): " + m);
                //Response.Write(m);
            }
            finally
            {
            }
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Organization.setCurrent())
            {
                Response.Redirect(LiftContext.Redirect);
            }

            PageAuthorized.check(Request, Response);

            string initialTimeZone        = "Central Standard Time";
            int    initialLanguageId      = 1; //-- 1 = English
            int    initialStatusId        = 0; //-- 0 = Unapproved; 1 = Approved
            string saltValue              = string.Empty;
            bool   sendOrgIsApprovedEmail = false;

            try
            {
                //-------------------------------------------------------------------------
                //-- do the language setting for the SUBMIT button here
                //-- (unable to place <%=LiftDomain.Language.Current.SHARED_SUBMIT %> in asp:Button Text field)
                //-------------------------------------------------------------------------
                this.submitBtn.Text = LiftDomain.Language.Current.SHARED_SUBMIT.Value;

                //-------------------------------------------------------------------------
                //-- do other language settings
                //-------------------------------------------------------------------------
                edit_organization_fieldset_legend = LiftDomain.Language.Current.ORGANIZATION_EDIT_ORGANIZATION.Value;

                LiftDomain.Organization thisOrganization = new LiftDomain.Organization();

                if (IsPostBack)
                {
                    //-------------------------------------------------------------------------
                    //-- get the object ID from the hidden id field on the page;
                    //-- if there is a object ID value, then we are editing an EXISTING object
                    //-------------------------------------------------------------------------
                    if (!String.IsNullOrEmpty(id.Value) && (id.Value != "0"))
                    {
                        thisOrganization.id.Value = int.Parse(id.Value);
                    }
                    else
                    {
                        //-------------------------------------------------------------------------
                        //-- if the object ID is blank or zero (0), then set some NEW object values (NOT id)
                        //-------------------------------------------------------------------------
                        thisOrganization.created_at.Value = LiftTime.CurrentTime;
                    }

                    //-------------------------------------------------------------------------
                    //-- transfer screen values to the object
                    //-------------------------------------------------------------------------
                    //TODO: ???what if data field validation fails??? // TO BE DONE IN JAVASCRIPT
                    //TODO: ???what if org title already exists??? // TO BE DONE IN JAVASCRIPT
                    //TODO: ???what if org subdomain already exists??? // TO BE DONE IN JAVASCRIPT
                    thisOrganization.title.Value          = organization_title.Text;
                    thisOrganization.user_id.Value        = 0; // LiftDomain.User.Current.id.Value;
                    thisOrganization.address.Value        = organization_address.Text;
                    thisOrganization.city.Value           = organization_city.Text;
                    thisOrganization.state_province.Value = organization_state.Text;
                    thisOrganization.postal_code.Value    = organization_postal_code.Text;
                    thisOrganization.phone.Value          = organization_phone.Text;
                    thisOrganization.subdomain.Value      = organization_subdomain.Text;
                    thisOrganization.time_zone.Value      = timezone_list.SelectedItem.Value;
                    thisOrganization.language_id.Value    = Convert.ToInt32(language_list.SelectedItem.Value);
                    thisOrganization.footer.Value         = organization_footer.Text;

                    thisOrganization.default_approval.Value = (default_approved.Checked ? 1 : 0);

                    thisOrganization.default_signup_mode.Value = (new_users_require_approval.Checked ? 1 : 0);


                    //-------------------------------------------------------------------------
                    //-- if the status changes from "Unapproved" to "Approved,"
                    //-- then we want to notify the organization's webmaster
                    //-------------------------------------------------------------------------
                    if (thisOrganization.id.Value != 0)
                    {
                        LiftDomain.Organization tempOrganization = new LiftDomain.Organization();
                        tempOrganization.id.Value = thisOrganization.id.Value;
                        tempOrganization          = tempOrganization.doSingleObjectQuery <LiftDomain.Organization>("select");

                        if ((tempOrganization.status == 0) && (Convert.ToInt32(language_list.SelectedItem.Value) == 1))
                        {
                            sendOrgIsApprovedEmail = true;
                        }
                    }
                    thisOrganization.status.Value = Convert.ToInt32(organization_status_list.SelectedItem.Value);

                    //-------------------------------------------------------------------------
                    //-- persist the object data to the database
                    //-------------------------------------------------------------------------
                    thisOrganization.id.Value = Convert.ToInt32(thisOrganization.doCommand("save"));

                    //id.Value = thisOrganization.id.Value.ToString();

                    //-------------------------------------------------------------------------
                    //-- send the approval email to the organization's webmaster
                    //-------------------------------------------------------------------------
                    if (sendOrgIsApprovedEmail)
                    {
                        LiftCommon.Email    emailHelper  = new LiftCommon.Email();
                        LiftDomain.OrgEmail thisOrgEmail = new LiftDomain.OrgEmail();
                        thisOrgEmail.organization_id.Value = thisOrganization.id.Value;
                        thisOrgEmail = thisOrgEmail.doSingleObjectQuery <LiftDomain.OrgEmail>("select");

                        //email.replyTo = thisOrgEmail.emailReplyTo;  // not supported yet

                        emailHelper.from = "*****@*****.**";

                        //TODO: ??? THIS NEEDS TO BE A VALID E-MAIL ADDRESS
                        if (LiftCommon.Email.IsValidEmailAddress(thisOrgEmail.webmaster_email_to.Value))
                        {
                            emailHelper.addTo(thisOrgEmail.webmaster_email_to.Value);
                        }
                        else
                        {
                            //TODO: ??? HOW DO WE NOTIFY THE USER
                            Logger.log(Logger.Level.ERROR, this, "E-mail address '" + thisOrgEmail.webmaster_email_to.Value + "' is not in a correct format [SignupOrganization.aspx].");
                            throw new ApplicationException("E-mail address '" + thisOrgEmail.webmaster_email_to.Value + "' is not in a correct format [SignupOrganization.aspx].");
                        }

                        emailHelper.subject = LiftDomain.Language.Current.SIGNUP_ORGANIZATION_APPROVAL_RESPONSE_SUBJECT.Value;
                        emailHelper.Body    = LiftDomain.Language.Current.SIGNUP_ORGANIZATION_APPROVAL_RESPONSE_MESSAGE.Value + "  " + thisOrganization.title.Value;

                        //email.MIME = MIME.Text | MIME.HTML;  // just supposing that it supports multiple formats. May not be necessary

                        emailHelper.send();
                    }

                    if (LiftDomain.User.Current.isSysAdmin)
                    {
                        //-------------------------------------------------------------------------
                        //-- return to the Organization List page
                        //-------------------------------------------------------------------------
                        if (Session["last_org_list_search"] != null)
                        {
                            Response.Redirect("OrganizationList.aspx?" + Session["last_org_list_search"]);
                        }
                        else
                        {
                            Response.Redirect("OrganizationList.aspx");
                        }
                    }
                    else
                    {
                        Response.Redirect("Admin.aspx");
                    }
                }
                else
                {
                    //-------------------------------------------------------------------------
                    //-- first time on this page, so get the organization ID from the ASP Request cache
                    //-------------------------------------------------------------------------
                    string idStr = Request["id"];

                    if (String.IsNullOrEmpty(idStr))
                    {
                        id.Value = "0";
                    }
                    else
                    {
                        id.Value = idStr;
                    }

                    thisOrganization.id.Value = Convert.ToInt32(id.Value);

                    //-------------------------------------------------------------------------
                    //-- if this is a NEW organization...
                    //-------------------------------------------------------------------------
                    if (id.Value == "0")
                    {
                        //-------------------------------------------------------------------------
                        //-- set default values
                        //-------------------------------------------------------------------------
                        initialTimeZone   = LiftDomain.Organization.Current.time_zone.Value;
                        initialLanguageId = LiftDomain.Organization.Current.language_id.Value;
                        initialStatusId   = 0; //-- 0 = Unapproved; 1 = Approved

                        title_label.Visible = false;
                        edit_organization_fieldset_legend = LiftDomain.Language.Current.ORGANIZATION_CREATE_A_NEW_ORGANIZATION.Value;

                        delete_organization_id        = string.Empty;
                        redirect_after_delete_to_page = string.Empty;
                    }

                    //-------------------------------------------------------------------------
                    //-- else, if this is an EXISTING organization...
                    //-------------------------------------------------------------------------
                    else
                    {
                        //-------------------------------------------------------------------------
                        //-- query database for data for this organization
                        //-------------------------------------------------------------------------
                        thisOrganization = thisOrganization.doSingleObjectQuery <LiftDomain.Organization>("select");

                        initialTimeZone   = thisOrganization.time_zone;
                        initialLanguageId = thisOrganization.language_id;
                        initialStatusId   = thisOrganization.status;

                        title_label.Text = LiftDomain.Language.Current.ORGANIZATION_EDITING_ORGANIZATION.Value + " " + thisOrganization.title;
                        edit_organization_fieldset_legend = LiftDomain.Language.Current.ORGANIZATION_EDIT_ORGANIZATION.Value;

                        delete_organization_id = id.Value;

                        if (Session["last_org_list_search"] != null)
                        {
                            redirect_after_delete_to_page = "OrganizationList.aspx?" + Session["last_org_list_search"];
                        }
                        else
                        {
                            redirect_after_delete_to_page = "OrganizationList.aspx";
                        }
                    }

                    //-------------------------------------------------------------------------
                    //-- populate the screen controls
                    //-------------------------------------------------------------------------
                    organization_title.Text       = thisOrganization.title;
                    organization_address.Text     = thisOrganization.address;
                    organization_city.Text        = thisOrganization.city;
                    organization_state.Text       = thisOrganization.state_province;
                    organization_postal_code.Text = thisOrganization.postal_code;
                    organization_phone.Text       = thisOrganization.phone;
                    organization_subdomain.Text   = thisOrganization.subdomain;
                    organization_footer.Text      = thisOrganization.footer;
                    if (thisOrganization.default_approval.Value == 1)
                    {
                        this.default_approved.Checked     = true;
                        this.default_not_approved.Checked = false;
                    }
                    else
                    {
                        this.default_approved.Checked     = false;
                        this.default_not_approved.Checked = true;
                    }

                    if (thisOrganization.default_signup_mode.Value == (int)UserSignupMode.user_create_account)
                    {
                        this.new_users_create_accounts.Checked  = true;
                        this.new_users_require_approval.Checked = false;
                    }
                    else
                    {
                        this.new_users_create_accounts.Checked  = false;
                        this.new_users_require_approval.Checked = true;
                    }

                    initTimeZoneList(initialTimeZone);
                    initLanguageList(initialLanguageId);
                    initOrganizationStatusList(initialStatusId);
                }
            }
            catch (Exception x)
            {
                //TODO: ??? WHAT DO WE DO IF THERE IS AN ERROR ???
                string m = x.Message;
                System.Diagnostics.Debug.Print("[" + DateTime.Now.ToString() + "] *** ERROR IN EditOrganization.aspx.cs::Page_Load(): " + m);
                Logger.log("EditOrganization.aspx.cs", x, "[" + DateTime.Now.ToString() + "] *** ERROR IN EditOrganization.aspx.cs::Page_Load(): " + m);
            }
            finally
            {
            }
        }