extjs 登录

//login.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="admin_login" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>登录</title>
    <link href="Ext/resources/css/ext-all.css" type="text/css" rel="stylesheet" />
   
   <style type="text/css">
    .user{ background:url(images/user.gif) no-repeat 1px 2px; }
    .key{ background:url(images/key.gif) no-repeat 1px 2px;  }
    
    .key,.user{
        background-color:#FFFFFF;
        padding-left:20px;
        font-weight:bold;
        color:#000033;
    }
    
</style>
   
<script src="Ext/adapter/ext/ext-base.js" type="text/javascript"></script>
<script src="Ext/ext-all.js" type="text/javascript"></script>




</head>
<body>
   
    <script type="text/javascript" language="javascript">                                                                                      
 Ext.QuickTips.init();
   Ext.form.Field.prototype.msgTarget = 'side';

 LoginWindow=Ext.extend(Ext.Window,{
     title : '登陆系统',        
    width : 265,            
    height : 170,    
     closeAction:'hide',
      closable: false,    
    collapsible : true,
        listeners:{
            "hide":function(){    },
            "show":function(LoginWindow){LoginWindow.findByType("textfield")[3].getEl().dom.src="ValidateCode.aspx";}
            },
    defaults : {            
        border : false
    },
    buttonAlign : 'center',    
        
    createFormPanel :function() {
        return new Ext.form.FormPanel( {
            bodyStyle : 'padding-top:10px',
            defaultType : 'textfield',
            labelAlign : 'right',
            labelWidth : 55,
            labelPad : 0,
            frame : true,
    
            defaults : {
                allowBlank : false,
                width : 158
            },
            items : [{
                    cls : 'user',
                    name : 'userName',
                    fieldLabel : '帐号',
                    blankText : '帐号不能为空'
                    
                }, {
                    cls : 'key',
                    name : 'password',
                    fieldLabel : '密码',
                    blankText : '密码不能为空',
                    inputType : 'password'
                    
                },{
                 fieldLabel:"验证",
                
                                       
       xtype:"panel",
       baseCls:"x-plain",
       layout:"column",
       defaultType:"textfield",
       items:[
       {  columnWidth:.65,
                xtype:"textfield",
                 cls : 'code',
                name : 'validateCode',
           blankText : '验证码不能为空',   
           allowBlank: false,
                style: 'background-color:#FFFFFF;font-weight:bold;color:#000033;padding-left:20px;' },
        
        {columnWidth:.04,xtype:"panel",baseCls:"x-plain"},
        
         {        columnWidth:.31,                                                
                layout:"form",                                                        
                inputType:"image",                                                        
                height:18,                                                    
                width:50,
                id:'verify_code',
                name:'verify_code',
            listeners:{
                                                            
                    "focus":function(){                                    
                        this.ownerCt.ownerCt.findByType("textfield")[2].focus();
                        this.ownerCt.ownerCt.findByType("textfield")[3].getEl().dom.src="ValidateCode.aspx?t="+new Date();
                                      }
                     }                                    
        }]
        }]
    });
    },    
    
    
                            
    login:function() {
    if(this.fp.form.isValid()){
            this.fp.form.submit({
                        url : 'Portal.aspx',
                    waitMsg : '正在登录......',
                    method: 'POST',
                    success : function(form, action) {
                    var loginResult = action.result.success;
                            if(loginResult == false){
                                Ext.Msg.alert('提示', action.result.msg);
                            } 
                            else
                            {
                                if(loginResult == true){
                                 window.location.href = 'Default.aspx';
                                  }
                          }  
                    },
                    failure : function(form, action) {
                    form.reset();    
                    
                    switch (action.failureType){
                               case Ext.form.Action.CLIENT_INVALID:
                                   // Ext.Msg.alert("Failure", "Form fields may not be submitted with invalid values");
                                   Ext.Msg.alert("错误", "提交的表单数据无效,请检查!");
                                    break;
                               case Ext.form.Action.CONNECT_FAILURE:
                                   // Ext.Msg.alert("Failure", "Ajax communication failed");
                                   Ext.Msg.alert("错误", "服务器连接失败,请稍后再试!");
                                   break;
                              case Ext.form.Action.SERVER_INVALID:
                                //  Ext.Msg.alert("Failure", action.result.msg);
                                   Ext.Msg.alert("错误", action.result.msg);
                          }
                                    
                    }
                });
        }
        },
    initComponent : function(){
        this.keys={
            key: Ext.EventObject.ENTER,
            fn: this.login,
            scope: this};
        LoginWindow.superclass.initComponent.call(this);       
        this.fp=this.createFormPanel();
        this.add(this.fp);
        this.addButton('登陆',this.login,this);
        this.addButton('重置', function(){this.fp.form.reset();},this);
     }     
 }); 

