Exemple #1
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 #2
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 #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));
        }
        private async Task <int> CreateUserBasicDataAsync(string aspNetUserId, string username)
        {
            UserBasicData user = new UserBasicData()
            {
                Aspnetuserid = aspNetUserId,
                UserName     = username
            };
            await _context.UserBasicData.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user.UserId);
        }
            public async Task <short> Handle(CreateUserBasicDataCommand request, CancellationToken cancellationToken)
            {
                UserBasicData user = new UserBasicData()
                {
                    UserName  = request.UserName,
                    FirstName = request.FirstName
                };

                _context.UserBasicData.Add(user);
                await _context.SaveChangesAsync(cancellationToken);

                return(user.UserId);
            }
Exemple #8
0
        public async Task <IActionResult> Join([FromBody] UserModels.Join.Request request)
        {
            // check format
            if (request.EMail.IsValidEmailAddress() == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            // check account
            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(request.EMail))
            {
                return(APIResponse(ErrorCode.ExistEMail));
            }

            // check verify code
            ErrorCode emailVerifyResult = CheckEMailVerifyCode(request.EMail, request.VerifyCode, false);

            if (emailVerifyResult != ErrorCode.Success)
            {
                return(APIResponse(emailVerifyResult));
            }

            // insert database
            DBQuery_User_Insert query = new DBQuery_User_Insert();

            basicData            = query.IN.BasicData;
            basicData.UserId     = IDGenerator.NewUserId;
            basicData.EMail      = request.EMail;
            basicData.CreateTime = DateTime.UtcNow;
            basicData.Password   = PasswordUtility.HashPassword(request.Password);

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

            // response
            var response = new UserModels.Join.Response();

            response.EMail      = request.EMail;
            response.CreateTime = basicData.CreateTime;

            return(Success(response));
        }
Exemple #9
0
 public bool FromDataTable(DataTable table)
 {
     try
     {
         foreach (DataRow row in table.Rows)
         {
             var item = new UserBasicData();
             item.FromDBTable(row);
             Items.Add(item);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #10
0
        // 로그인 처리
        private async Task <ErrorCode> ProcessLoginAsync(string email, string password, int timeZoneOffsetFromUTC = 0)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(ErrorCode.AlreadyLoggedin);
            }

            if (email.IsValidEmailAddress() == false)
            {
                return(ErrorCode.InvalidEMail);
            }

            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(email) == false)
            {
                return(ErrorCode.InvalidEMail);
            }

            if (PasswordUtility.VerifyPassword(password, basicData.Password) == false)
            {
                return(ErrorCode.InvalidPassword);
            }

            var claims = new List <Claim>();

            claims.Add(new Claim(HenaClaimTypes.UserId, basicData.UserId.ToString()));
            claims.Add(new Claim(HenaClaimTypes.GivenName, basicData.GivenName));
            claims.Add(new Claim(HenaClaimTypes.Surname, basicData.SurName));
            claims.Add(new Claim(HenaClaimTypes.Email, basicData.EMail));
            claims.Add(new Claim(HenaClaimTypes.Language, basicData.Language));
            claims.Add(new Claim(HenaClaimTypes.TimeZoneId, basicData.TimeZoneId));
            claims.Add(new Claim(HenaClaimTypes.TimeZoneOffset, TimeSpan.FromMinutes(timeZoneOffsetFromUTC).ToString()));

            var userIdentity = new ClaimsIdentity(claims, "login");

            ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
            await HttpContext.SignInAsync(principal);

            Response.Cookies.Delete(HenaClaimTypes.UserId);
            Response.Cookies.Append(HenaClaimTypes.UserId, basicData.UserId.ToString());


            return(ErrorCode.Success);
        }
Exemple #11
0
        public async Task <IActionResult> JoinVerifyEMail([FromBody] UserModels.JoinVerifyEMail.Request request)
        {
            // check format
            if (request.EMail.IsValidEmailAddress() == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            // check account
            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(request.EMail))
            {
                return(APIResponse(ErrorCode.ExistEMail));
            }

            var response = new UserModels.JoinVerifyEMail.Response();

            return(Success(response));
        }
Exemple #12
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 #13
0
        public async Task <IActionResult> ResetPassword([FromBody] UserModels.ResetPassword.Request request)
        {
            // check account
            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(request.EMail) == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            string newPassword = IDGenerator.NewVerifyCode;

            basicData.Password = PasswordUtility.HashPassword(newPassword);

            var query = new DBQuery_User_Update_Password();

            query.IN.UserId   = basicData.UserId;
            query.IN.Password = basicData.Password;

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


            // 이메일 발송
            StringBuilder msg = new StringBuilder(1024);

            msg.AppendLine(string.Format($"Hello. {basicData.EMail.Split('@')[0]}"));
            msg.AppendLine(string.Format($"Reseted your password."));
            msg.AppendLine();
            msg.AppendLine(string.Format($"Your temp password : {newPassword}"));

            await WebServiceUtility.SendEMailAsync("[Hena Platform] Reseted your password.", msg.ToString(), false, request.EMail);

            var response = new UserModels.ResetPassword.Response();

            return(Success(response));
        }
Exemple #14
0
        public ActionResult EditBasicData(UserBasicData form)
        {
            User editUser = db.Users.Where(u => u.Login == HttpContext.User.Identity.Name).FirstOrDefault();

            if (editUser != null)
            {
                string changedFirstName   = form.FirstName.Trim();
                string changedLastName    = form.LastName.Trim();
                string changedEmail       = form.Email.Trim();
                string changedPhoneNumber = form.Phone.Trim();


                if (changedFirstName != editUser.FirstName && changedFirstName != null)
                {
                    editUser.FirstName = changedFirstName;
                }

                if (changedLastName != editUser.LastName && changedLastName != null)
                {
                    editUser.LastName = changedLastName;
                }

                if (changedEmail != editUser.Email && changedEmail != null)
                {
                    editUser.Email = changedEmail;
                }

                if (changedPhoneNumber != editUser.Phone && changedPhoneNumber != null)
                {
                    editUser.Phone = changedPhoneNumber;
                }

                db.Entry(editUser).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            return(Json("Pomyślnie zmienione podstawowe dane użytkownika!"));
        }
Exemple #15
0
        public async Task <IActionResult> SendVerifyEMail([FromBody] UserModels.SendVerifyEMail.Request request)
        {
            // check account
            UserBasicData basicData = new UserBasicData();

            if (request.EMail.IsValidEmailAddress() == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            if (await basicData.FromDBByEmailAsync(request.EMail))
            {
                return(APIResponse(ErrorCode.ExistEMail));
            }

            // generate verify data
            var verifyData = VerifyDataManager.Instance.NewVerifyData(TimeSpan.FromMinutes(3)
                                                                      , TimeSpan.FromHours(1), true, request);

            // 이메일 발송
            StringBuilder msg = new StringBuilder(1024);

            msg.AppendLine(string.Format($"Hello. "));
            msg.AppendLine(string.Format($"Please enter your verification code below and complete verification."));
            msg.AppendLine();
            msg.AppendLine(string.Format($"CODE : {verifyData.VerifyCode}"));

            await WebServiceUtility.SendEMailAsync("[Hena Platform] Signup verification code.", msg.ToString(), false, request.EMail);

            // response
            var response = new UserModels.SendVerifyEMail.Response();

            response.EMail    = request.EMail;
            response.SendTime = DateTime.UtcNow;

            return(Success(response));
        }
Exemple #16
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));
        }