コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PageAuthorized.check(Request, Response);
            Organization.setCurrent();

            try
            {
                string idStr        = Request["id"];
                string userStateStr = Request["value"];

                int userState = Convert.ToInt32(userStateStr);

                LiftDomain.User u = new LiftDomain.User();
                u.id.Value    = Convert.ToInt32(idStr);
                u.state.Value = userState;

                userStatus = LiftDomain.User.getUserStatusDescription(userState);

                /* TODO - need a new method to change user status */
                u.doCommand("update_status");
            }
            catch
            {
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Organization.setCurrent())
            {
                Response.Redirect(LiftContext.Redirect);
            }

            PageAuthorized.check(Request, Response);

            idStr = Request["id"];
            if (!String.IsNullOrEmpty(idStr))
            {
                try
                {
                    int             id       = int.Parse(idStr);
                    LiftDomain.User thisUser = new LiftDomain.User();
                    thisUser.id.Value = id;
                    thisUser.doCommand("delete");

                    LiftDomain.RolesUser thisRolesUser = new LiftDomain.RolesUser();
                    thisRolesUser.user_id.Value = thisUser.id.Value;
                    thisRolesUser.doQuery("delete_roles_users_by_user_id");

                    Response.Redirect(Request["redirect_to_page"]);

                    //Response.ContentType = "text/javascript";
                }
                catch (Exception x)
                {
                    Logger.log(idStr, x, "Error deleting user");
                }
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            EmailValidator.ErrorMessage    = LiftDomain.Language.Current.SHARED_MUST_BE_A_VALID_EMAIL_ADDRESS;
            PasswordValidator.ErrorMessage = LiftDomain.Language.Current.SHARED_PASSWORDS_DO_NOT_MATCH;

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

            PageAuthorized.check(Request, Response);

            int      initialLanguageId = 1; //-- 1 = English
            string   initialTimeZone   = string.Empty;
            string   saltValue         = string.Empty;
            int      sumTotalRequests  = 0;
            TimeSpan sumPrayerSessionsDurationTimeSpan = new TimeSpan();

            //-------------------------------------------------------------------------
            //-- 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;
            this.submitBtnPassword.Text = LiftDomain.Language.Current.SHARED_CHANGE;
            this.submitBtnTimeZone.Text = LiftDomain.Language.Current.SHARED_CHANGE;

            LiftDomain.User thisUser = new LiftDomain.User();

            if (IsPostBack)
            {
                //-------------------------------------------------------------------------
                //-- transfer screen values to the object
                //-------------------------------------------------------------------------
                thisUser.id.Value = int.Parse(id.Value);

                thisUser.login.Value          = login.Text;
                thisUser.first_name.Value     = first_name.Text;
                thisUser.last_name.Value      = last_name.Text;
                thisUser.email.Value          = email.Text;
                thisUser.address.Value        = address.Text;
                thisUser.city.Value           = city.Text;
                thisUser.state_province.Value = state_province.Text;
                thisUser.postal_code.Value    = postal_code.Text;
                thisUser.phone.Value          = phone.Text;

                thisUser.language_id.Value = Convert.ToInt32(language_list.SelectedItem.Value);

                //TODO: ???what if passwords do not match??? // TO BE DONE IN JAVASCRIPT
                //(user_password.Text != user_password_confirmation.Text)

                if (!String.IsNullOrEmpty(user_password.Text.Trim()))
                {
                    thisUser.password_hash_type.Value = "md5";
                    saltValue = LiftDomain.User.generateRandomSalt();
                    thisUser.password_salt.Value    = saltValue;
                    thisUser.crypted_password.Value = LiftDomain.User.hash(user_password.Text, saltValue);
                }

                thisUser.updated_at.Value            = LiftTime.CurrentTime;
                thisUser.time_zone.Value             = timezone_list.SelectedItem.Value;
                thisUser.previous_increment_id.Value = 0;

                //-------------------------------------------------------------------------
                //-- persist the User object data to the database
                //-------------------------------------------------------------------------
                thisUser.doCommand("save_current");

                Response.Redirect("MyAccount.aspx");
            }
            else
            {
                //-------------------------------------------------------------------------
                //-- query database for data for the current user
                //-------------------------------------------------------------------------
                id.Value          = LiftDomain.User.Current.id.Value.ToString();
                thisUser.id.Value = LiftDomain.User.Current.id.Value;
                thisUser          = thisUser.doSingleObjectQuery <LiftDomain.User>("select");
            }

            //-------------------------------------------------------------------------
            //-- populate the screen controls
            //-------------------------------------------------------------------------
            first_name_label.Text = thisUser.first_name;
            last_name_label.Text  = thisUser.last_name;
            login.Text            = thisUser.login;
            created_at.Text       = thisUser.created_at.Value.ToString("dddd MMMM dd, yyyy");

            first_name.Text     = thisUser.first_name;
            last_name.Text      = thisUser.last_name;
            email.Text          = thisUser.email;
            address.Text        = thisUser.address;
            city.Text           = thisUser.city;
            state_province.Text = thisUser.state_province;
            postal_code.Text    = thisUser.postal_code;
            phone.Text          = thisUser.phone;

            initialLanguageId = thisUser.language_id;
            initLanguageList(initialLanguageId);

            initialTimeZone = thisUser.time_zone;
            initTimeZoneList(initialTimeZone);

            //-------------------------------------------------------------------------
            //-- MY PRAYER REQUESTS
            //-------------------------------------------------------------------------

            LiftDomain.Request prayerRequest = new LiftDomain.Request();
            prayerRequest.user_id.Value = thisUser.id;
            prayerRequestSet            = prayerRequest.doQuery("get_my_account_requests");

            if (prayerRequestSet.Tables[0].Rows.Count > 0)
            {
                prayerRequestRenderer       = new PartialRenderer(HttpContext.Current, prayerRequestSet, "_MyAccountRequest.htm", new PartialRenderer.RenderHelper(prayerRequest.my_account_request_helper));
                prayerRequestRendererResult = prayerRequestRenderer;
            }
            else
            {
                prayerRequestRendererResult = "<p>" + LiftDomain.Language.Current.MY_ACCOUNT_YOU_HAVE_NO_REQUESTS.Value + ".</p>";
            }

            //-------------------------------------------------------------------------
            //-- MY PRAYER REQUEST SUBSCRIPTIONS
            //-------------------------------------------------------------------------
            LiftDomain.Subscription prayerRequestSubscription = new LiftDomain.Subscription();
            prayerRequestSubscription.user_id.Value = thisUser.id;
            prayerRequestSubscriptionSet            = prayerRequestSubscription.doQuery("get_subscription_by_user");

            if (prayerRequestSubscriptionSet.Tables[0].Rows.Count > 0)
            {
                prayerRequestSubscriptionRenderer       = new PartialRenderer(HttpContext.Current, prayerRequestSubscriptionSet, "_MyAccountPrayerRequestSubscription.htm", new PartialRenderer.RenderHelper(prayerRequestSubscription.my_account_prayer_request_subscription_helper));
                prayerRequestSubscriptionRendererResult = prayerRequestSubscriptionRenderer;
            }
            else
            {
                prayerRequestSubscriptionRendererResult = "<p>" + LiftDomain.Language.Current.MY_ACCOUNT_YOU_HAVE_NO_SUBSCRIPTIONS.Value + ".</p>";
            }

            //-------------------------------------------------------------------------
            //-- MY PRAYER SESSIONS
            //-------------------------------------------------------------------------
            LiftDomain.Prayersession prayerSessionObject = new LiftDomain.Prayersession();
            prayerSessionObject.user_id.Value = thisUser.id;
            prayerSessionSet = prayerSessionObject.doQuery("get_prayer_sessions_by_user_start_time_desc");

            if (prayerSessionSet.Tables[0].Rows.Count > 0)
            {
                prayerSessionRenderer       = new PartialRenderer(HttpContext.Current, prayerSessionSet, "_MyAccountPrayerSession.htm", new PartialRenderer.RenderHelper(prayerSessionObject.my_account_prayer_session_helper));
                prayerSessionRendererResult = prayerSessionRenderer;

                foreach (DataRow thisDataRow in prayerSessionSet.Tables[0].Rows)
                {
                    sumTotalRequests += Convert.ToInt32(thisDataRow["total_requests"]);
                    sumPrayerSessionsDurationTimeSpan = sumPrayerSessionsDurationTimeSpan.Add(Convert.ToDateTime(thisDataRow["end_time"]) - Convert.ToDateTime(thisDataRow["start_time"]));
                }

                prayer_requests_sum_label          = Convert.ToString(sumTotalRequests);
                prayer_sessions_duration_sum_label = Convert.ToString(sumPrayerSessionsDurationTimeSpan.Hours) + "." + (((float)((float)sumPrayerSessionsDurationTimeSpan.Minutes / (float)60)) * 10).ToString("0");
            }
            else
            {
                prayerSessionRendererResult = "<tr id='request0'><td valign='top' colspan='4' align='center'>" + LiftDomain.Language.Current.MY_ACCOUNT_YOU_HAVE_NO_SESSIONS.Value + ".</td></tr>";
            }
        }
