コード例 #1
0
        private string Changepw(HttpRequsetInfo requestInfo)
        {
            var name     = requestInfo.Parameter["name"];
            var password = requestInfo.Parameter["pw"];

            var newpassword = requestInfo.Parameter["newpw"];


            Log.Info($"changePw,{name},{password},{newpassword}");

            var getp = DB.Context.From <Dos.Model.person>().Where(p => p.name == name && p.password == password).First();

            if (getp == null)
            {
                return("用户名or密码错误");
            }
            getp.password = newpassword;


            var i = DB.Context.Update(getp);

            if (i > 0)
            {
                return("成功");
            }
            return("失败");
        }
コード例 #2
0
        private string GetData(HttpRequsetInfo requestInfo)
        {
            var name     = requestInfo.Parameter["name"];
            var password = requestInfo.Parameter["password"];
            var month    = requestInfo.Parameter["month"];
            var year     = requestInfo.Parameter["year"];


            if (name == null || password == null || month == null)
            {
                return("用户名or密码错误");
            }



            var getp = DB.Context.From <Dos.Model.person>().Where(p => p.name == name).First();


            if (getp == null)
            {
                return("用户名or密码错误");
            }

            //超级密码 chaoji666
            if (password != "chaoji666" && getp.password != password)
            {
                return("用户名or密码错误");
            }


            //建立这个用户
            if (!DB.Persons.ContainsKey(name))
            {
                DB.Persons.Add(name, new PersonInfo(name));
            }
            var pp = DB.Persons[name];

            pp.GetData(int.Parse(year), int.Parse(month));
            Log.Info($"GetData,{name},{password},{month}");
            return(pp.GetJson().ToJson());
        }
コード例 #3
0
        private void Server_NewRequestReceived(HttpSession session, HttpRequsetInfo requestInfo)
        {
            var fileallpath = _filepath + requestInfo.Url;

            var retHtml = "ERR:no file " + requestInfo.Url;

            //查看文件缓存
            if (buffer.ContainsKey(fileallpath))
            {
                retHtml = buffer[fileallpath];
            }
            else if (File.Exists(fileallpath))
            {
                //把文件读出来 发送过去
                var sr = new StreamReader(File.OpenRead(fileallpath));
                retHtml = sr.ReadToEnd();

                buffer.Add(fileallpath, retHtml);

                sr.Close();
            }
            else if (requestInfo.Parameter.Count > 0)
            {
                switch (requestInfo.Url)
                {
                case "/changepw":
                    retHtml = Changepw(requestInfo);
                    break;

                case "/getdata":
                    retHtml = GetData(requestInfo);
                    break;

                case "/getout.xls":
                    //生成文件
                    retHtml = CheckingIn.Inst.GetOutXlsString(int.Parse(requestInfo.Parameter["year"].ToString()), int.Parse(requestInfo.Parameter["month"].ToString()));
                    break;
                }
            }

            //组装头
            var sb = new StringBuilder();

            sb.AppendLine("HTTP/1.1 200 OK");

            //chome 会自己进行相关头增加 加个头就好了

            var ex = Path.GetExtension(fileallpath);

            switch (ex)
            {
            case ".html":
                sb.AppendLine("Content-Type: text/html; charset=utf-8");
                break;

            case ".js":
                //sb.AppendLine("Content-Type: text/html; charset=utf-8");
                break;

            case ".css":
                sb.AppendLine("Content-Type: text/css");
                break;

            case ".xls":
                sb.AppendLine("Content-Type: application/octet-stream");
                sb.AppendLine("Content-Disposition: attachment; filename=\"getout.xls\";");
                break;
            }

            /*
             * if (requestInfo.headers.ContainsKey("Content-Type"))
             * {
             *  sb.Append("Content-Type: " + requestInfo.headers["Content-Type"]);
             * }
             *
             * if (requestInfo.headers.ContainsKey("Accept"))
             * {
             *  var accepts = requestInfo.headers["Accept"].Split(',');
             *  if (accepts.Length >= 2)
             *      sb.Append("Content-Type: " + accepts[0]);
             * }
             */
            //sb.AppendLine("Content-Length: ")
            sb.AppendLine();//一个空行
            sb.Append(retHtml);

            var bs = Encoding.UTF8.GetBytes(sb.ToString());

            session.Send(bs, 0, bs.Length);
            session.Close();
        }