/// <summary> /// 登出 /// </summary> /// <param name="phone"></param> /// <returns></returns> public Result <Account> SignOut(long phone) { Result <Account> result = new Result <Account>() { Status = false, Message = "登出失败,登出人员与当前账户不匹配", StatusCode = "SO001" }; IOnlineAccountCache service = ServiceObjectContainer.Get <IOnlineAccountCache>(); string key = string.Format("OnlineAI_{0}", phone); if (service.SearchInfoByKey(key) != null) { if (service.RemoveInfo(key)) { result.Status = true; result.Message = "登出成功"; result.StatusCode = "SO000"; //Todo :记录数据库 登出日志 } } return(result); }
/// <summary> /// 登陆 /// </summary> /// <param name="signInCode"></param> /// <param name="securityCode"></param> /// <returns></returns> public Result <Account> SignIn(string signInCode, string securityCode) { Result <Account> result = new Result <Account>() { Status = false }; try { //1.检查是否已经登录 IOnlineAccountCache service = ServiceObjectContainer.Get <IOnlineAccountCache>(); IAccountInfoCache accountservice = ServiceObjectContainer.Get <IAccountInfoCache>(); string phonekey = string.Format("OnlineAI_{0}_*", signInCode); string emailkey = string.Format("OnlineAI_*_{0}", signInCode); string securityCodeMD5 = MD5Engine.ToMD5String(securityCode); OnlineAccountInfo onlineinfo = null; onlineinfo = service.SearchInfoByKey(phonekey); if (onlineinfo == null) { onlineinfo = service.SearchInfoByKey(emailkey); } if (onlineinfo == null) { //2.直接从数据库拿数据 IList <AccountInfo> inforesult = DBConnectionManager.Instance.Reader.Select <AccountInfo>(new AccountSelectSpefication(3, signInCode, securityCodeMD5).Satifasy()); if (inforesult != null && inforesult.Count > 0) { result.Status = true; result.Data = inforesult[0].Copy <Account>(); //保存到缓存 service.SaveInfo(inforesult[0].Copy <OnlineAccountInfo>()); accountservice.SaveInfo(inforesult[0]); } else { result.Message = "用户名或密码错误"; result.StatusCode = "LG000"; } } else { //校验密码 if (onlineinfo.SecurityCode != securityCodeMD5) { result.Message = "密码错误"; result.StatusCode = "LG000"; result.Data = null; } else { //返回结果 result.Status = true; result.Data = onlineinfo.Copy <Account>(); } } } catch (Exception ex) { result.Status = false; result.Data = null; result.Message = ex.Message; result.StatusCode = "EX000"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:SignIn() .AccountService"), LogType.ErrorLog); } return(result); }