コード例 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string cell       = string.Empty;
            string wallId     = string.Empty;
            string dow        = string.Empty;
            string tod        = string.Empty;
            string login      = string.Empty;
            string first_name = string.Empty;
            string last_name  = string.Empty;
            string phone      = string.Empty;
            string email      = string.Empty;
            string password   = string.Empty;

            LiftDomain.Organization.setCurrent();

            cell = Request["cell"];
            string[] parts = cell.Split(new char[] { '_' });
            wallId = parts[0];
            dow    = parts[1];
            tod    = parts[2];

            login      = Request["login"];
            first_name = Request["first_name"];
            last_name  = Request["last_name"];
            phone      = Request["phone"];
            email      = Request["email"];
            password   = Request["password"];

            LiftDomain.User thisUser = new LiftDomain.User();

            thisUser.password_hash_type.Value = "md5";
            string saltValue = LiftDomain.User.generateRandomSalt();

            thisUser.password_salt.Value = saltValue;

            thisUser.crypted_password.Value           = LiftDomain.User.hash(password, saltValue);
            thisUser.last_password_changed_date.Value = LiftTime.CurrentTime;

            thisUser.state.Value               = 1;
            thisUser.created_at.Value          = LiftTime.CurrentTime;
            thisUser.last_logged_in_at.Value   = new DateTime(2000, 1, 1, 0, 0, 0); //-- DateTime.MinValue;
            thisUser.login_failure_count.Value = 0;

            thisUser.login.Value = login;
            thisUser.email.Value = email;

            thisUser.first_name.Value     = first_name;
            thisUser.last_name.Value      = last_name;
            thisUser.address.Value        = string.Empty;
            thisUser.city.Value           = string.Empty;
            thisUser.state_province.Value = string.Empty;
            thisUser.postal_code.Value    = string.Empty;
            thisUser.phone.Value          = phone;

            thisUser.time_zone.Value   = Organization.Current.time_zone.Value;
            thisUser.language_id.Value = Organization.Current.language_id.Value;

            thisUser.previous_increment_id.Value = 0;
            thisUser.updated_at.Value            = LiftTime.CurrentTime;

            bool ok = true;

            if (LiftDomain.User.checkEmailExists(email))
            {
                ok = false;
            }

            if (LiftDomain.User.checkUsernameExists(login))
            {
                ok = false;
            }


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

                Appt a = new Appt();

                a["dow"]     = dow;
                a["tod"]     = tod;
                a["user_id"] = thisUser.id.Value;
                a["wall_id"] = wallId;
                a.doCommand("subscribe");

                userId = thisUser.id.Value.ToString();
                appt   = first_name.Substring(0, 1);
                appt  += ". ";
                appt  += last_name;
            }
        }
