/// <summary> /// 从客户端Cookie中读取管理员信息 /// </summary> /// <returns></returns> private DB.Entity.Base.AccountPO ReadAdminInfoFromCookie() { FormsAuthenticationTicket ticket = null; try { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { ticket = FormsAuthentication.Decrypt( Request.Cookies[FormsAuthentication.FormsCookieName].Value); } } catch (Exception) { ticket = null; } if (ticket != null) { var adminDal = new DB.BLL.Base.AccountBO(); DB.Entity.Base.AccountPO entity = adminDal.FindByID(ticket.UserData.ToInt()); if (entity != null) { Session[Config.SessionName] = entity; } return(entity); } return(null); }
/// <summary> /// 从客户端Cookie中读取管理员信息 /// </summary> /// <returns></returns> private DB.Entity.Base.AccountPO ReadAdminInfoFromCookie() { FormsAuthenticationTicket ticket = null; try { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { ticket = FormsAuthentication.Decrypt( Request.Cookies[FormsAuthentication.FormsCookieName].Value); } } catch (Exception) { ticket = null; } if (ticket != null) { DB.Entity.Base.AccountPO entity = Utility.DataCache.Account.GetEntity(ticket.UserData); if (entity != null) { Session[Utility.Config.SessionName] = entity; } return(entity); } return(null); }
public static Account Refresh(DB.Entity.Base.AccountPO entity) { var cacheKey = Utility.Config.CacheKeyPrefix + ".acc." + entity.Id; var model = new Account(entity); Utility.Common.Cache.Insert(cacheKey, model); return(model); }
/// <summary> /// 保存管理员身份信息 /// </summary> /// <param name="entity"></param> /// <param name="saveCookie"></param> /// <returns></returns> public bool SetAuthorizedAdminTiket(DB.Entity.Base.AccountPO entity, bool saveCookie) { Session[Config.SessionName] = entity; try { var ticket = new FormsAuthenticationTicket(1, entity.Email, DateTime.Now, DateTime.Now.AddMonths(1), true, entity.Id + ""); string encTicket = FormsAuthentication.Encrypt(ticket); if (saveCookie) { WriteCookieToClient(FormsAuthentication.FormsCookieName, encTicket); } return(true); } catch (Exception ex) { Logger.Error(ex); return(false); } }
/// <summary> /// 保存会员身份信息 /// </summary> /// <param name="entity"></param> /// <param name="saveCookie"></param> /// <returns></returns> public bool SetAuthorizedAccountTiket(DB.Entity.Base.AccountPO entity, bool saveCookie) { Session[Utility.Config.SessionName] = entity; try { var ticket = new FormsAuthenticationTicket( 1, entity.NickName,//DataCache.Account.GetNickName( entity.Id), DateTime.Now, saveCookie ? DateTime.Now.AddMonths(1) : DateTime.Now.AddDays(1), true, entity.Id + ""); string encTicket = FormsAuthentication.Encrypt(ticket); WriteCookieToClient(FormsAuthentication.FormsCookieName, encTicket); return(true); } catch (Exception ex) { Logger.Error(ex); return(false); } }
///// <summary> ///// 客户端推广渠道 ///// </summary> //public DB.Entity.Base.MarketingPO ClientMarketingInfo //{ // get // { // var marketingCode = Utility.Common.Cookie.GetValue(Utility.Config.MarketingCookieName); // if (!string.IsNullOrEmpty(marketingCode)) // { // return DataCache.Marketing.GetEntityByCode(marketingCode); // } // return null; // } //} /// <summary> /// 客户端推广渠道主键 /// </summary> //public int ClientMarketingId //{ // get { return ClientMarketingInfo != null ? ClientMarketingInfo.Id : 0; } //} ///// <summary> ///// ///// </summary> ///// <param name="AccountId"></param> ///// <returns></returns> //public bool LogForRegister(int AccountId) //{ // try // { // var now = DateTime.Now; // var pointLog = new DB.Entity.Base.AccountPointLogPO // { // CreateTime = now, // AccountId = AccountId, // Deleted = false, // Expense = 0, // ExpireDate = now.AddYears(1), // Income = 50, // Note = "注册", // OrdersId = 0, // PointType = 1, // UpdateTime = now // }; // new DB.BLL.Base.AccountPointLogBO().Insert(pointLog); // UpdateAccountPoint(AccountId, 50); // } // catch (Exception ex) // { // Logger.Error(ex); // } // return true; //} ///// <summary> ///// ///// </summary> ///// <param name="AccountId"></param> ///// <returns></returns> //public bool LogForLogin(int AccountId) //{ // try // { // var now = DateTime.Now; // var bllPointLog = new DB.BLL.Base.AccountPointLogBO(); // var exists = bllPointLog.Count( // string.Format("AccountId={0} AND PointType=2 AND DateDiff(DAY,CreateTime,'{1}')=0", AccountId, // now), null); // if (exists== 0) // { // var pointLog = new DB.Entity.Base.AccountPointLogPO // { // CreateTime = now, // AccountId = AccountId, // Deleted = false, // Expense = 0, // ExpireDate = now.AddYears(1), // Income = 10, // Note = "登录", // OrdersId = 0, // PointType = 2, // UpdateTime = now // }; // bllPointLog.Insert(pointLog); // UpdateAccountPoint(AccountId, 10); // } // } // catch (Exception ex) // { // Logger.Error(ex); // } // return true; //} /// <summary> /// 联合登录保存用户信息 /// </summary> /// <param name="openId"></param> /// <param name="friendlyName"></param> /// <param name="key"></param> /// <returns></returns> public DB.Entity.Base.AccountPO SaveAccount( string openId, string friendlyName, string key ) { var now = DateTime.Now; var trans = new Transaction(); try { trans.Begin(); if (openId != "") { var dbHelper = new DB.Agent.MssqlHelper <DB.Entity.Base.AccountPO>(); var entity = dbHelper.FindSingle(string.Format("PassportCode='{0}'", openId), trans.DbConnection, trans.DbTrans); if (entity == null) { entity = new DB.Entity.Base.AccountPO { NickName = friendlyName, PassportCode = openId, PassportKey = key, Balance = 0, CreateTime = now, UpdateTime = now, Credit = 0, Valid = false, LastSignin = now }; entity = dbHelper.Insert(entity, trans.DbConnection, trans.DbTrans); } else { var newEntity = new DB.Entity.Base.AccountPO(); newEntity.FillFrom(entity); newEntity.PassportKey = key; newEntity.LastSignin = now; newEntity.UpdateTime = now; dbHelper.Update(entity, newEntity, trans.DbConnection, trans.DbTrans); } return(entity); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); Logger.Error(ex); } finally { trans.Dispose(); } return(null); }
public static AccountPO SaveAccount( ChannelPO channel, AccountPO account, AccountAvatarsPO avatar, List <AccountContactsPO> contacts, List <AccountMessagesPO> messages, List <SchedulePO> schedules ) { var now = DateTime.Now; var trans = new Transaction(); try { trans.Begin(); #region DBOP var bllAccount = new DB.Agent.MssqlHelper <AccountPO>(); var bllAccountAvatars = new DB.Agent.MssqlHelper <AccountAvatarsPO>(); var bllAccountContacts = new DB.Agent.MssqlHelper <AccountContactsPO>(); var bllAccountMessages = new DB.Agent.MssqlHelper <AccountMessagesPO>(); var bllProject = new DB.Agent.MssqlHelper <ProjectPO>(); var bllSchedule = new DB.Agent.MssqlHelper <SchedulePO>(); #region avatar and account var condition = account == null ? string.Format("ChannelId={0} AND ChannelIdentity='{1}'", avatar.ChannelId, avatar.ChannelIdentity) : string.Format("ChannelId={0} AND ChannelIdentity='{1}' AND AccountId={2}", avatar.ChannelId, avatar.ChannelIdentity, account.Id); var avatarExists = bllAccountAvatars.FindSingle(condition, trans.DbConnection, trans.DbTrans); if (avatarExists == null) { if (account == null) { account = new DB.Entity.Base.AccountPO { NickName = avatar.DisplayName, Valid = true, UpdateTime = now, CreateTime = now, LastSignin = now, MobileVerifyTime = now, EmailVerifyTime = now }; Logger.Debug(account.SerializeXml()); account = bllAccount.Insert(account, trans.DbConnection, trans.DbTrans); } avatarExists = new AccountAvatarsPO { ChannelId = avatar.ChannelId, ChannelIdentity = avatar.ChannelIdentity, DisplayName = avatar.DisplayName, Code = avatar.Code, Token = avatar.Token, TokenGenerated = avatar.TokenGenerated, TokenExpires = avatar.TokenExpires, UpdateTime = avatar.UpdateTime, RefreshToken = avatar.RefreshToken, AccountId = account.Id, Valid = true, CreateTime = now, SynchroTime = now, SynchroDuration = 600 }; avatarExists.UpdateTime = now; Logger.Debug(avatarExists.SerializeXml()); avatar = bllAccountAvatars.Insert(avatarExists, trans.DbConnection, trans.DbTrans); } else { avatar.Id = avatarExists.Id; avatar.AccountId = avatarExists.AccountId; avatar.Valid = avatarExists.Valid; avatar.CreateTime = avatarExists.CreateTime; avatar.UpdateTime = now; avatar.SynchroTime = now; if (avatar.SynchroDuration == 0) { avatar.SynchroDuration = 600; } Logger.Info(avatar.SerializeXml()); bllAccountAvatars.Update(avatarExists, avatar, trans.DbConnection, trans.DbTrans); account = bllAccount.FindById(avatar.AccountId, trans.DbConnection, trans.DbTrans); } Utility.DataCache.AccountAvatars.InitCache(account.Id); #endregion Logger.Debug("REFRESH ACCOUNT CACHE"); var all = Refresh(account); #region contacts if (contacts != null && contacts.Any()) { Logger.Debug("SAVE CONTACTS"); foreach (var a in contacts) { var a0 = all.Contacts.FindLast( o => o.ChannelId == a.ChannelId && o.ChannelIdentity == a.ChannelIdentity && o.AccountId == account.Id); if (a0 == null) { a0 = new AccountContactsPO { AccountId = account.Id, ChannelId = a.ChannelId, ChannelIdentity = a.ChannelIdentity, DisplayName = a.DisplayName, Detail = a.Detail, CreateTime = now, Valid = true, UpdateTime = now }; a0 = bllAccountContacts.Insert(a0, trans.DbConnection, trans.DbTrans); } else { a0.DisplayName = a.DisplayName; a0.Detail = a.Detail; a0.UpdateTime = now; bllAccountContacts.Update(a, a0, trans.DbConnection, trans.DbTrans); } } Utility.DataCache.AccountContacts.InitCache(account.Id); } #endregion #region messages if (messages != null && messages.Any()) { Logger.Debug("SAVE MESSAGES"); foreach (var b in messages) { var b0 = all.Messages.FindLast( o => o.ChannelId == b.ChannelId && o.ChannelIdentity == b.ChannelIdentity && o.ToAccountId == account.Id); if (b0 == null) { b0 = new AccountMessagesPO { ToAccountId = account.Id, ChannelId = b.ChannelId, ChannelIdentity = b.ChannelIdentity, MessageType = b.MessageType, MessageSubject = b.MessageSubject, MessageContent = b.MessageContent, CreateTime = b.CreateTime, Valid = true, Weblink = b.Weblink, UpdateTime = now }; b0 = bllAccountMessages.Insert(b0, trans.DbConnection, trans.DbTrans); } else { b0.MessageType = b.MessageType; b0.MessageSubject = b.MessageSubject; b0.MessageContent = b.MessageContent; b0.Weblink = b.Weblink; b0.UpdateTime = now; b0.CreateTime = b.CreateTime; bllAccountMessages.Update(b, b0, trans.DbConnection, trans.DbTrans); } } Utility.DataCache.AccountMessages.InitCache(account.Id); } #endregion #region p&s if (schedules != null && schedules.Any()) { Logger.Debug("SAVE SCHEDULES"); var projectCode = avatar.Code + "." + account.Id + "." + channel.Id; var projectExists = Utility.DataCache.Project.CacheList().FindLast(o => o.ChannelId == channel.Id && o.CreatorAccountId == account.Id && o.ProjectCode == projectCode); var projectSchedules = new List <SchedulePO>(); if (projectExists == null) { projectExists = new ProjectPO { ProjectCode = projectCode, Valid = true, CreateTime = now, UpdateTime = now, ProjectName = avatar.DisplayName + "@" + channel.ChannelName, ChannelId = channel.Id, CreatorAccountId = account.Id, EnterDeadline = now }; Logger.Debug(projectExists.SerializeXml()); projectExists = bllProject.Insert(projectExists, trans.DbConnection, trans.DbTrans); } else { projectSchedules = Utility.DataCache.Schedule.CacheList(projectExists.Id); } Utility.DataCache.Project.InitCache(); foreach (var c in schedules) { var c0 = projectSchedules.FindLast( o => o.ProjectId == projectExists.Id && o.ScheduleIdentity == c.ScheduleIdentity); if (c0 == null) { c0 = new SchedulePO { ProjectId = projectExists.Id, ScheduleIdentity = c.ScheduleIdentity, Cycle = c.Cycle, ScheduleTitle = c.ScheduleTitle, ScheduleLead = c.ScheduleLead, BeginDate = c.BeginDate, BeginTime = c.BeginTime, EndDate = c.EndDate, EndTime = c.EndTime, Weblink = c.Weblink, CreateTime = now, Valid = true, UpdateTime = now }; c0 = bllSchedule.Insert(c0, trans.DbConnection, trans.DbTrans); } else { c0.Cycle = c.Cycle; c0.ScheduleTitle = c.ScheduleTitle; c0.ScheduleLead = c.ScheduleLead; c0.BeginDate = c.BeginDate; c0.BeginTime = c.BeginTime; c0.EndDate = c.EndDate; c0.EndTime = c.EndTime; c0.Weblink = c.Weblink; c0.UpdateTime = now; bllSchedule.Update(c, c0, trans.DbConnection, trans.DbTrans); } } Utility.DataCache.Schedule.InitCache(projectExists.Id); } #endregion #endregion trans.Commit(); Logger.Info("处理完结"); } catch (Exception ex) { trans.RollBack(); Logger.Error(ex); } finally { trans.Dispose(); } return(account); }