コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        BindPageSize();

        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ShowUser"]))
            {
                int l_UserID;
                if (int.TryParse(Request.QueryString["ShowUser"], out l_UserID))
                {
                    ProfilesMembershipUser l_user =
                        (ProfilesMembershipUser) new ProfilesDBMembershipProviderBL().GetUserByID(l_UserID);

                    if (l_user != null)
                    {
                        int userPosition = new ProfilesDBMembershipProviderBL().GetUserPosition(l_user.UserID);

                        int recordsAtPage = userPosition / gridUsers.PageSize;
                        gridUsers.PageIndex = recordsAtPage;
                    }
                }
            }

            if (Cache.Count == 0)
            {
                RefreshCache();
            }
        }
    }
コード例 #2
0
    // PRG: Fix this
    //
    //MembershipProvider.ResetPassword

    public override string ResetPassword(string username, string answer)
    {
        string l_resultPass = null;

        string l_Pass = new ProfilesDBMembershipProviderBL().GetPasswordByAnswer(username, answer);

        if (!string.IsNullOrEmpty(l_Pass))
        {
            l_Pass = UnEncodePassword(l_Pass);
            string l_newPass = Membership.GeneratePassword(MinRequiredPasswordLength + 2, 1);

            if (ChangePassword(username, l_Pass, l_newPass))
            {
                l_resultPass = l_newPass;
            }
        }
        return(l_resultPass);
    }
コード例 #3
0
    protected void lbSave_Click(object sender, EventArgs e)
    {
        bool   l_isValid             = true;
        string l_PasswordAnswer      = tbPasswordAnswer.Text.Trim();
        string l_PasswordQuestion    = tbPasswordQuestion.Text.Trim();
        string l_Password            = tbPassword.Text.Trim();
        string l_Login               = tbLogin.Text.Trim();
        string l_LastName            = tbLastName.Text.Trim();
        string l_FirstName           = tbFirstName.Text.Trim();
        string l_OfficePhone         = tbOfficePhone.Text.Trim();
        string l_EmailAddr           = tbEmail.Text.Trim();
        string l_InstitutionFullname = tbInstitutionFullname.Text.Trim();
        string l_DepartmentFullname  = tbDepartmentFullname.Text.Trim();
        string l_DivisionFullname    = tbDivisionFullname.Text.Trim();
        string l_Comments            = tbComments.Text.Trim();

        if (string.IsNullOrEmpty(l_PasswordAnswer))
        {
            l_isValid = false;
            tbPasswordAnswer.Focus();
        }

        if (string.IsNullOrEmpty(l_PasswordQuestion))
        {
            l_isValid = false;
            tbPasswordQuestion.Focus();
        }

        if (string.IsNullOrEmpty(l_EmailAddr))
        {
            l_isValid = false;
            tbEmail.Focus();
        }
        else
        {
            if (!Regex.IsMatch(l_EmailAddr, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
            {
                l_isValid             = false;
                lInvalidEmail.Visible = true;
                lInvalidEmail.Text    = "Incorrect format";
                tbEmail.Focus();
            }
        }

        if (IsNewUser)
        {
            if (string.IsNullOrEmpty(l_Password))
            {
                l_isValid = false;
                tbPassword.Focus();
            }
            else
            {
                if (l_Password != tbConfirmPassword.Text.Trim())
                {
                    l_isValid = false;
                    lInvalidPassword.Visible = true;
                    tbPassword.Focus();
                }
            }
        }

        if (string.IsNullOrEmpty(l_Login))
        {
            l_isValid = false;
            tbLogin.Focus();
        }

        if (string.IsNullOrEmpty(l_LastName))
        {
            l_isValid = false;
            tbLastName.Focus();
        }

        if (string.IsNullOrEmpty(l_FirstName))
        {
            l_isValid = false;
            tbFirstName.Focus();
        }

        if (!l_isValid)
        {
            return;
        }


        ProfilesMembershipUser l_CheckUser = new ProfilesDBMembershipProviderBL().GetUser(l_Login, false);

        if (l_CheckUser != null)
        {
            if (l_CheckUser.UserID != UserID)
            {
                l_isValid             = false;
                lInvalidLogin.Visible = true;
                tbLogin.Focus();
            }
        }
        if (!l_isValid)
        {
            return;
        }



        try
        {
            MembershipUser l_updatedUser;
            ProfilesDBMembershipProvider customMembership = (ProfilesDBMembershipProvider)Membership.Provider;
            if (IsNewUser)
            {
                l_updatedUser = customMembership.CreateUser(l_Login,
                                                            l_FirstName, l_LastName, l_EmailAddr,
                                                            l_OfficePhone, l_InstitutionFullname,
                                                            l_DepartmentFullname, l_DivisionFullname,
                                                            customMembership.EncodePassword(l_Password), GlobalConst.PasswordFormat,
                                                            l_PasswordQuestion, l_PasswordAnswer,
                                                            GlobalConst.ApplicationName, l_Comments, true);
            }
            else
            {
                l_updatedUser = customMembership.UpdateUser(UserID.Value, l_Login,
                                                            l_FirstName, l_LastName, l_EmailAddr,
                                                            l_OfficePhone, l_InstitutionFullname,
                                                            l_DepartmentFullname, l_DivisionFullname,
                                                            customMembership.EncodePassword(l_Password),
                                                            GlobalConst.PasswordFormat,
                                                            l_PasswordQuestion, l_PasswordAnswer,
                                                            GlobalConst.ApplicationName, l_Comments, true);

                if (l_updatedUser != null)
                {
                    string[] userRolesNames = Roles.GetRolesForUser(l_Login);
                    if (userRolesNames != null && userRolesNames.Length > 0)
                    {
                        Roles.RemoveUserFromRoles(l_Login, userRolesNames);
                    }
                }
            }

            if (l_updatedUser != null)
            {
                foreach (ListItem l_Item in cblRoles.Items)
                {
                    if (l_Item.Selected)
                    {
                        Roles.AddUserToRole(l_updatedUser.UserName, l_Item.Value);
                    }
                }
            }

            RefreshCache();


            if (l_updatedUser != null)
            {
                UserID = ((ProfilesMembershipUser)l_updatedUser).UserID;
            }


            string l_redirectUrl = string.Format("{0}", ResolveUrl("AllUsers.aspx"));
            if (PageSize.HasValue)
            {
                l_redirectUrl += string.Format("?PageSize={0}", PageSize.Value);
            }
            else
            {
                l_redirectUrl += string.Format("?PageSize=empty");
            }

            if (UserID != null)
            {
                l_redirectUrl += string.Format("&ShowUser={0}", UserID.Value);
            }

            Response.Redirect(l_redirectUrl);
        }
        catch (Exception ex)
        {
            //ExceptionPolicy.HandleException(ex, GlobalConst.LogOnlyPolicy);
            lGeneralError.Visible = true;
            lGeneralError.Text    = ex.Message;
        }
    }