コード例 #5
0
ファイル: SignupUser.aspx.cs プロジェクト: ekohlenberg/lift
        protected void Page_Load(object sender, EventArgs e)
        {
            EmailValidator.ErrorMessage    = LiftDomain.Language.Current.SHARED_MUST_BE_A_VALID_EMAIL_ADDRESS;
            PasswordValidator.ErrorMessage = LiftDomain.Language.Current.SHARED_PASSWORDS_DO_NOT_MATCH;

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

            int    initialUserStatus = 1; //-- 1 = unconfirmed
            string initialTimeZone   = "Central Standard Time";
            int    initialLanguageId = 1; //-- 1 = English
            string saltValue         = string.Empty;


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

                //-------------------------------------------------------------------------
                //-- do other language settings
                //-------------------------------------------------------------------------
                signup_user_fieldset_legend  = LiftDomain.Language.Current.SIGNUP_USER_NEW_USER_REGISTRATION.Value;
                signup_user_fieldset_legend2 = LiftDomain.Language.Current.SIGNUP_USER_ALL_FIELDS_REQUIRED.Value;

                LiftDomain.User thisUser = new LiftDomain.User();

                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");



                        //-------------------------------------------------------------------------
                        //-- get the user ID from the hidden id field on the page;
                        //-- if there is a user ID value, then we are editing an EXISTING user
                        //-------------------------------------------------------------------------
                        if (!String.IsNullOrEmpty(id.Value) && (id.Value != "0"))
                        {
                            thisUser.id.Value = int.Parse(id.Value);

                            if (!String.IsNullOrEmpty(password.Text.Trim()))
                            {
                                //TODO: ???what if passwords do not match??? // TO BE DONE IN JAVASCRIPT
                                //(user_password.Text != password_confirmation.Text)

                                thisUser.password_hash_type.Value = "md5";
                                saltValue = LiftDomain.User.generateRandomSalt();
                                thisUser.password_salt.Value = saltValue;

                                thisUser.crypted_password.Value           = LiftDomain.User.hash(password.Text, saltValue);
                                thisUser.last_password_changed_date.Value = LiftTime.CurrentTime;
                            }
                        }
                        else
                        {
                            //-------------------------------------------------------------------------
                            //-- if the user ID is blank or zero (0), then set some NEW user values (NOT id)
                            //-------------------------------------------------------------------------
                            thisUser.state.Value               = initialUserStatus;
                            thisUser.created_at.Value          = LiftTime.CurrentTime;
                            thisUser.last_logged_in_at.Value   = new DateTime(2000, 1, 1, 0, 0, 0); //-- DateTime.MinValue;
                            thisUser.login_failure_count.Value = 0;
                            //thisUser.total_comments.Value = 0;
                            //thisUser.total_comments_needing_approval.Value = 0;
                            //thisUser.total_private_comments.Value = 0;

                            //TODO: ???what if password is blank??? // TO BE DONE IN JAVASCRIPT
                            if (String.IsNullOrEmpty(password.Text.Trim()))
                            {
                            }
                            else
                            {
                                //TODO: ???what if passwords do not match??? // TO BE DONE IN JAVASCRIPT
                                //(user_password.Text != password_confirmation.Text)

                                thisUser.password_hash_type.Value = "md5";
                                saltValue = LiftDomain.User.generateRandomSalt();
                                thisUser.password_salt.Value = saltValue;

                                thisUser.crypted_password.Value = LiftDomain.User.hash(password.Text, saltValue);
                            }
                        }

                        //-------------------------------------------------------------------------
                        //-- transfer screen values to the object
                        //-------------------------------------------------------------------------
                        thisUser.login.Value = user_email.Text;
                        thisUser.email.Value = user_email.Text;

                        thisUser.first_name.Value = user_first_name.Text;
                        thisUser.last_name.Value  = user_last_name.Text;
                        //thisUser.address.Value = user_address.Text;
                        thisUser.address.Value = "";
                        //thisUser.city.Value = user_city.Text;
                        thisUser.city.Value = "";
                        //thisUser.state_province.Value = user_state.Text;
                        thisUser.state_province.Value = "";
                        //thisUser.postal_code.Value = user_postal_code.Text;
                        thisUser.postal_code.Value = "";
                        thisUser.phone.Value       = user_phone.Text;

                        //thisUser.state.Value = initialUserStatus;
                        //thisUser.time_zone.Value = timezone_list.SelectedItem.Value;
                        thisUser.time_zone.Value = Organization.Current.time_zone.Value;
                        //thisUser.language_id.Value = Convert.ToInt32(language_list.SelectedItem.Value);
                        thisUser.language_id.Value = Organization.Current.language_id.Value;

                        thisUser.previous_increment_id.Value = 0;
                        thisUser.updated_at.Value            = LiftTime.CurrentTime;
                        thisUser.password_hash_type.Value    = "md5";

                        //thisUser.isapproved.Value = true; //TODO: ???need to fix when moderator user available

                        bool ok = true;
                        if (LiftDomain.User.checkEmailExists(user_email.Text))
                        {
                            ok = false;
                        }

                        if (user_login.Text.Length == 0)
                        {
                            user_login.Text = user_email.Text;
                        }

                        if (LiftDomain.User.checkUsernameExists(user_login.Text))
                        {
                            ok = false;
                        }

                        if (!ok)
                        {
                            errorMsg.Text  = Language.Current.SIGNUP_ACCT_EXISTS1;
                            errorMsg.Text += " ";
                            errorMsg.Text += Language.Current.SIGNUP_ACCT_EXISTS2;
                            errorMsg.Text += "<br/><br/>";
                            errorMsg.Text += " <a href=\"ForgotPassword.aspx?email=";
                            errorMsg.Text += thisUser.email.Value;
                            errorMsg.Text += "\">";
                            errorMsg.Text += LiftDomain.Language.Current.SIGNUP_RETRIEVE_YOUR_PASSWORD;
                            errorMsg.Text += "</a>";
                        }

                        if (ok)
                        {
                            //-------------------------------------------------------------------------
                            //-- persist the User object data to the database
                            //-------------------------------------------------------------------------
                            thisUser.id.Value = Convert.ToInt32(thisUser.doCommand("create_account"));

                            LiftMembershipProvider membership = new LiftMembershipProvider();

                            if (membership.ValidateUser(user_email.Text, password.Text))
                            {
                                FormsAuthentication.Initialize();

                                LiftRoleProvider roleProvider = new LiftRoleProvider();
                                roleProvider.Initialize(null, null);
                                //String strRole = membership.AssignRoles(txtUsername.Text);
                                string[] roles   = roleProvider.GetRolesForUser(user_login.Text);
                                string   strRole = "";
                                foreach (string role in roles)
                                {
                                    if (strRole.Length > 0)
                                    {
                                        strRole += ",";
                                    }
                                    strRole += role;
                                }

                                //FormsIdentity fi = new FormsIdentity((FormsIdentity)HttpContext.Current.User.Identity;
                                FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1,
                                                                                              user_email.Text, DateTime.Now,
                                                                                              DateTime.Now.AddMinutes(30), false, strRole,
                                                                                              FormsAuthentication.FormsCookiePath);


                                FormsIdentity fi = new FormsIdentity(fat);

                                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
                                                                    FormsAuthentication.Encrypt(fat)));


                                HttpContext.Current.User = new GenericPrincipal(fi, roles);

                                Response.Redirect(FormsAuthentication.GetRedirectUrl(user_email.Text, false));
                            }
                            else
                            {
                                Response.Redirect("SignUpThankYou.aspx");
                            }
                        }
                    }
                    else
                    {
                        errorMsg.Text = Language.Current.SIGNUP_USER_USER_REGISTRATION_FAILED;
                    }
                }
                else
                {
                    //-------------------------------------------------------------------------
                    //-- first time on this page, so get the user ID from the ASP Request cache
                    //-------------------------------------------------------------------------
                    string idStr = Request["id"];

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

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

                    //-------------------------------------------------------------------------
                    //-- if this is a NEW user...
                    //-------------------------------------------------------------------------
                    if (id.Value == "0")
                    {
                        //-------------------------------------------------------------------------
                        //-- set default values
                        //-------------------------------------------------------------------------
                        initialUserStatus = 1;  //-- 1 = unconfirmed
                        initialTimeZone   = LiftDomain.Organization.Current.time_zone.Value;
                        initialLanguageId = LiftDomain.Organization.Current.language_id.Value;
                    }

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

                        initialUserStatus = thisUser.state;
                        initialTimeZone   = thisUser.time_zone;
                        initialLanguageId = thisUser.language_id;
                    }

                    //-------------------------------------------------------------------------
                    //-- populate the screen controls
                    //-------------------------------------------------------------------------
                    user_login.Text       = thisUser.login;
                    user_email.Text       = thisUser.email;
                    user_first_name.Text  = thisUser.first_name;
                    user_last_name.Text   = thisUser.last_name;
                    user_address.Text     = thisUser.address;
                    user_city.Text        = thisUser.city;
                    user_state.Text       = thisUser.state_province;
                    user_postal_code.Text = thisUser.postal_code;
                    user_phone.Text       = thisUser.phone;

                    initTimeZoneList(initialTimeZone);
                    initLanguageList(initialLanguageId);
                }
            }
            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 SignupUser.aspx.cs::Page_Load(): " + m);
                Logger.log("SignupUser.aspx.cs", x, "[" + DateTime.Now.ToString() + "] *** ERROR IN SignupUser.aspx.cs::Page_Load(): " + m);
                //Response.Write(m);
            }
            finally
            {
            }
        }
