Browse Source

修改登录验证方式

callm 5 months ago
parent
commit
59d92307ae
2 changed files with 60 additions and 1 deletions
  1. 1 1
      UAS_MES_BG/Login.cs
  2. 59 0
      UAS_MES_BG/PublicMethod/LogicHandler.cs

+ 1 - 1
UAS_MES_BG/Login.cs

@@ -100,7 +100,7 @@ namespace UAS_MES_NEW
             SystemInf.dh = dh;
             string ErrorMessage = "";
             //验证用户名和密码
-            if (LogicHandler.CheckUserLogin(UserName.Text, PassWord.Text, out ErrorMessage))
+            if (LogicHandler.CheckUserLogin(UserName.Text, PassWord.Text, DBUser, out ErrorMessage))
             {
                 //验证岗位资源,通过验证开启主窗体
                 if (LogicHandler.CheckUserAndResourcePassed(UserName.Text, Source.Text, out ErrorMessage))

+ 59 - 0
UAS_MES_BG/PublicMethod/LogicHandler.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.IO;
+using System.Net;
 using System.Text;
 using System.Windows;
 using System.Windows.Forms;
@@ -89,6 +91,63 @@ namespace UAS_MES_NEW.PublicMethod
             }
         }
 
+        public static bool CheckUserLogin(string iUserCode, string iPassWord, string Master, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            try
+            {
+                string url = "http://192.168.1.92:8088/mes/" + "mobile/login.action";//html调用的地址              
+                HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
+                if (webrequest == null)
+                {
+                    return false;
+                }
+                webrequest.Method = "POST";
+                webrequest.Timeout = 1000;
+                webrequest.ContentType = "application/x-www-form-urlencoded";
+                System.Collections.Hashtable pars = new System.Collections.Hashtable();
+                pars.Add("username", iUserCode);
+                pars.Add("password", iPassWord);
+                pars.Add("master", Master);
+                string buffer = "";
+                //发送POST数据 
+                if (!(pars == null || pars.Count == 0))
+                {
+                    foreach (string key in pars.Keys)
+                    {
+                        buffer = buffer + "&" + key + "=" + pars[key].ToString();
+                    }
+                    byte[] data = Encoding.UTF8.GetBytes(buffer);
+                    using (Stream stream = webrequest.GetRequestStream())
+                    {
+                        stream.Write(data, 0, data.Length);
+                    }
+                }
+
+                string[] values = webrequest.Headers.GetValues("Content-Type");
+                WebResponse myResponse = webrequest.GetResponse();
+
+                using (Stream resStream = myResponse.GetResponseStream())//得到回写的流
+                {
+                    StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
+                    string Content = newReader.ReadToEnd();
+                    Dictionary<string, object> dic = new Dictionary<string, object>();
+                    dic = BaseUtil.ToDictionary(Content);
+                    if (!dic.ContainsKey("erpaccount"))
+                    {
+                        oErrorMessage = dic["reason"].ToString();
+                        return false;
+                    }
+                    newReader.Close();
+                }
+            }
+            catch (Exception ex)
+            {
+                LogManager.DoLog(ex.Message.ToString());
+            }
+            return true;
+        }
+
         /// <summary>
         /// 记录登陆信息
         /// </summary>