예제 #1
0
        /// <summary>
        /// 添加SR基础数据
        /// </summary>
        /// <returns></returns>
        public async Task <MResponse> AsyncSRData()
        {
            MRankInfo srRankInfo = (await _steamBLL.GetRankScore(new[] { CurrentUser.RankID })).FirstOrDefault();

            if (srRankInfo == null)
            {
                bool hasSR = (await _steamBLL.GetOwnedGames(CurrentUser.PlatformID))?.OwnedGames?.Any(x => x.AppId == 207140) ?? false;
                if (!hasSR)
                {
                    return(MResponse.Fail("此账号尚未拥有SpeedRunners游戏"));
                }
                srRankInfo.RankType = 2;
            }
            else
            {
                srRankInfo.RankType     = 1;
                srRankInfo.OldRankScore = srRankInfo.RankScore;
            }
            BeginDb(DAL =>
            {
                DAL.UpdateRankInfo(srRankInfo, true);
                if (DAL.ExistRankLog(CurrentUser.PlatformID))
                {
                    return;
                }
                // 添加RankLog
                MRankLog rankLog = new MRankLog
                {
                    PlatformID = CurrentUser.PlatformID,
                    RankScore  = srRankInfo.RankScore.Value,
                };
                DAL.AddRankLog(rankLog);
            });
            return(MResponse.Success());
        }
예제 #2
0
        public override void OnResultExecuting(ResultExecutingContext context)
        {
            // 统一出参格式
            MResponse response = new MResponse();

            if (context.Result is EmptyResult)
            {
                response = MResponse.Success();
            }
            else if (context.Result is ObjectResult obj)
            {
                if (obj.DeclaredType == typeof(MResponse))
                {
                    response = (MResponse)obj.Value;
                }
                else
                {
                    // 出参类型不为MResponse时,将出参赋值给MResponse.Data再返回
                    response = obj.Value.Success();
                }
            }

            // 统一刷新返回Token
            AddRefreshToken(context.HttpContext, response);

            context.Result = new ObjectResult(response);
            base.OnResultExecuting(context);
        }
예제 #3
0
 public MResponse DeleteAccessToken(int tokenID)
 {
     return(BeginDb(DAL =>
     {
         MUser deleteUser = DAL.GetUserByTokenID(tokenID);
         if (deleteUser == null)
         {
             return MResponse.Fail("此设备已退出登录");
         }
         if (deleteUser.PlatformID != CurrentUser.PlatformID)
         {
             return MResponse.Fail("权限错误,操作失败");
         }
         if (deleteUser.LoginDate > CurrentUser.LoginDate)
         {
             return MResponse.Fail("目标设备权限较高,请重新登录后再试", -403);
         }
         DAL.DeleteAccessToken(deleteUser);
         return MResponse.Success();
     }));
 }
예제 #4
0
        public async Task <MResponse> Login(string query, string browser)
        {
            string openIDUrl = "https://steamcommunity.com/openid/login";

            query = Regex.Replace(query, "(?<=openid.mode=).+?(?=\\&)", "check_authentication", RegexOptions.IgnoreCase).Trim('?');
            string result = string.Empty;

            try
            {
                result = await HttpHelper.HttpPost(openIDUrl, query);
            }
            catch (Exception)
            {
                // 超时登录失败
                return(MResponse.Fail("登录超时", -555));
            }
            if (result.ToLower().Contains("is_valid:true"))
            {
                string steamID  = Regex.Match(HttpUtility.UrlDecode(query), "(?<=openid/id/)\\d+", RegexOptions.IgnoreCase).Value;
                string newToken = CommonUtils.CreateToken();
                // 保存登录凭证
                BeginDb(DAL =>
                {
                    DAL.AddAccessToken(new MUser
                    {
                        PlatformID = steamID,
                        Browser    = browser,
                        Token      = newToken
                    });
                });
                MResponse response = MResponse.Success();
                response.Token = newToken;
                return(response);
            }
            return(MResponse.Fail("登录失败"));
        }