Ajax 비동기 로그 인 요청
24317 단어 데이터Ajax 비동기 로그 인 요청
1. 먼저 제3자 의 물건 을 가 져 옵 니 다
- <link href="../Css/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
- <script src="../member/js/jquery-1.7.2.js" type="text/javascript"></script>
- <script src="../SWFUpload/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
2. html 폼 꺼 내기
- <body>
- <form id="form1" runat="server">
- <div>
- <div>
- <div id="divLogin" style="display: none">
- <a id="linkUserName"></a><a id="linkLogout" href="void(0)"< /span>> </a>
- </div>
- <div id="divNotLogin" style="display: none">
- <a href="void(0)"< /span> id="linkLogin"> </a>
- </div>
- <div id="dlgLogin" style="display: none">
- :<input type="text" id="txtLoginUserName" /><br />
- :<input type="password" id="txtLoginPassword" /><br />
- <div id="divLoginMsg" style="color: Red">
- </div>
- <br />
- <input type="button" id="btnLogin" value=" " />
- </div>
- </div>
- </form>
- </body>
||||| Jquery
- <script type="text/javascript">
- $(function(){
- CheckLogin();//
- //
- $("#btnLogin").click(function(){
- userLogin();//
- location.href="/member/BookShow_UI.aspx";//
- });
- // JqueryUI
- $("#linkLogin").click(function () {
- $("#dlgLogin").dialog({
- modal: true,
- buttons: {
- Ok: function () {
- $(this).dialog('close');
- }
- }
- });
- });
- //
- function userLogin(){
- //
- var name=$("#txtLoginUserName").val();
- var pwd=$("#txtLoginPassword").val();
- //
- if(name!="" && pwd!=null){
- $.post("/ashx/Login.ashx",{"action":"login","textName":name,"textPwd":pwd},function(data){
- var str=data.split(":");
- var s = data.split(":");
- if (s[0] == "0k") {
- $("#divLogin").show();
- $("#linkUserName").text(s[1]);
- //
- $("#dlgLogin").dialog('close');
- $("#divNotLogin").hide();
- $("#dlgLogin").hide();
- } else if (s[0] == "no") {
- $("#divLogin").hide();
- $("#divNotLogin").show();
- } else {
- alert(" ");
- return false;
- }
- });
- }
- };
- //
- function CheckLogin() {
- $.post("/ashx/Login.ashx", { "action": "check" }, function (data) {
- var s = data.split(":");
- if (s[0] == "ok") {//ok
- $("#divLogin").show();
- $("#linkUserName").text(s[1]);
- $("#divNotLogin").hide();
- $("#dlgLogin").hide();
- } else if (s[0] == "no") {
- $("#divLogin").hide();
- $("#divNotLogin").show();
- } else {
- alert(" !!");
- }
- });
- }
- </scirpt>
========================================
,Seesion["User"]=user,
Session 。 System.Web.SessionSatae.IRequiresSessionState
1. check login
string action=context.Request.Form["action"];// check login
// ,
- if(action=="check"){
- //
- if(context.Session["User"]!=null)
- {
- // Seesion
- context.Response.Write("ok:"+(((Model.User)context.Session["User"])).LoginId);
- }else{
- context.Response.Write("no:");
- }
- }else if(action=="login"){
- //
- string textName=context.Request.Form["textName"];
- string textPwd=context.Request.Form["textPwd"];
- // BLL
- BLL.UserManger bll=new BLL.UserManager();
- // Model
- Model.User model=null;
- //
- string msg=string.Empty;
- // bll
- bool b=bll.GetCheckUserLogin(textName,textPwd,out msg,out model);
- // b true;
- if(b){
- context.Session["User"]=model;
- context.Response.Write("ok:"+model.LoginId);
- }else{
- context.Response.Write("on:");
- }
- }
bll GetCheckUserLogin(string name,string pwd,out string msg,out Model.User user)
- //
- public bool GetCheckUserLogin(string name,string pwd,out string msg out Model.User user)
- {
- // DAL
- DAL.UserServices dal=new DAL.UserServices();
- user=dal.GetModel(name);//
- //
- if(user!=null)
- {
- //
- if(user.UserState.Name==" ")
- {
- //
- if(user.LoginPwd=="pwd")
- {
- msg=" ";
- return true;
- }else{
- msg=" ";
- return false;
- }
- }else{
- msg=" ";
- return false;
- }
- }else{
- msg=" ";
- return false;
- }
- }