示例#1
0
        /// <summary>
        /// Get message check token invalid
        /// </summary>
        /// <param name="headers"></param>
        /// <param name="path"></param>
        /// <param name="repositoryFactory"></param>
        /// <returns></returns>
        private static FilterModel GetMessageTokenInvalid(IHeaderDictionary headers, string path,
                                                          IVakapayRepositoryFactory repositoryFactory)
        {
            Console.WriteLine("GenerateTokenKey: " + CommonHelper.GenerateTokenKey("wk961j2jewxaz0zy",
                                                                                   "cjon3tnigdvuosipgxm1hlu3fd6umtbm", "1540372506277", path));
            var filterModel = new FilterModel
            {
                Message = MessageError.TOKEN_INVALID,
                Status  = false
            };
            string clientToken = headers[Requests.HEADER_TOKEN_KEY];
            var    key         = Encoding.UTF8.GetString(Convert.FromBase64String(clientToken));
            var    parts       = key.Split(new[] { ':' });

            if (parts.Length != 3)
            {
                return(filterModel);
            }
            var apiKey       = parts[1];
            var timeStamp    = parts[2];
            var userBusiness = new UserBusiness.UserBusiness(repositoryFactory);
            var apiKeyModel  = userBusiness.GetApiKeyByKey(apiKey);

            if (apiKeyModel == null || string.IsNullOrEmpty(apiKeyModel.UserId))
            {
                return(filterModel);
            }
            var userModel = userBusiness.GetUserById(apiKeyModel.UserId);

            if (userModel == null)
            {
                filterModel.Message = MessageError.USER_NOT_EXIT;
                return(filterModel);
            }

            var serverToken = CommonHelper.GenerateTokenKey(apiKeyModel.KeyApi, apiKeyModel.Secret, timeStamp, path);

            Console.WriteLine(serverToken);

            if (!IsTokenExpired(timeStamp))
            {
                if (!string.Equals(clientToken, serverToken))
                {
                    return(filterModel);
                }
                filterModel.Message     = null;
                filterModel.Status      = true;
                filterModel.ApiKeyModel = apiKeyModel;
                filterModel.UserModel   = userModel;
            }
            else
            {
                filterModel.Message = MessageError.TOKEN_EXPIDER;
            }

            return(filterModel);
        }
示例#2
0
        public ReturnObject UpdateBalanceDeposit(string toAddress, decimal addedBalance, string networkName)
        {
            try
            {
                //  userID = "";
                if (_connectionDb.State != ConnectionState.Open)
                {
                    _connectionDb.Open();
                }

                var wallet = FindByAddressAndNetworkName(toAddress, networkName);

                if (wallet == null)
                {
                    return(new ReturnObject
                    {
                        Status = Status.STATUS_ERROR,
                        Message = "Update fail, Address not exists"
                    });
                }

                if (!wallet.Currency.Equals(networkName))
                {
                    return(new ReturnObject
                    {
                        Status = Status.STATUS_ERROR,
                        Message = "Not same network"
                    });
                }

                //                wallet.Balance += addedBalance;
                //                wallet.Version += 1;
                //                var result = walletRepository.Update(wallet);
                var result = UpdateBalance(addedBalance, wallet.Id, wallet.Version);
                if (result.Status == Status.STATUS_ERROR)
                {
                    return(result);
                }
                else
                {
                    User user = userBusiness.GetUserById(wallet.UserId);
                    //  userID = user.Id;
                    if (user != null)
                    {
                        portfolioHistoryBusiness.InsertWithPrice(user.Id);
                        //send mail:
                        EmailQueue email = new EmailQueue()
                        {
                            ToEmail     = user.Email,
                            NetworkName = wallet.Currency,
                            Amount      = addedBalance,
                            Template    = EmailTemplate.Received,
                            Subject     = EmailConfig.SUBJECT_SENT_OR_RECEIVED,
                            //							Content = networkName + "+" + addedBlance
                        };
                        result = sendMailBusiness.CreateEmailQueueAsync(email).Result;
                    }
                }

                return(result);
            }
            catch (Exception e)
            {
                //     userID = "";
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }