Exemple #1
0
        public async Task <IActionResult> ChangePassword(string password, string newPassword, string confirmPassword)
        {
            if (string.IsNullOrEmpty(password) ||
                string.IsNullOrEmpty(newPassword) ||
                newPassword.Length < 8 ||
                newPassword != confirmPassword)
            {
                ModelState.AddModelError("Message", "Invalid Password");
                return(View());
            }

            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBAsync(UserId) == false)
            {
                ModelState.AddModelError("Message", "Invalid Session");
                return(View());
            }

            if (PasswordUtility.VerifyPassword(password, basicData.Password) == false)
            {
                ModelState.AddModelError("Message", "Invalid Password");
                return(View());
            }

            var query = new DBQuery_User_Update_Password();

            query.IN.UserId   = UserId;
            query.IN.Password = PasswordUtility.HashPassword(newPassword);

            await DBThread.Instance.ReqQueryAsync(query);

            return(RedirectToAction("Index", "Dashboard"));
        }
Exemple #2
0
        public async Task <bool> StartMining(DBKey userId)
        {
            if (userId == GlobalDefine.INVALID_DBKEY)
            {
                return(false);
            }

            UserBasicData userBasicData = new UserBasicData();

            if (await userBasicData.FromDBAsync(userId) == false)
            {
                return(false);
            }

            lock (Items)
            {
                if (Items.ContainsKey(userId))
                {
                    return(false);
                }

                var miningData = new MiningData()
                {
                    UserId         = userId,
                    NextMiningTime = DateTime.UtcNow.AddSeconds(RandomEx.Range(MiningTimeRange.min.TotalSeconds, MiningTimeRange.max.TotalSeconds)),
                    LastMiningTime = DateTime.UtcNow,
                };
                miningData.RefreshSessionExpireTime();

                Items.Add(userId, miningData);
            }
            return(true);
        }
Exemple #3
0
        public async Task <IActionResult> MiningHistory([FromBody] MiningModels.MiningHistory.Request request)
        {
            if (request.UserId == GlobalDefine.INVALID_DBKEY)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            UserBasicData userBasicData = new UserBasicData();

            if (await userBasicData.FromDBAsync(request.UserId) == false)
            {
                return(APIResponse(ErrorCode.InvalidId));
            }

            if (request.Count <= 0)
            {
                request.Count = 20;
            }

            MiningHistoryDataContainer histories = new MiningHistoryDataContainer();
            await histories.FromDBByCustomerIdAsync(request.UserId, request.Offset, request.Count);

            var response = new MiningModels.MiningHistory.Response();

            response.Items.AddRangeSafe(histories.Items);
            return(Success(response));
        }
Exemple #4
0
        public async Task <IActionResult> Balances([FromBody] UserServiceModels.Balances.Request request)
        {
            if (request.UserId == GlobalDefine.INVALID_DBKEY)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            UserBasicData userBasicData = new UserBasicData();

            if (await userBasicData.FromDBAsync(request.UserId) == false)
            {
                return(APIResponse(ErrorCode.InvalidId));
            }

            BalanceDataContainer balances = new BalanceDataContainer();
            await balances.FromDBByUserIdAsync(request.UserId);

            var currencies = Enum.GetValues(typeof(CurrencyTypes));

            foreach (CurrencyTypes it in currencies)
            {
                if (it == CurrencyTypes.None)
                {
                    continue;
                }

                balances.FindOrAdd(request.UserId, it);
            }

            var response = new UserServiceModels.Balances.Response();

            response.Balances.AddRangeSafe(balances.Items);
            return(Success(response));
        }
Exemple #5
0
        public async Task <IActionResult> AICRevenueReport([FromBody] UserServiceModels.AICRevenueReport.Request request)
        {
            if (request.UserId == GlobalDefine.INVALID_DBKEY)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            UserBasicData userBasicData = new UserBasicData();

            if (await userBasicData.FromDBAsync(request.UserId) == false)
            {
                return(APIResponse(ErrorCode.InvalidId));
            }

            RevenueReportDataContainer revenueReports = new RevenueReportDataContainer();

            if (request.IsPublisherReport)
            {
                await revenueReports.FromDBByPublisherIdAsync(request.UserId, request.BeginTime, request.EndTime, request.TimeZoneOffset);
            }
            else
            {
                await revenueReports.FromDBByCustomerIdAsync(request.UserId, request.BeginTime, request.EndTime, request.TimeZoneOffset);
            }

            var response = new UserServiceModels.AICRevenueReport.Response();

            response.Items.AddRangeSafe(revenueReports.Items);
            return(Success(response));
        }
Exemple #6
0
        public async Task <IActionResult> MiningReport([FromBody] MiningModels.MiningReport.Request request)
        {
            if (request.UserId == GlobalDefine.INVALID_DBKEY)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            UserBasicData userBasicData = new UserBasicData();

            if (await userBasicData.FromDBAsync(request.UserId) == false)
            {
                return(APIResponse(ErrorCode.InvalidId));
            }

            MiningReportDataContainer reports = new MiningReportDataContainer();
            await reports.FromDBByUserIdAsync(request.UserId, request.BeginTime, request.EndTime, request.TimeZoneOffset);

            var response = new MiningModels.MiningReport.Response();

            response.Items.AddRangeSafe(reports.Items);
            return(Success(response));
        }
Exemple #7
0
        public async Task <IActionResult> AdReady([FromBody] PageAdModels.AdReady.Request request)
        {
            if (request == null || request.IsValidParameters() == false)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            // Check Data
            AdInfo ai = new AdInfo();

            if (await ai.AdUnitData.FromDBAsync(request.AdUnitId) == false ||
                await ai.AppData.FromDBAsync(ai.AdUnitData.AppId) == false)
            {
                return(APIResponse(ErrorCode.BadRequest));
            }

            if (ai.AdUnitData.AdSystemType != request.AdSystemType)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }


            var supportedDesignTypes = AdDesignTypes.ToSupported(request.ClientType, request.AdSystemType, request.IsLandscape);

            bool isFound = false;

            for (int i = 0; i < 3; ++i)
            {
                var adDesignType = supportedDesignTypes[RandomEx.Range(0, supportedDesignTypes.Length)];
                if (await ai.AdDesignData.ChoiceFromDBAsync(adDesignType) &&
                    await ai.CampaignData.FromDBAsync(ai.AdDesignData.CampaignId) &&
                    await ai.AdResourceData.FromDBAsync(ai.AdDesignData.AdResourceId)
                    )
                {
                    isFound = true;
                    break;
                }
            }

            if (isFound == false)
            {
                return(APIResponse(ErrorCode.NotFound));
            }

            // Insert to db
            var insertQuery = new DBQuery_AdHistory_Insert();
            var ahd         = ai.AdHistoryData = insertQuery.IN.Item;

            ahd.AdHistoryId = IDGenerator.NewAdHistoryId;

            UserBasicData customerData = new UserBasicData();

            if (request.CustomerId != GlobalDefine.INVALID_DBKEY &&
                await customerData.FromDBAsync(request.CustomerId))
            {
                ahd.CustomerId = request.CustomerId;
            }
            else
            {
                ahd.CustomerId = GlobalDefine.INVALID_DBKEY;
            }

            ahd.PublisherId = ai.AdUnitData.UserId;
            ahd.AppId       = ai.AdUnitData.AppId;
            ahd.AdUnitId    = ai.AdUnitData.AdUnitId;

            ahd.AdvertiserId = ai.CampaignData.UserId;
            ahd.AdDesignId   = ai.AdDesignData.AdDesignId;
            ahd.CampaignId   = ai.CampaignData.CampaignId;

            ahd.UserAgent = UserAgent;
            ahd.IPAddress = RemoteIPAddress;

            ahd.AdDesignType = ai.AdDesignData.AdDesignType;
            ahd.CampaignType = ai.CampaignData.CampaignType;
            ahd.Cost         = ai.CampaignData.Cost;

            if (await DBThread.Instance.ReqQueryAsync(insertQuery) == false)
            {
                return(APIResponse(ErrorCode.DatabaseError));
            }

            // Response
            var response = new PageAdModels.AdReady.Response();

            response.AdUnitId     = request.AdUnitId;
            response.AdSystemType = ai.AdUnitData.AdSystemType;
            response.AdDesignType = ai.AdDesignData.AdDesignType;

            response.ContentType = ai.AdResourceData.ContentType;
            var resourceUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("AdResource", "PageAd")}";

            response.ResourceUrl = resourceUrl;

            response.Width  = ai.AdResourceData.Width;
            response.Height = ai.AdResourceData.Height;

            response.AdUrl = ai.AdDesignData.DestinationUrl;

            response.AdClickUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("AdClick", "PageAd")}";

            response.Ai = ai.Encode().EncodeBase64ToUrlSafeBase64();
            return(Success(response));
        }