122 lines
4.0 KiB
C#
122 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Runtime.Serialization.Json;
|
|
using System.Web.SessionState;
|
|
using Dapper;
|
|
using Dapper.Contrib.Extensions;
|
|
using System.Data.SqlClient;
|
|
using System.IO.Compression;
|
|
|
|
namespace abbott_2024_event.BackEnd.api
|
|
{
|
|
/// <summary>
|
|
/// clearLineUid 的摘要描述
|
|
/// </summary>
|
|
public class clearLineUid : IHttpHandler
|
|
{
|
|
SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString"));
|
|
public authToken authToken;
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
result objRet = new result();
|
|
DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType());
|
|
context.Response.ContentType = "application/json;charset=utf-8";
|
|
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToString().ToUpperInvariant();
|
|
if (!String.IsNullOrEmpty(acceptEncoding))
|
|
{
|
|
if (acceptEncoding.Contains("GZIP"))
|
|
{
|
|
//输出流头部GZIP压缩
|
|
context.Response.AppendHeader("Content-encoding", "gzip");
|
|
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
|
|
}
|
|
else if (acceptEncoding.Contains("DEFLATE"))
|
|
{
|
|
//输出流头部DEFLATE压缩
|
|
context.Response.AppendHeader("Content-encoding", "deflate");
|
|
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
|
|
}
|
|
}
|
|
|
|
authToken objAuth = new authToken();
|
|
|
|
if (!objAuth.user_isLogin)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0001";
|
|
objRet.message = "尚未登入,請登入後使用";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
string line_uid = (context.Request["line_uid"] == null) ? "" : context.Request["line_uid"].ToString();
|
|
|
|
if (line_uid == "")
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "2001";
|
|
objRet.message = "line_uid為空字串!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
string myIP = globalClass.GetIPAddress();
|
|
|
|
if (myIP == "::1")
|
|
{
|
|
myIP = "127.0.0.1";
|
|
}
|
|
|
|
Boolean isAllow = false;
|
|
|
|
if (myIP == "127.0.0.1")
|
|
{
|
|
isAllow = true;
|
|
}
|
|
|
|
string myIP_2 = myIP.Substring(0, myIP.LastIndexOf('.'));
|
|
|
|
if (myIP_2 == "60.251.161")
|
|
{
|
|
isAllow = true;
|
|
}
|
|
|
|
//isAllow = false;
|
|
|
|
if (isAllow == false)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0002";
|
|
objRet.message = "IP錯誤無法操作!";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
conn.Execute("delete from babyRec where line_uid = @line_uid ", new { line_uid = line_uid });
|
|
conn.Execute("delete from babyData where line_uid = @line_uid ", new { line_uid = line_uid });
|
|
conn.Execute("delete from lineUser where line_uid = @line_uid ", new { line_uid = line_uid });
|
|
|
|
objRet.ret = "yes";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
public class result
|
|
{
|
|
public string ret = "no";
|
|
public string err_code = "0000";
|
|
public string message = "";
|
|
}
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |