101 lines
3.1 KiB
Plaintext
101 lines
3.1 KiB
Plaintext
<%@ WebHandler Language="C#" Class="user_profile" %>
|
|
|
|
using System;
|
|
using System.Web;
|
|
using System.Runtime.Serialization.Json;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Web.Services.Protocols;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Web.SessionState;
|
|
using System.Data;
|
|
|
|
public class user_profile : IHttpHandler, IReadOnlySessionState {
|
|
|
|
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", "*");
|
|
authPermission objAuth = new authPermission();
|
|
|
|
if (!objAuth.isLogin())
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0001";
|
|
objRet.message = "尚未登入,請登入後使用";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
string user_email = (context.Request["input_email"] == null) ? "" : context.Request["input_email"].ToString();
|
|
string result = (context.Request["pic_data"] == null) ? "" : context.Request["pic_data"].ToString();
|
|
string pass = (context.Request["pass"] == null) ? "" : context.Request["pass"].ToString();
|
|
|
|
if (user_email == null || result == null)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0002";
|
|
objRet.message = "沒有資料可以儲存";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
userdata objUser = new userdata(objAuth.user_uid);
|
|
|
|
objUser.user_email = user_email;
|
|
|
|
JToken jsonObj = JValue.Parse(result);
|
|
|
|
string base64Img = "";
|
|
string picChange = jsonObj[0]["meta"]["picChange"].ToString();
|
|
|
|
if (picChange == "Y")
|
|
{
|
|
base64Img = jsonObj[0]["output"]["image"].ToString();
|
|
objUser.pic_image = globalClass.Base64ToImage(base64Img);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (objUser.updateData())
|
|
{
|
|
if (pass != "")
|
|
{
|
|
autoExecSQL objPass = new autoExecSQL(string.Format("update users set user_pwd = '{0}' where user_uid = '{1}' ", pass, objAuth.user_uid));
|
|
}
|
|
objRet.ret = "yes";
|
|
}
|
|
else
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0004";
|
|
objRet.message = objUser.update_result;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0005";
|
|
objRet.message = ex.Message;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
} |