SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Account Locked Message Inside the Anonymous Template

    Hi everyone, thanks to this site I was able to implement a message to teh suer when their accoutn is locked. This works in the regular asp.net login control, however I am not able to implement the message inside of the Anonymous view and logged in view. can someone please tell me what I am doing wrong. Thanks.

    Here is the code behind for the error message:
    Code:
    Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoginError
            'There was a problem logging in the user
    
            'See if this user exists in the database
            Dim userInfo As MembershipUser = Membership.GetUser(Login1.UserName)
    
            If userInfo Is Nothing Then
                'The user entered an invalid username...
                Login1.FailureText = "There is no user in the database with the username " & Login1.UserName
            Else
                'See if the user is locked out or not approved
                If Not userInfo.IsApproved Then
                    Login1.FailureText = "Your account has not yet been approved by the site's administrators. Please try again later..."
                ElseIf userInfo.IsLockedOut Then
                    Login1.FailureText = "Account locked due to too many failed login attempts. Please contact the registrar."
                   
                Else
                    'The password was incorrect (don't show anything, the Login control already describes the problem)
                    Login1.FailureText = String.Empty
                End If
            End If
        End Sub
    Here is the login control which is inside a update panel:

    Code:
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:LoginView ID="lv2" runat="server">
                                <AnonymousTemplate>
                                    <asp:Login ID="Login1" runat="server" Font-Size="10px" FailureText="Login Failure. Please Try Again."
                                        FailureTextStyle-ForeColor="red" ForeColor="#CC0000" OnPreRender="Login1_PreRender">
                                        <LayoutTemplate>
                                            <asp:Literal runat="server" ID="FailureText" EnableViewState="False"></asp:Literal>
                                            <table cellpadding="0" cellspacing="2" width="200">
                                                <tr>
                                                    <td align="right">
                                                        <asp:Label runat="server" AssociatedControlID="UserName" ID="UserNameLabel" CssClass="fontTen"
                                                            Style="color: #000000"><strong>User name:</strong> </asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox runat="server" ID="UserName" Style="width: 100px;"></asp:TextBox>
                                                        <asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" ValidationGroup="Login1"
                                                            ErrorMessage="User Name is required." ToolTip="User Name is required." ID="UserNameRequired"><img src="~/App_Themes/RSS/Images/forms/errorX.png" runat="server" /></asp:RequiredFieldValidator>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="right">
                                                        <asp:Label runat="server" AssociatedControlID="Password" ID="PasswordLabel" CssClass="fontTen"
                                                            Style="color: #000000"><strong>Password: </strong></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox runat="server" TextMode="Password" ID="Password" Style="width: 100px;"></asp:TextBox>
                                                        <asp:RequiredFieldValidator runat="server" ControlToValidate="Password" ValidationGroup="Login1"
                                                            ErrorMessage="Password is required." ToolTip="Password is required." ID="PasswordRequired">
                                                            <img id="Img1" src="~/App_Themes/RSS/Images/forms/errorX.png" runat="server" /></asp:RequiredFieldValidator>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" class="fontTen" style="color: #000000">
                                                       <div style="padding:3px"><asp:HyperLink ID="HyperLinkForgotUsername" runat="server" CssClass="fontTen" OnPreRender="HyperLinkForgotUsername_PreRender">Forgot Username or Password?</asp:HyperLink></div>
                                                        <%--<asp:CheckBox runat="server" ID="RememberMe" Text="Remember me." CssClass="fontTen" />--%>
                                                        <div style="padding:3px"><asp:HyperLink ID="HyperLinkRegister" runat="server" CssClass="fontTen" OnPreRender="HyperLinkRegister_PreRender">New Member</asp:HyperLink></div>
                                                    </td>
                                                </tr>
                                            </table>
                                            <asp:Button ID="LoginButtonHDR" runat="server" Text="Login" CommandName="Login" CausesValidation="true"
                                                ValidationGroup="Login1" />
                                            </div>
                                        </LayoutTemplate>
                                        <ValidatorTextStyle ForeColor="#990033" />
                                        <FailureTextStyle ForeColor="#66FF99" />
                                    </asp:Login>
                                </AnonymousTemplate>
                                <LoggedInTemplate>
                                    <div>
                                        <h2 class="welcomeDropdown">
                                            Hello <br />
                                            <asp:LoginName ID="LoginName1" runat="server" />
                                        </h2>
                                        <p>
                                            <asp:Button runat="server" ID="logout" Text="Log Out" OnClick="logout_click" CausesValidation="false" />
                                        </p>
                                        <br />
                                        <br />
                                        <br />
                                    </div>
                                    <!-- end content -->
                                </LoggedInTemplate>
                            </asp:LoginView>
                        </ContentTemplate>
                    </asp:UpdatePanel>
    The error I am getting with the code above in the SUB is.... "Name 'Login1' is not declared" - reference Login1.FailureText

    Thanks!!

  2. #2
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Everyone, I was able to get the code behind to not throw errors, but now when I test by logging in with an account that is locked I am getting the default .net login error message "Your login attempt was not successful. Please try again".

    Why is the below new code not firing and displaying my custom messages?
    Code:
    Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As System.EventArgs
            
            'There was a problem logging in the user
            'See if this user exists in the database
            Dim Login1 As Login = DirectCast(lv2.FindControl("Login1"), Login)
            Dim userInfo As MembershipUser = Membership.GetUser(Login1.UserName)
    
            If userInfo Is Nothing Then
                'The user entered an invalid username...
                Login1.FailureText = "There is no user in the database with the username " & Login1.UserName
            Else
                'See if the user is locked out or not approved
                If Not userInfo.IsApproved Then
                    Login1.FailureText = "Your account has not yet been approved by the site's administrators. Please try again later..."
                ElseIf userInfo.IsLockedOut Then
                    Login1.FailureText = "Account locked due to too many failed login attempts. Please contact the registrar."
                   
                Else
                    'The password was incorrect (don't show anything, the Login control already describes the problem)
                    Login1.FailureText = String.Empty
                End If
            End If
        End Sub


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •