Beispiel #1
0
        /// <summary>
        /// 虛擬登入
        /// </summary>
        /// <returns></returns>
        public async Task <Guid> SimulationLogin(Guid token, string loginAccount, string sessionId)
        {
            var memberService   = new MemberService();
            var simulatorMember = await memberService.TokenToMember(token);

            if (simulatorMember != null)
            {
                var db = _uow.DbContext;

                var userTokenService = new TokenService();
                //判斷是否有資格模擬登入
                if (simulatorMember.IsOrgAdmin)
                {
                    var loginMember  = db.Members.FirstOrDefault(t => t.Account == loginAccount);
                    var checkedToken = userTokenService.InsertUserToken("iCAN API Viewer", sessionId, loginMember, null, simulatorMember.Id);

                    return(Guid.Parse(checkedToken.Token));
                }
                else
                {
                    return(Guid.Empty);
                }
            }
            else
            {
                return(Guid.Empty);
            }
        }
Beispiel #2
0
        /// <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);
            }
        }