1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get User data and reactivate account

Get User data and reactivate account

2 posts, 0 answered
  1. marco pessina
    marco pessina avatar
    16 posts
    Registered:
    02 Nov 2009
    15 Dec 2009
    Link to this post

    Hi,


    Could you please tell me how to load user data from a Telerik.DataAccess.AspnetProviders.User object of which I only know the UserName?

    Is there a way to intercept when a user in the login phase is blocked due to too many attempt?

    In the User Administration interface I need to have the possibility to reactivate a user with IsLockedOut = True, how can I do that?

     

    Thank you

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 Dec 2009
    Link to this post
    Hello marco pessina,

     You can use the code below to access the date form the Membership provider

    string name = Telerik.Security.UserManager.GetCurrentUserName();
    MembershipUser user = Membership.GetUser(name);
    string datecreation = user.CreationDate.ToString();
    string email = user.Email;
    bool approved = user.IsApproved;

    As you see, you can use standard ASP.NET class MembershipUser Class to retrieve the needed data.

    In your project web.config you can set the maxInvalidPasswordAttempts and other membership provider properties.

    <membership defaultProvider="Sitefinity" userIsOnlineTimeWindow="15" hashAlgorithmType="">
                <providers>
                    <clear/>
                    <add name="Sitefinity" connectionStringName="DefaultConnection" type="Telerik.DataAccess.AspnetProviders.TelerikMembershipProvider, Telerik.DataAccess" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression="" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0"/>

    isLockedOut has only get accessor so you cannot set the value to this property. You can use IsApproved instead. You can modify ~/Sitefinity/Admin/CmsAdmin/Users.aspx and ~/Sitefinity/Admin/CmsAdmin/Users.aspx.cs to add your checkbox and set the value

    sample:

    Membership Info</h3>
                      <fieldset class="userinfo set">
                          <ol class="setIn">
                              <li class="exField">
                                  <dl>
                                      <dt>Username</dt><dd class="readOnly"><asp:Literal ID="UserName" runat="server"></asp:Literal></dd>
                                      <dd class="example">
                                          The username cannot be changed</dd>
                                  </dl>
                              </li>
                              <li>
                                  <cc2:FieldLabel ID="lblEmail" runat="server" Text="Email *" TargetID="Email">
                                  </cc2:FieldLabel>
                                  <asp:TextBox ID="Email" runat="server"></asp:TextBox>
                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Email"
                                      ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUser"
                                      Display="Dynamic" CssClass="validMessage"><strong>E-mail cannot be empty!</strong></asp:RequiredFieldValidator>
                                  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="Email"
                                      Display="Dynamic" ErrorMessage="The email format is invalid." ValidationExpression="\S+@\S+\.\S+"
                                      ValidationGroup="CreateUser" CssClass="validMessage"><strong>The email format is invalid!</strong></asp:RegularExpressionValidator>
                              </li>                                   
                              <li class="newPass">
                                  <asp:LinkButton ID="passwordRecoveryButton" runat="server" Text="Reset password" OnClick="passwordRecoveryButton_Click" Tooltip="Click to automatically create a new password for this user." OnClientClick="return confirm('Are you sure you want to change the password for this user?');"/>
                              </li>
                               <li class="newPass">
                               <asp:CheckBox runat="server" ID="isLockedCheckBox" />
                              </li>
                          </ol>

    protected override void OnPreRender(EventArgs e)
        {
     
     
            base.OnPreRender(e);
            // ADD THE SIMILAR LOGIC WHEN YOU SAVE THE USER TO UPDATE THE DATABASE!!!
            Telerik.Security.WebControls.ManageUsers.EditContainer editContainer = manageUsers.GetCurrentContainer() as Telerik.Security.WebControls.ManageUsers.EditContainer;
            if (editContainer != null)
            {
                string uname = manageUsers.UserName;
                MembershipUser user = Membership.GetUser(uname);
                CheckBox isLockedCheckBox = (CheckBox)editContainer.FindControl("isLockedCheckBox");
                if (isLockedCheckBox != null)
                {
                    if (user.IsApproved)
                    {
                        
                         isLockedCheckBox.Checked = false;
                    }
                    else
                    {
                        isLockedCheckBox.Checked = true;
                    }
     
     
                }
            }
        }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered