ASP.Net Membership System - Login
New Community Forums available at http://forums.ext.net
 

Coolite Forums

Welcome Guest ( Login | Register )
 
ASP.Net Membership System - Login
Subscribe
Last Login: 4/26/2010 7:00:20 AM
Posts: 25,
Posted 3/4/2010 2:56:06 AM

Group: Coolite Early Adopter
 Hey,  After a little work I've added the asp.net membership functionality to a login window.  Any help or improvements welcome

VB.Net:



<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="DriveBusiness_Tracking._Default" %>

<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<%@ Register assembly="Devart.Data.Mysql" namespace="Devart.Data.Mysql" tagprefix="ddm" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As Coolite.Ext.Web.AjaxEventArgs)

        'We need to determine if the user is authenticated and set e.Authenticated accordingly
        'Get the values entered by the user
        Dim loginUsername As String = Username.Text
        Dim loginPassword As String = Password.Text

        'determine if the user's username/password are valid
        If Membership.ValidateUser(loginUsername, loginPassword) Then
            FormsAuthentication.SetAuthCookie(loginUsername, True)
            Response.Redirect("/desktop.aspx")
        Else
            e.Success = False
            e.ErrorMessage = "Invalid Username or Password"
        End If

    End Sub
   
   
   </script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="loginhead" runat="server">
    <title>Login</title>
   
</head>
<body>
    <form id="form1" runat="server">
    <asp:Login ID="Login1" runat="server" Width="312px">
        <LayoutTemplate>
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
                <ext:Window ID="LoginWindow" runat="server" Closable="false" Resizable="false" Height="150" Icon="Lock" Title="Login" Draggable="false" Width="350" Modal="true" BodyStyle="padding:5px;">
                    <Body>
                        <ext:FormLayout ID="FormLayout1" runat="server">
                            <ext:Anchor Horizontal="100%">
                                <ext:TextField  ID="Username" runat="server" ReadOnly="false" FieldLabel="Username" AllowBlank="false" BlankText="Your username is required." />
                            </ext:Anchor>
                            <ext:Anchor Horizontal="100%">
                                <ext:TextField ID="Password" runat="server" ReadOnly="false" InputType="Password" FieldLabel="Password" AllowBlank="false" BlankText="Your password is required." />
                            </ext:Anchor>
                            <ext:Anchor Horizontal="100%">
                                <ext:Checkbox id="RememberMe" runat="server" ReadOnly="false" FieldLabel="Remember Me" />
                            </ext:Anchor>
                        </ext:FormLayout>
                    </body>
                    <Buttons>
                        <ext:Button ID="LoginButton" ValidationGroup="Login1" runat="server" CommandName="Login1.Authenticate" Text="Login" Icon="Accept">
                            <AjaxEvents>
                               <Click OnEvent="Login1_Authenticate"></Click>
                            </AjaxEvents>                    
                        </ext:Button>
                    </Buttons>
                </ext:Window>
            </LayoutTemplate>
       </asp:Login>
    </form>
</body>

</html>





C#



<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="DriveBusiness_Tracking._Default" %>

<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<%@ Register assembly="Devart.Data.Mysql" namespace="Devart.Data.Mysql" tagprefix="ddm" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
   protected void Login1_Authenticate(object sender, Coolite.Ext.Web.AjaxEventArgs e)
{
          
    //We need to determine if the user is authenticated and set e.Authenticated accordingly
    //Get the values entered by the user
    string loginUsername = Username.Text;
    string loginPassword = Password.Text;

    //determine if the user's username/password are valid
    if (Membership.ValidateUser(loginUsername, loginPassword)) {
        FormsAuthentication.SetAuthCookie(loginUsername, true);
        Response.Redirect("/desktop.aspx");
    }
    else {
        e.Success = false;
        e.ErrorMessage = "Invalid Username or Password";
       
    }
}
   
   </script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="loginhead" runat="server">
    <title>Login</title>
   
</head>
<body>
    <form id="form1" runat="server">
    <asp:Login ID="Login1" runat="server" Width="312px">
        <LayoutTemplate>
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
                <ext:Window ID="LoginWindow" runat="server" Closable="false" Resizable="false" Height="150" Icon="Lock" Title="Login" Draggable="false" Width="350" Modal="true" BodyStyle="padding:5px;">
                    <Body>
                        <ext:FormLayout ID="FormLayout1" runat="server">
                            <ext:Anchor Horizontal="100%">
                                <ext:TextField  ID="Username" runat="server" ReadOnly="false" FieldLabel="Username" AllowBlank="false" BlankText="Your username is required." />
                            </ext:Anchor>
                            <ext:Anchor Horizontal="100%">
                                <ext:TextField ID="Password" runat="server" ReadOnly="false" InputType="Password" FieldLabel="Password" AllowBlank="false" BlankText="Your password is required." />
                            </ext:Anchor>
                            <ext:Anchor Horizontal="100%">
                                <ext:Checkbox id="RememberMe" runat="server" ReadOnly="false" FieldLabel="Remember Me" />
                            </ext:Anchor>
                        </ext:FormLayout>
                    </body>
                    <Buttons>
                        <ext:Button ID="LoginButton" ValidationGroup="Login1" runat="server" CommandName="Login1.Authenticate" Text="Login" Icon="Accept">
                            <AjaxEvents>
                               <Click OnEvent="Login1_Authenticate"></Click>
                            </AjaxEvents>                    
                        </ext:Button>
                    </Buttons>
                </ext:Window>
            </LayoutTemplate>
       </asp:Login>
    </form>
</body>

</html>



Hope this helps
Last Login: 7/8/2010 1:50:34 AM
Posts: 4,722,
Posted 3/4/2010 8:28:19 AM

Group: Core Development Team
Thanks for posting this example!

--
Geoffrey McGill
Coolite Inc.
Development Team
Skype : geoffrey.mcgill
Forum Guidelines | Coolite Examples | Coolite API Docs | ExtJS API Docs | Twitter
Last Login: 4/26/2010 7:00:20 AM
Posts: 25,
Posted 3/5/2010 1:09:23 AM

Group: Coolite Early Adopter
No problem geoffrey,

If i get some time over the weekend I'm looking at possibly creating a new <ext:loginwindow> control

Just need to have a proper look through the coolite source

Last Login: 6/7/2010 10:36:04 PM
Posts: 22,
Posted 5/14/2010 5:37:30 AM

Group: Coolite Early Adopter
Hello Craig,

Good work! I'm looking forward to use your Login Control

FYI, I'm working on a web application that need "Forgot Password", "Add New User" and "Change Password" features. Do you have any sample on these?

Thanks.

Regards,
JeeShen Lee
+012- 904 2869
« Prev Topic | Next Topic »
Reading This Topic
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.
All times are GMT -5:00, Time now is 8:34pm