コード例 #1
0
ファイル: AscmWebService.asmx.cs プロジェクト: gofixiao/Midea
        public bool UserAuthentication(string userId, string userPwd, string hostIP, ref string message, ref string encryptTicket)
        {
            try
            {
                message = "";
                AscmUserInfo ascmUserInfo = AscmUserInfoService.GetInstance().TryGet(userId);
                /*
                YnFrame.Dal.Entities.YnUser ynUser = YnFrame.Services.YnUserService.GetInstance().Get(userId);
                if (ynUser == null)
                {
                    //throw new Exception("用户不存在");
                    //判断是否erp用户
                    ynUser = YnFrame.Services.YnUserService.GetInstance().Get("erp_" + userId);
                    if (ynUser == null)
                    {
                        //判断是否mes用户
                    }
                }

                if (ynUser == null)
                {
                    throw new Exception("用户不存在");
                }*/
                if (!string.IsNullOrEmpty(ascmUserInfo.extExpandType))
                {
                    if (ascmUserInfo.extExpandType.Trim() == "erp")
                    {
                        if (!YnFrame.Services.YnUserService.GetInstance().ValidateUser(ascmUserInfo.userId, userPwd))
                        {
                            throw new Exception("提供的用户名或密码不正确。");
                        }
                    }
                    else if (ascmUserInfo.extExpandType.Trim() == "mes")
                    {
                        cn.com.midea.mespda.TransferService service = new cn.com.midea.mespda.TransferService();
                        cn.com.midea.mespda.OutputWebMessage message1 = service.UserLogin(ascmUserInfo.userId, userPwd);
                        if (!message1.IsSuccess)
                        {
                            throw new Exception(message1.ErrorMessage);
                        }
                    }
                }
                else
                {
                    if (!YnFrame.Services.YnUserService.GetInstance().ValidateUser(ascmUserInfo.userId, userPwd))
                    {
                        //ModelState.AddModelError("", "提供的用户名或密码不正确。");
                        throw new Exception("提供的用户名或密码不正确。");
                    }
                }

                //ynUser = YnFrame.Services.YnUserService.GetInstance().Get(userId);

                string sUserData = Newtonsoft.Json.JsonConvert.SerializeObject(ascmUserInfo.GetTicket());
                bool createPersistentCookie = false;
                DateTime dt = createPersistentCookie ? DateTime.Now.AddMinutes(99999) : DateTime.Now.AddDays(365);//用一年看他还过不过期
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                                                                                    1, // 票据版本号
                                                                                    userId.ToString(), // 票据持有者
                                                                                    DateTime.Now, //分配票据的时间
                                                                                    dt, // 失效时间
                                                                                    createPersistentCookie, // 需要用户的 cookie
                                                                                    sUserData, // 用户数据,这里其实就是用户的角色
                                                                                    FormsAuthentication.FormsCookiePath);//cookie有效路径

                ////System.Web.Security.FormsAuthenticationTicket ticket = YnFrame.Web.FormsAuthenticationService.GetInstance().GetTicket(userId, 0, ynUser, false);
                //string hash = System.Web.Security.FormsAuthentication.Encrypt(ticket);
                //HttpCookie cookie = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, hash); //加密之后的cookie
                //if (ticket.IsPersistent)
                //{
                //    cookie.Expires = ticket.Expiration;
                //}
                //encryptTicket = hash;
                ////添加cookie到页面请求响应中
                //HttpContext.Current.Response.Cookies.Add(cookie);
                encryptTicket = System.Web.Security.FormsAuthentication.Encrypt(ticket);

                //写日志
                ascmUserInfo.lastLoginIp = hostIP;
                ascmUserInfo.lastLoginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                AscmUserInfoService.GetInstance().Update(ascmUserInfo);

                return true;

            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return false;
        }
コード例 #2
0
ファイル: AscmWebService.asmx.cs プロジェクト: gofixiao/Midea
 public string MobileLogin(string userId, string userPwd, string pdaIdentity, ref string message)
 {
     string result = string.Empty;
     try
     {
         message = string.Empty;
         //if (MideaAscm.Security.Utility.GetInstance().IsPdaAuthorized(pdaIdentity))
         //{
             //string connString = System.Configuration.ConfigurationManager.ConnectionStrings["OraConnString"].ConnectionString;
             //string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.16.17.77)(PORT=1601))(CONNECT_DATA=(SERVICE_NAME=md_ascm)));User Id=ascm;Password=Ascm32@;";
             string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.16.9.191)(PORT=1522))(CONNECT_DATA=(SERVICE_NAME=md_ascm)));User Id=ascm;Password=AScm1240#;";
             AscmUserInfo ascmUserInfo = AscmUserInfoService.GetInstance().MobileLogin(userId, userPwd, connString, ref message);
             if (string.IsNullOrEmpty(message))
             {
                 if (ascmUserInfo != null)
                 {
                     if (ascmUserInfo.extExpandType == "mes")
                     {
                         cn.com.midea.mespda.TransferService service = new cn.com.midea.mespda.TransferService();
                         cn.com.midea.mespda.OutputWebMessage message1 = service.UserLogin(ascmUserInfo.userId, userPwd);
                         if (!message1.IsSuccess)
                         {
                             message = message1.ErrorMessage;
                         }
                     }
                     if (string.IsNullOrEmpty(message))
                         result = YnBaseClass2.Helper.ObjectHelper.Serialize<AscmUserInfo>(ascmUserInfo);
                 }
                 else
                     message = "用户名不正确";
             }
         //}
         //else
         //    message = "手持认证失败";
     }
     catch (Exception ex)
     {
         message = ex.Message;
     }
     return result;
 }