You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
339 lines
13 KiB
339 lines
13 KiB
|
|
using EasyBL.WebApi;
|
|
using EasyBL.WebApi.Common;
|
|
using EasyBL.WebApi.Message;
|
|
using EasyNet;
|
|
using Entity;
|
|
using Entity.ShowEasyDtos;
|
|
using Entity.Sugar;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using SqlSugar.Base;
|
|
using System;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web;
|
|
|
|
namespace EasyBL.WEBAPP.SYS
|
|
{
|
|
public class MembersService : ServiceBase
|
|
{
|
|
|
|
#region 用戶登錄
|
|
public HttpResponseMessage Login(Login dto)
|
|
{
|
|
SuccessResponseMessage srm = null;
|
|
string sError = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var sUserID = dto.Account;
|
|
var sPassword = dto.Password;
|
|
if (string.IsNullOrWhiteSpace(sUserID))
|
|
{
|
|
sError = @"帳號不能為空"; //帳號不能為空
|
|
break;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(sPassword))
|
|
{
|
|
sError = @"密碼不能為空"; //密碼不能為空
|
|
break;
|
|
}
|
|
var sEncryptPwd = SecurityUtil.Encrypt(sPassword);//將輸入之密碼轉換驗證格式
|
|
//string sPwd1 = SecurityUtil.Decrypt("wTBo6uXVBlVH8Ms76xiE4w==");
|
|
//string sPwd1 = SecurityUtil.Decrypt("3EOyqH52VBUg3pj5Wy0rwQ==");
|
|
var oUser = db.Queryable<SETB_CMS_Member>().Single(x => x.Account == sUserID && x.Password == sEncryptPwd);
|
|
|
|
if (oUser == null)
|
|
{
|
|
sError = @"帳號或密碼不正確"; //帳號或密碼不正確
|
|
break;
|
|
}
|
|
|
|
if (oUser.Status != @"1")
|
|
{
|
|
sError = @"該帳號未啓用"; //該帳號無效
|
|
break;
|
|
}
|
|
|
|
var ticket = new OTB_SYS_TicketAuth
|
|
{
|
|
OrgID = oUser.OrgID,
|
|
UserID = oUser.Account,
|
|
UserName = oUser.FirstName,
|
|
Token = SignExtension.CreateToken(),
|
|
// LoginIp = i_crm.ClientIP,
|
|
LoginTime = DateTime.Now
|
|
};
|
|
var iExpireTime = 240;
|
|
var sExpireTime = Common.GetSystemSetting(db, oUser.OrgID, @"ExpireTime");
|
|
if (!string.IsNullOrEmpty(sExpireTime))
|
|
{
|
|
iExpireTime = int.Parse(sExpireTime);
|
|
}
|
|
else
|
|
{
|
|
iExpireTime = int.Parse(Common.GetAppSettings(@"ExpireTime"));
|
|
}
|
|
ticket.ExpireTime = DateTime.Now.AddMinutes(iExpireTime); //30分钟过期
|
|
ticket.IsVerify = @"Y";
|
|
var oTicket = db.Queryable<OTB_SYS_TicketAuth>().Single(x => x.OrgID == oUser.OrgID && x.UserID == oUser.Account);
|
|
if (oTicket != null)
|
|
{
|
|
db.Updateable(ticket).IgnoreColumns(x => x.OutlookId).Where(x => x.NO == oTicket.NO).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
ticket.CreateTime = DateTime.Now;
|
|
db.Insertable(ticket).ExecuteCommand();
|
|
}
|
|
//記錄log日誌
|
|
db.Insertable(new OTB_SYS_LoginLog
|
|
{
|
|
OrgId = ticket.OrgID,
|
|
UserId = ticket.UserID,
|
|
UserName = ticket.UserName,
|
|
LoginIp = ticket.LoginIp,
|
|
LoginTime = ticket.LoginTime
|
|
}).ExecuteCommand();
|
|
HttpRuntimeCache.Set(ticket.OrgID + ticket.UserID, ticket, iExpireTime * 60, true);
|
|
HttpContext.Current.Session.Add(@"orgid", ticket.OrgID);
|
|
HttpContext.Current.Session.Add(@"userid", ticket.UserID);
|
|
HttpCookie cookie = new HttpCookie("EURO_COOKIE");//初始化並設置Cookie的名稱
|
|
DateTime dt = DateTime.Now;
|
|
TimeSpan ts = new TimeSpan(0, 0, 1, 0, 0);//過期時間為1分鐘
|
|
cookie.Expires = dt.Add(ts);//設置過期時間
|
|
cookie.Values.Add("orgid", ticket.OrgID);
|
|
cookie.Values.Add("userid", ticket.UserID);
|
|
HttpContext.Current.Response.AppendCookie(cookie);
|
|
var jo = new SetMap
|
|
{
|
|
{ @"orgid", ticket.OrgID },
|
|
{ @"userid", ticket.UserID },
|
|
{ @"loginname", ticket.UserName },
|
|
{ @"token", ticket.Token }
|
|
|
|
};
|
|
srm = new SuccessResponseMessage(null, null);
|
|
srm.DATA.Add(BLWording.REL, jo);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sError = Util.GetLastExceptionMsg(ex);
|
|
}
|
|
finally
|
|
{
|
|
if (null != sError)
|
|
{
|
|
srm = new SuccessResponseMessage(null, null)
|
|
{
|
|
STATUSCODE = (int)StatusCodeEnum.Error,
|
|
MSG = sError
|
|
};
|
|
}
|
|
}
|
|
|
|
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
//會員個人訊息查詢
|
|
public HttpResponseMessage GetMemberInfo(string OrgID, string Account)
|
|
{
|
|
SuccessResponseMessage srm = null;
|
|
string sError = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
string requestUrl = Common.ConfigGetValue("", "ida:RedirectUri");
|
|
var saCountry = db.Queryable<SETB_CMS_Member>()
|
|
//搜尋條件
|
|
.Where(x => x.OrgID == OrgID && x.Account == Account)
|
|
.Single();
|
|
|
|
var sFilePath = db.Queryable<OTB_SYS_Files>()
|
|
.Where(x => x.ParentID == saCountry.MemberID)
|
|
.Single();
|
|
|
|
saCountry.MemberPicture = requestUrl + "/" + sFilePath.FilePath.Replace("\\", "/");
|
|
var iRel = db.Insertable(saCountry).ExecuteCommand();
|
|
|
|
//返回user信息
|
|
srm = new SuccessResponseMessage(null, null);
|
|
srm.DATA.Add(BLWording.REL, iRel);
|
|
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sError = Util.GetLastExceptionMsg(ex);
|
|
srm = new SuccessResponseMessage(null, null)
|
|
{
|
|
STATUSCODE = (int)StatusCodeEnum.Error,
|
|
MSG = StatusCodeEnum.Error.GetEnumText()
|
|
};
|
|
}
|
|
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
|
|
}
|
|
|
|
#region 修改會員個人信息
|
|
/// <summary>
|
|
/// 修改會員個人信息
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public HttpResponseMessage Update(MemberDTO Member)
|
|
{
|
|
SuccessResponseMessage srm = null;
|
|
string sError = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var iRel = db.Updateable(MemberDTOtoEntity(Member))
|
|
.Where(t1 => t1.Account == Member.Account)
|
|
.ExecuteCommand();
|
|
srm = new SuccessResponseMessage(null, null);
|
|
srm.DATA.Add(BLWording.REL, iRel);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sError = Util.GetLastExceptionMsg(ex);
|
|
srm = new SuccessResponseMessage(null, null)
|
|
{
|
|
STATUSCODE = (int)StatusCodeEnum.Error,
|
|
MSG = StatusCodeEnum.Error.GetEnumText()
|
|
};
|
|
srm.DATA.Add(BLWording.REL, "");
|
|
}
|
|
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
|
|
}
|
|
#endregion
|
|
|
|
#region Upload 上傳文件
|
|
|
|
public HttpResponseMessage Upload()
|
|
{
|
|
SuccessResponseMessage srm = null;
|
|
string sError = null;
|
|
try
|
|
{
|
|
var c = HttpContext.Current;
|
|
|
|
var sGUID = Guid.NewGuid().ToString();
|
|
|
|
SECommonService commonService = new SECommonService();
|
|
// 文件上傳
|
|
HttpResponseMessage ret = commonService.Upload(c);
|
|
if (ret.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
|
|
var db = SugarBase.DB;
|
|
SETB_CMS_Member i_crm = new SETB_CMS_Member();
|
|
//// 缺userid 和orgid
|
|
var iRel = db.Updateable(i_crm).ExecuteCommand();
|
|
srm = new SuccessResponseMessage(null, null);
|
|
srm.DATA.Add(BLWording.REL, iRel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sError = Util.GetLastExceptionMsg(ex);
|
|
srm = new SuccessResponseMessage(null, null)
|
|
{
|
|
STATUSCODE = (int)StatusCodeEnum.Error,
|
|
MSG = StatusCodeEnum.Error.GetEnumText()
|
|
};
|
|
srm.DATA.Add(BLWording.REL, "");
|
|
}
|
|
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
|
|
}
|
|
|
|
|
|
#endregion Upload 上傳文件
|
|
|
|
//註銷帳號
|
|
public HttpResponseMessage DeactivateAccount(string OrgID, string Account)
|
|
{
|
|
//string sMsg = null;
|
|
SuccessResponseMessage srm = SugarBase.ExecTran(db =>
|
|
{
|
|
do
|
|
{
|
|
|
|
var sUser = db.Queryable<SETB_CMS_Member>().Single(x => x.OrgID == OrgID && x.Account == Account);
|
|
|
|
|
|
sUser.Status = "2"; //會員狀態為刪除
|
|
var iRel = db.Updateable(sUser).ExecuteCommand();
|
|
|
|
srm = new SuccessResponseMessage(null, null);
|
|
srm.DATA.Add(BLWording.REL, sUser.Status);
|
|
} while (false);
|
|
|
|
return srm;
|
|
|
|
});
|
|
|
|
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
|
|
}
|
|
|
|
//重設密碼
|
|
public HttpResponseMessage ResetNewPassword(string OrgID, string Account, string Password)
|
|
{
|
|
//string sMsg = null;
|
|
SuccessResponseMessage srm = SugarBase.ExecTran(db =>
|
|
{
|
|
do
|
|
{
|
|
var sUser = db.Queryable<SETB_CMS_Member>().Single(x => x.OrgID == OrgID && x.Account == Account);
|
|
sUser.Password = SecurityUtil.Encrypt(Password); //新密碼加密
|
|
var iRel = db.Updateable(sUser).ExecuteCommand(); //將新密碼更新至資料庫
|
|
|
|
srm = new SuccessResponseMessage(null, null);
|
|
srm.DATA.Add(BLWording.REL, sUser.MemberID);
|
|
} while (false);
|
|
|
|
return srm;
|
|
|
|
});
|
|
|
|
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
|
|
}
|
|
|
|
private SETB_CMS_Member MemberDTOtoEntity(MemberDTO Member)
|
|
{
|
|
|
|
SETB_CMS_Member rsMember = new SETB_CMS_Member();
|
|
|
|
rsMember.MemberID = Member.MemberID;
|
|
rsMember.MemberPicture = Member.MemberPicture;
|
|
rsMember.FirstName = Member.FirstName;
|
|
rsMember.LastName = Member.LastName;
|
|
rsMember.Title = Member.Title;
|
|
rsMember.MemberType = Member.MemberType;
|
|
rsMember.Account = Member.Account;
|
|
rsMember.Password = Member.Password;
|
|
rsMember.Email = Member.Email;
|
|
rsMember.Phone = Member.Phone;
|
|
rsMember.CountryID = Member.CountryID;
|
|
rsMember.ArgumentID = Member.LanguageID;
|
|
rsMember.BirthDate = Member.BirthDate;
|
|
rsMember.Status = Member.Status;
|
|
rsMember.OrgID = Member.OrgID;
|
|
|
|
return rsMember;
|
|
|
|
}
|
|
|
|
}
|
|
}
|