Ext.onReady(function()
{
    var win=new LoginWindow();
    win.show();
    
    new Ext.ToolTip({target: 'verify_code', width:120, html: '看不清? 点击刷新',trackMouse:true});


}
);
                         

                     
                         
</script>
   
</body>
</html>

 

//Portal.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Form_Portal : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            CheckUser();
        }
    }

    private void CheckUser()
    {
        string name = Request.Params["userName"];
        string pwd = Request.Params["password"];
        string code = Request.Params["validateCode"];

        if (code != Session["CheckCode"].ToString())
        {
            Response.Write("{\"success\":false,msg:\"验证码错误!\"}");
        }
        else
        {
            if (name != "" & pwd != "")
            {
                bool a = ret();
                if (a)
                {
                    Session["LoginName"] = name;
                    Response.Write("{\"success\":true,msg:\"登录成功!\"}");
                }

                else
                {
                    Response.Write("{\"success\":false,msg:\"用户名或密码错误!\"}");
                }
            }
        }
    }

    public bool ret()
    {
        bool flag = false;
        string name = Request.Params["userName"];
        string pwd = Request.Params["password"];
        db s = new db();
        int count = 0;
        count = s.ReturnSQL("select count(*) from admin where userName='" + name + "' and userPass='" + pwd + "'");
        if( count>0) 
        {
            flag= true;
        }
        return flag;
    }

  
}

 

//ValidateCode.aspx.cs

using using using using using using using using using using using public partial class ValidateCode Page
    private void object EventArgs //每次载入时执行创建验证码图像并填写验证码字符函数,保证每次刷新的验证码都不同。
            this#region override protected void EventArgs //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            base/// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void thisnew EventHandlerthis#endregion

        private string //产生随机验证码字符函数
        int char string StringRandom new Randomfor int //字符和数字的混合.长度为4。其实i的大小可以自由设置
            if //偶数
                    char'0' charelse
                    char'A' char//esponse.Cookies.Add(new HttpCookie("CheckCode", checkCode));
            //把产生的验证码保存到COOKIE中
            "CheckCode"return //返回结果以供CreateCheckCodeImage()函数使用
        //以下函数是创建验证码图像并填写验证码字符

        private void string if null Stringreturn//先判断传入的验证码是否有效或非空

            Bitmap new BitmapintMath//用指定的大小初始化Bitmap类创建图像对象
            Graphics Graphics//表示在指定的图像上写字

            try
            //生成随机生成器
                Random new Random//清空图片背景色
                Color//画图片的背景噪音线
                for int int int int int new PenColor//用银色笔在图像区域内划线形成背景噪音线

                Font new Font"Arial"FontStyleFontStyle//设置验证码的字体属性
                LinearGradientBrush new LinearGradientBrushnew RectangleColorColortrue//用画笔画出高级的2D向量图形字体
                //以字符串的形式输出

                //画图片的前景噪音点
                for int //i的大小可以自由设置
                int int Color//随机设置图像的像素

                //画图片的边框线
                new PenColor//用银色笔画出边框线

                MemoryStream new MemoryStream//申明一个内存流对象
                ImageFormat//把生成的gif以字节数组的形式保存在内存里
                //清空缓冲区中的内容
                "image/Gif"//输出内容的类型,即以gif的文件格式输出
                //把字节数组一二进制的形式输出,即以基本数据类型形式输出
            finally
            //释放绘图对象
                //释放图像对象
            

//Request.Cookies["CheckCode"].Value



本文转自曾祥展博客园博客,原文链接:http://www.cnblogs.com/zengxiangzhan/archive/2009/10/19/1585923.html,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值