コード例 #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PasswordRequired.Enabled       = false;
            EmailValidator.ErrorMessage    = LiftDomain.Language.Current.SHARED_MUST_BE_A_VALID_EMAIL_ADDRESS;
            PasswordValidator.ErrorMessage = LiftDomain.Language.Current.SHARED_PASSWORDS_DO_NOT_MATCH;

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

            PageAuthorized.check(Request, Response);

            int    initialUserStatus = 1; //-- 1 = unconfirmed
            string initialTimeZone   = "Central Standard Time";
            int    initialLanguageId = 1; //-- 1 = English
            int    initialOrgId      = 0;
            string saltValue         = string.Empty;

            LiftDomain.RolesUser thisRolesUser;

            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_user_fieldset_legend = LiftDomain.Language.Current.USER_EDIT_USER.Value;
                //this.user_roles_2.Text = LiftDomain.Language.Current.ROLES_ADMIN.Value;
                this.user_roles_7.Text  = LiftDomain.Language.Current.ROLES_MODERATOR.Value;
                this.user_roles_8.Text  = LiftDomain.Language.Current.ROLES_WALL_LEADER.Value;
                this.user_roles_10.Text = LiftDomain.Language.Current.ROLES_WATCHMAN.Value;
                this.user_roles_13.Text = LiftDomain.Language.Current.ROLES_SYSTEM_ADMIN.Value;
                this.user_roles_14.Text = LiftDomain.Language.Current.ROLES_ORGANIZATION_ADMIN.Value;
                //this.user_roles_11.Text = LiftDomain.Language.Current.ROLES_TESTADMIN.Value;
                //this.user_roles_12.Text = LiftDomain.Language.Current.ROLES_ADMINTEST.Value;

                LiftDomain.User thisUser = new LiftDomain.User();

                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"))
                    {
                        thisUser.id.Value = int.Parse(id.Value);

                        if (!String.IsNullOrEmpty(password.Text.Trim()))
                        {
                            //TODO: ???what if passwords do not match??? // TO BE DONE IN JAVASCRIPT
                            //(user_password.Text != password_confirmation.Text)

                            thisUser.password_hash_type.Value = "md5";
                            saltValue = LiftDomain.User.generateRandomSalt();
                            thisUser.password_salt.Value = saltValue;

                            thisUser.crypted_password.Value           = LiftDomain.User.hash(password.Text, saltValue);
                            thisUser.last_password_changed_date.Value = LiftTime.CurrentTime;
                        }
                    }
                    else
                    {
                        //-------------------------------------------------------------------------
                        //-- if the object ID is blank or zero (0), then set some NEW object values (NOT id)
                        //-------------------------------------------------------------------------
                        thisUser.created_at.Value          = LiftTime.CurrentTime;
                        thisUser.last_logged_in_at.Value   = new DateTime(2000, 1, 1, 0, 0, 0); //-- DateTime.MinValue;
                        thisUser.login_failure_count.Value = 0;
                        //thisUser.total_comments.Value = 0;
                        //thisUser.total_comments_needing_approval.Value = 0;
                        //thisUser.total_private_comments.Value = 0;

                        //TODO: ???what if password is blank??? // TO BE DONE IN JAVASCRIPT
                        if (String.IsNullOrEmpty(password.Text.Trim()))
                        {
                        }
                        else
                        {
                            //TODO: ???what if passwords do not match??? // TO BE DONE IN JAVASCRIPT
                            //(user_password.Text != password_confirmation.Text)

                            thisUser.password_hash_type.Value = "md5";
                            saltValue = LiftDomain.User.generateRandomSalt();
                            thisUser.password_salt.Value = saltValue;

                            thisUser.crypted_password.Value           = LiftDomain.User.hash(password.Text, saltValue);
                            thisUser.last_password_changed_date.Value = LiftTime.CurrentTime;
                        }
                    }

                    //-------------------------------------------------------------------------
                    //-- transfer screen values to the object
                    //-------------------------------------------------------------------------
                    //TODO: ???what if data field validation fails??? // TO BE DONE IN JAVASCRIPT
                    //TODO: ???what if user login already exists??? // TO BE DONE IN JAVASCRIPT
                    thisUser.login.Value = user_login.Text;
                    thisUser.email.Value = user_email.Text;

                    thisUser.first_name.Value     = user_first_name.Text;
                    thisUser.last_name.Value      = user_last_name.Text;
                    thisUser.address.Value        = user_address.Text;
                    thisUser.city.Value           = user_city.Text;
                    thisUser.state_province.Value = user_state.Text;
                    thisUser.postal_code.Value    = user_postal_code.Text;
                    thisUser.phone.Value          = user_phone.Text;

                    thisUser.state.Value           = Convert.ToInt32(user_status_list.SelectedItem.Value);
                    thisUser.time_zone.Value       = timezone_list.SelectedItem.Value;
                    thisUser.language_id.Value     = Convert.ToInt32(language_list.SelectedItem.Value);
                    thisUser.organization_id.Value = Convert.ToInt32(org_list.SelectedItem.Value);

                    thisUser.previous_increment_id.Value = 0;
                    thisUser.updated_at.Value            = LiftTime.CurrentTime;

                    //thisUser.isapproved.Value = true; //TODO: ???need to fix when moderator user available

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

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

                    //-------------------------------------------------------------------------
                    //-- persist the RolesUser object data to the database
                    //-- first, delete all for this user...then insert in the selected roles
                    //-------------------------------------------------------------------------
                    thisRolesUser = new LiftDomain.RolesUser();
                    thisRolesUser.user_id.Value = thisUser.id.Value;
                    thisRolesUser.doQuery("delete_roles_users_by_user_id");

                    /*
                     * if (user_roles_2.Checked)
                     * {
                     *  thisRolesUser = new LiftDomain.RolesUser();
                     *  thisRolesUser.user_id.Value = thisUser.id.Value;
                     *  thisRolesUser.role_id.Value = 2;
                     *  thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                     *  thisRolesUser.doCommand("save");
                     * }
                     */


                    if (user_roles_7.Checked)
                    {
                        thisRolesUser = new LiftDomain.RolesUser();
                        thisRolesUser.user_id.Value    = thisUser.id.Value;
                        thisRolesUser.role_id.Value    = 7;
                        thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                        thisRolesUser.doCommand("save");
                    }

                    if (user_roles_8.Checked)
                    {
                        thisRolesUser = new LiftDomain.RolesUser();
                        thisRolesUser.user_id.Value    = thisUser.id.Value;
                        thisRolesUser.role_id.Value    = 8;
                        thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                        thisRolesUser.doCommand("save");
                    }

                    if (user_roles_10.Checked)
                    {
                        thisRolesUser = new LiftDomain.RolesUser();
                        thisRolesUser.user_id.Value    = thisUser.id.Value;
                        thisRolesUser.role_id.Value    = 10;
                        thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                        thisRolesUser.doCommand("save");
                    }

                    if (user_roles_13.Checked)
                    {
                        thisRolesUser = new LiftDomain.RolesUser();
                        thisRolesUser.user_id.Value    = thisUser.id.Value;
                        thisRolesUser.role_id.Value    = 13;
                        thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                        thisRolesUser.doCommand("save");
                    }

                    if (user_roles_14.Checked)
                    {
                        thisRolesUser = new LiftDomain.RolesUser();
                        thisRolesUser.user_id.Value    = thisUser.id.Value;
                        thisRolesUser.role_id.Value    = 14;
                        thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                        thisRolesUser.doCommand("save");
                    }

                    //if (user_roles_11.Checked)
                    //{
                    //    thisRolesUser = new LiftDomain.RolesUser();
                    //    thisRolesUser.user_id.Value = thisUser.id.Value;
                    //    thisRolesUser.role_id.Value = 11;
                    //    thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                    //    thisRolesUser.doCommand("save");
                    //}

                    //if (user_roles_12.Checked)
                    //{
                    //    thisRolesUser = new LiftDomain.RolesUser();
                    //    thisRolesUser.user_id.Value = thisUser.id.Value;
                    //    thisRolesUser.role_id.Value = 12;
                    //    thisRolesUser.created_at.Value = LiftTime.CurrentTime;
                    //    thisRolesUser.doCommand("save");
                    //}

                    //-------------------------------------------------------------------------
                    //-- return to the User List page
                    //-------------------------------------------------------------------------
                    if (Session["last_user_list_search"] != null)
                    {
                        Response.Redirect("UserList.aspx?" + Session["last_user_list_search"]);
                    }
                    else
                    {
                        Response.Redirect("UserList.aspx");
                    }
                }
                else
                {
                    //-------------------------------------------------------------------------
                    //-- first time on this page, so get the object ID from the ASP Request cache
                    //-------------------------------------------------------------------------
                    string idStr = Request["id"];

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

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

                    //-------------------------------------------------------------------------
                    //-- if this is a NEW user...
                    //-------------------------------------------------------------------------
                    if (id.Value == "0")
                    {
                        //-------------------------------------------------------------------------
                        //-- set default values
                        //-------------------------------------------------------------------------
                        initialUserStatus = 1;  //-- 1 = unconfirmed
                        initialTimeZone   = LiftDomain.Organization.Current.time_zone.Value;
                        initialLanguageId = LiftDomain.Organization.Current.language_id.Value;
                        initialOrgId      = LiftDomain.Organization.Current.id.Value;

                        login_label.Visible       = false;
                        edit_user_fieldset_legend = LiftDomain.Language.Current.USER_CREATE_A_NEW_USER.Value;

                        bottomNavTableCellDelete.Visible = false;
                        delete_user_id = string.Empty;
                        redirect_after_delete_to_page = string.Empty;
                        PasswordRequired.Enabled      = true;
                    }

                    //-------------------------------------------------------------------------
                    //-- else, if this is an EXISTING user...
                    //-------------------------------------------------------------------------
                    else
                    {
                        //-------------------------------------------------------------------------
                        //-- query database for data for this user
                        //-------------------------------------------------------------------------

                        if (LiftDomain.User.Current.IsInRole(Role.SYS_ADMIN))
                        {
                            thisUser.OverrideAutoOrgAssignment = true;
                        }

                        thisUser = thisUser.doSingleObjectQuery <LiftDomain.User>("select");

                        initialUserStatus = thisUser.state;
                        initialTimeZone   = thisUser.time_zone;
                        initialLanguageId = thisUser.language_id;
                        initialOrgId      = thisUser.organization_id;

                        login_label.Text          = LiftDomain.Language.Current.USER_EDITING_USER.Value + " " + thisUser.login;
                        edit_user_fieldset_legend = LiftDomain.Language.Current.USER_EDIT_USER.Value;

                        bottomNavTableCellDelete.Visible = true;
                        delete_user_id = id.Value;

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

                    //-------------------------------------------------------------------------
                    //-- populate the screen controls
                    //-------------------------------------------------------------------------
                    user_login.Text       = thisUser.login;
                    user_email.Text       = thisUser.email;
                    user_first_name.Text  = thisUser.first_name;
                    user_last_name.Text   = thisUser.last_name;
                    user_address.Text     = thisUser.address;
                    user_city.Text        = thisUser.city;
                    user_state.Text       = thisUser.state_province;
                    user_postal_code.Text = thisUser.postal_code;
                    user_phone.Text       = thisUser.phone;

                    /*
                     * thisRolesUser = new LiftDomain.RolesUser();
                     * thisRolesUser.user_id.Value = thisUser.id.Value;
                     * thisRolesUser.role_id.Value = 2;
                     * thisRolesUser = thisRolesUser.doSingleObjectQuery<LiftDomain.RolesUser>("select");
                     * user_roles_2.Checked = (thisRolesUser.id.Value > 0);
                     * */

                    thisRolesUser = new LiftDomain.RolesUser();
                    thisRolesUser.user_id.Value = thisUser.id.Value;
                    thisRolesUser.role_id.Value = 7;
                    thisRolesUser        = thisRolesUser.doSingleObjectQuery <LiftDomain.RolesUser>("select");
                    user_roles_7.Checked = (thisRolesUser.id.Value > 0);

                    thisRolesUser = new LiftDomain.RolesUser();
                    thisRolesUser.user_id.Value = thisUser.id.Value;
                    thisRolesUser.role_id.Value = 8;
                    thisRolesUser        = thisRolesUser.doSingleObjectQuery <LiftDomain.RolesUser>("select");
                    user_roles_8.Checked = (thisRolesUser.id.Value > 0);

                    thisRolesUser = new LiftDomain.RolesUser();
                    thisRolesUser.user_id.Value = thisUser.id.Value;
                    thisRolesUser.role_id.Value = 10;
                    thisRolesUser         = thisRolesUser.doSingleObjectQuery <LiftDomain.RolesUser>("select");
                    user_roles_10.Checked = (thisRolesUser.id.Value > 0);

                    thisRolesUser = new LiftDomain.RolesUser();
                    thisRolesUser.user_id.Value = thisUser.id.Value;
                    thisRolesUser.role_id.Value = 13;
                    thisRolesUser         = thisRolesUser.doSingleObjectQuery <LiftDomain.RolesUser>("select");
                    user_roles_13.Checked = (thisRolesUser.id.Value > 0);

                    thisRolesUser = new LiftDomain.RolesUser();
                    thisRolesUser.user_id.Value = thisUser.id.Value;
                    thisRolesUser.role_id.Value = 14;
                    thisRolesUser         = thisRolesUser.doSingleObjectQuery <LiftDomain.RolesUser>("select");
                    user_roles_14.Checked = (thisRolesUser.id.Value > 0);

                    //thisRolesUser = new LiftDomain.RolesUser();
                    //thisRolesUser.user_id.Value = thisUser.id.Value;
                    //thisRolesUser.role_id.Value = 11;
                    //thisRolesUser = thisRolesUser.doSingleObjectQuery<LiftDomain.RolesUser>("select");
                    //user_roles_11.Checked = (thisRolesUser.id.Value > 0);

                    //thisRolesUser = new LiftDomain.RolesUser();
                    //thisRolesUser.user_id.Value = thisUser.id.Value;
                    //thisRolesUser.role_id.Value = 12;
                    //thisRolesUser = thisRolesUser.doSingleObjectQuery<LiftDomain.RolesUser>("select");
                    //user_roles_12.Checked = (thisRolesUser.id.Value > 0);

                    initUserStatusList(initialUserStatus);
                    initTimeZoneList(initialTimeZone);
                    initLanguageList(initialLanguageId);
                    initOrgList(initialOrgId);

                    enforceRoleSettings();
                }
            }
            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 EditUser.aspx.cs::Page_Load(): " + m);
                Logger.log("EditUser.aspx.cs", x, "[" + DateTime.Now.ToString() + "] *** ERROR IN EditUser.aspx.cs::Page_Load(): " + m);
            }
            finally
            {
            }
        }
コード例 #7
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
            {
            }
        }