public bool LogOut(string token) { var tokenService = new TokenService(); var tokenInfo = tokenService.GetTokenInfo(token).Result; var deleteToken = tokenService.DeleteUserToken(tokenInfo.MemberId, tokenInfo.RequestSystem); return(deleteToken); }
/// <summary> /// 新增登入紀錄 /// </summary> /// <param name="data"></param> /// <param name="loginMemberInfo"></param> /// <param name="simulators"></param> /// <returns></returns> public Infrastructure.Entity.UserToken InsertLoginLog(LoginRequest data, Member loginMemberInfo, IEnumerable <Member> simulators) { var tokenService = new TokenService(); var db = _uow.DbContext; if (loginMemberInfo == null) { return(null); } //var checkOrgLogin = (from ut in db.UserToken // join o in db.Organizations on ut.OrgId equals o.Id // orderby ut.Id descending // where ut.MemberId == loginMemberInfo.Id && // o.OrgCode != "amateur" && // ut.DeviceKey.ToLower()==data.RequestSystem.ToLower() // select ut).FirstOrDefault(); //if (checkOrgLogin != null) // return checkOrgLogin; //判斷是否為組織登入過 var checkOrgLogin = db.UserToken.FirstOrDefault(t => t.MemberId == loginMemberInfo.Id && t.OrgId == loginMemberInfo.OrgId && t.RequestSystem.ToLower() == data.RequestSystem.ToLower()); if (checkOrgLogin != null) { return(checkOrgLogin); } try { if (simulators.Count() > 1) { //tokenService.DeleteUserToken(loginMemberInfo.Id, data.RequestSystem, true); var response = tokenService.InsertUserToken(data.RequestSystem, data.PhoneID, loginMemberInfo, data.PushToken, simulators.FirstOrDefault().Id); return(response); } else { tokenService.DeleteUserToken(loginMemberInfo.Id, data.RequestSystem); var response = tokenService.InsertUserToken(data.RequestSystem, data.PhoneID, loginMemberInfo, data.PushToken); return(response); } } catch (Exception ex) { return(null); } }
/// <summary> /// 登出資料處理 /// </summary> /// <param name="data"></param> /// <returns></returns> public bool LogoutProxy(UserTokenRequest data) { var tokenService = new TokenService(); //判斷是否有遺漏資訊 if (!PassLogoutDataCheck(data)) { return(false); } var accounts = GetSimulatorAccount(data.Account); //取得登入者資訊 var memberInfo = accounts.Count() > 1 ? accounts.ToArray()[1] : accounts.FirstOrDefault(); //是否本來為有效的登入 var checkSuccess = CheckLoginSuccess(memberInfo.Id, null, data.Code.ToLower()); if (checkSuccess == null) { return(false); } //將過去的token設為失效 tokenService.DeleteUserToken(memberInfo.Id, data.Code); return(true); }