Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            string UserEmail    = null;
            bool   EmailChanged = false;

            if (IsNewMode)
            {
                User user = null;
                Membership.UserCreateResults results = Membership.CreateUser(txtEmail.Text, txtPassword.Text.Trim(), out user);
                switch (results)
                {
                default:
                case Membership.UserCreateResults.UnknownError:
                    Master.MessageCenter.DisplayErrorMessage(UsersStrings.GetText(@"MessageCreateFailedUnknown"));
                    return;

                case Membership.UserCreateResults.AlreadyExists:
                    Master.MessageCenter.DisplayErrorMessage(UsersStrings.GetText(@"MessageCreateFailedAlreadyExists"));
                    return;

                case Membership.UserCreateResults.InvalidEmailAddress:
                    Master.MessageCenter.DisplayErrorMessage(UsersStrings.GetText(@"MessageCreateFailedEmailAddressInvalid"));
                    return;

                case Membership.UserCreateResults.Success:
                    break;
                }
                if (chkIsLocked.Checked != user.IsLocked)
                {
                    user.IsLocked = chkIsLocked.Checked;
                    user.Save();
                }
                UserId    = user.UserId;
                UserEmail = user.Email;
            }
            else
            {
                User user = core.DAL.User.FetchByID(UserId);
                UserEmail = user.UniqueEmail;

                if (user.UniqueEmail != txtEmail.Text.NormalizeEmail() ||
                    user.IsLocked != chkIsLocked.Checked)
                {
                    try
                    {
                        user.Email       = txtEmail.Text.Trim();
                        user.UniqueEmail = user.Email.NormalizeEmail();
                        user.IsLocked    = chkIsLocked.Checked;
                        user.Save();
                        if (user.UniqueEmail != UserEmail)
                        {
                            UserEmail    = user.Email;
                            EmailChanged = true;
                        }
                    }
                    catch
                    {
                        Master.MessageCenter.DisplayWarningMessage(UsersStrings.GetText(@"MessageEmailChangeFailed"));
                    }
                }

                if (txtPassword.Text.Length > 0)
                {
                    Membership.UserPasswordChangeResults results;
                    if (UserId == SessionHelper.UserId())
                    {
                        results = Membership.ChangeUserPassword(user.Email, txtCurrentPassword.Text, txtPassword.Text);
                    }
                    else
                    {
                        results = Membership.ChangeUserPassword(user.Email, txtPassword.Text);
                    }
                    switch (results)
                    {
                    default:
                        Master.MessageCenter.DisplayWarningMessage(UsersStrings.GetText(@"MessagePasswordChangeFailedUnknown"));
                        break;

                    case Membership.UserPasswordChangeResults.PasswordDoNotMatch:
                        Master.MessageCenter.DisplayWarningMessage(UsersStrings.GetText(@"MessagePasswordChangeBadOldPassword"));
                        break;

                    case Membership.UserPasswordChangeResults.Success:
                        break;
                    }
                }
                UserEmail = user.Email;
            }

            if (IsNewMode)
            {
                string successMessage = UsersStrings.GetText(@"MessageUserCreated");
                string url            = @"EditUser.aspx?Email=" + UserEmail;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
            }
            else
            {
                string successMessage = UsersStrings.GetText(@"MessageUserSaved");
                if (EmailChanged)
                {
                    string url = @"EditUser.aspx?message-success=" + Server.UrlEncode(successMessage);
                    if (UserId != SessionHelper.UserId())
                    {
                        url += @"&Email=" + UserEmail;
                    }
                    Response.Redirect(url, true);
                }
                else
                {
                    Master.MessageCenter.DisplaySuccessMessage(successMessage);
                }
            }
        }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                UserProfile userProfile = UserProfile.FetchByID(SessionHelper.UserId());
                if (userProfile == null)
                {
                    userProfile        = new UserProfile();
                    userProfile.UserId = SessionHelper.UserId();
                }

                userProfile.FirstName = txtFirstName.Text.Trim();
                userProfile.LastName  = txtLastName.Text.Trim();
                userProfile.Phone     = txtPhone.Text.Trim();

                userProfile.Save();
                Master.MessageCenter.DisplaySuccessMessage(UserProfileStrings.GetText(@"MessageSaved"));

                if (txtCurrentPassword.Text.Length > 0)
                {
                    if (txtPassword.Text.Length > 0)
                    {
                        Membership.UserPasswordChangeResults results;
                        results = Membership.ChangeUserPassword(SessionHelper.UserEmail(), txtCurrentPassword.Text, txtPassword.Text);
                        switch (results)
                        {
                        default:
                            Master.MessageCenter.DisplayWarningMessage(UserProfileStrings.GetText(@"MessagePasswordChangeFailedUnknown"));
                            break;

                        case Membership.UserPasswordChangeResults.PasswordDoNotMatch:
                            Master.MessageCenter.DisplayWarningMessage(UserProfileStrings.GetText(@"MessagePasswordChangeBadOldPassword"));
                            break;

                        case Membership.UserPasswordChangeResults.Success:
                            Master.MessageCenter.DisplaySuccessMessage(UserProfileStrings.GetText(@"MessagePasswordChanged"));
                            break;
                        }
                    }
                    if (txtEmail.Text.Length > 0 && txtEmail.Text != SessionHelper.UserEmail())
                    {
                        if (SessionHelper.UserEmail().NormalizeEmail() != txtEmail.Text.NormalizeEmail())
                        {
                            try
                            {
                                Snoopi.core.DAL.User user = Snoopi.core.DAL.User.FetchByID(SessionHelper.UserId());
                                user.Email       = txtEmail.Text.Trim();
                                user.UniqueEmail = user.Email.NormalizeEmail();
                                user.Save();
                                SessionHelper.SetUserEmail(user.Email);
                                Master.MessageCenter.DisplayWarningMessage(UserProfileStrings.GetText(@"MessageEmailChanged"));
                            }
                            catch
                            {
                                Master.MessageCenter.DisplaySuccessMessage(UserProfileStrings.GetText(@"MessageEmailChangeFailed"));
                            }
                        }
                    }
                }
            }
        }