public void AfterLogin()
        {
            Console.WriteLine("start");
            var repositoryConfig = new RepositoryConfiguration
            {
                ConnectionString = AppSettingHelper.GetDbConnection()
            };

            Console.WriteLine("New Address");
            PersistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig);
            var userBus        = new UserBusiness.UserBusiness(PersistenceFactory);
            var walletBusiness = new WalletBusiness.WalletBusiness(PersistenceFactory);
            var userRepo       = PersistenceFactory.GetUserRepository(PersistenceFactory.GetOldConnection());

            var resultCreated = userBus.Login(
                new User {
                Email = "*****@*****.**", PhoneNumber = "+84988478266", FullName = "Ngo Ngoc Huan"
            });

            walletBusiness.MakeAllWalletForNewUser(userRepo.FindByEmailAddress("*****@*****.**"));
            Console.WriteLine(JsonHelper.SerializeObject(resultCreated));
            Assert.IsNotNull(resultCreated);

            resultCreated = userBus.Login(
                new User
            {
                Email = "*****@*****.**", PhoneNumber = "+84965995710", FullName = "Tieu Thanh Liem"
            });
            walletBusiness.MakeAllWalletForNewUser(userRepo.FindByEmailAddress("*****@*****.**"));
            Console.WriteLine(JsonHelper.SerializeObject(resultCreated));
            Assert.IsNotNull(resultCreated);
        }
        public override void OnActionExecuting(ActionExecutingContext actionExecutedContext)
        {
            try
            {
                var email = actionExecutedContext.HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.Email)
                            .Select(c => c.Value).SingleOrDefault();
                email = "*****@*****.**";
                if (!string.IsNullOrEmpty(email))
                {
                    var query = new Dictionary <string, string> {
                        { "Email", email }
                    };
                    var userBusiness = new UserBusiness.UserBusiness(_repositoryFactory);

                    var userModel = userBusiness.GetUserInfo(query);
                    connection.Close();
                    if (userModel != null)
                    {
                        actionExecutedContext.RouteData.Values.Add("UserModel", userModel);
                        return;
                    }
                }

                actionExecutedContext.Result = new JsonResult(CreateDataError(MessageApiError.USER_NOT_EXIT));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                actionExecutedContext.Result = new JsonResult(CreateDataError(MessageApiError.USER_NOT_EXIT));
            }
        }
Beispiel #3
0
 public SecurityController(
     IVakapayRepositoryFactory persistenceFactory,
     IConfiguration configuration,
     IHostingEnvironment hostingEnvironment
     ) : base(persistenceFactory, configuration, hostingEnvironment)
 {
     _userBusiness = new UserBusiness.UserBusiness(persistenceFactory);
 }
Beispiel #4
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);
        }
 public PortfolioController(
     IVakapayRepositoryFactory persistenceFactory,
     IConfiguration configuration,
     IHostingEnvironment hostingEnvironment
     ) : base(persistenceFactory, configuration, hostingEnvironment)
 {
     _userBusiness             = new UserBusiness.UserBusiness(persistenceFactory);
     _portfolioHistoryBusiness = new PortfolioHistoryBusiness.PortfolioHistoryBusiness(persistenceFactory);
 }
        public UserController()
        {
            var repositoryConfig = new RepositoryConfiguration
            {
                ConnectionString = AppSettingHelper.GetDbConnection()
            };

            VakapayRepositoryFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig);
            userBusiness             = new UserBusiness.UserBusiness(VakapayRepositoryFactory);
        }
 public WalletController(
     IVakapayRepositoryFactory persistenceFactory,
     IConfiguration configuration,
     IHostingEnvironment hostingEnvironment
     ) : base(persistenceFactory, configuration, hostingEnvironment)
 {
     _userBusiness     = new UserBusiness.UserBusiness(persistenceFactory);
     _walletBusiness   = new Vakapay.WalletBusiness.WalletBusiness(persistenceFactory);
     _sendMailBusiness = new Vakapay.SendMailBusiness.SendMailBusiness(persistenceFactory);
 }
Beispiel #8
0
        public LoginController(
            IVakapayRepositoryFactory persistenceFactory,
            IConfiguration configuration,
            IHostingEnvironment hostingEnvironment)
        {
            _repositoryFactory = persistenceFactory;
            _env          = hostingEnvironment;
            Configuration = configuration;

            _userBusiness   = new UserBusiness.UserBusiness(persistenceFactory);
            _walletBusiness = new WalletBusiness.WalletBusiness(persistenceFactory);
        }
Beispiel #9
0
        public WalletBusiness(IVakapayRepositoryFactory vakapayRepositoryFactory, bool isNewConnection = true)
        {
            _vakapayRepositoryFactory = vakapayRepositoryFactory;
            _connectionDb             = isNewConnection
                ? _vakapayRepositoryFactory.GetDbConnection()
                : _vakapayRepositoryFactory.GetOldConnection();

            ethereumBussiness        = new EthereumBusiness.EthereumBusiness(vakapayRepositoryFactory, false);
            bitcoinBussiness         = new BitcoinBusiness.BitcoinBusiness(vakapayRepositoryFactory, false);
            vakacoinBussiness        = new VakacoinBusiness.VakacoinBusiness(vakapayRepositoryFactory, false);
            sendMailBusiness         = new SendMailBusiness.SendMailBusiness(_vakapayRepositoryFactory, false);
            userBusiness             = new UserBusiness.UserBusiness(_vakapayRepositoryFactory, false);
            portfolioHistoryBusiness =
                new PortfolioHistoryBusiness.PortfolioHistoryBusiness(_vakapayRepositoryFactory, false);
            //(PortfolioHistoryBusiness.PortfolioHistoryBusiness)_vakapayRepositoryFactory.GetPortfolioHistoryRepository(_connectionDb);
        }
        public void UserInfo()
        {
            Console.WriteLine("start");
            var repositoryConfig = new RepositoryConfiguration
            {
                ConnectionString = AppSettingHelper.GetDbConnection()
            };

            Console.WriteLine("New Address");
            PersistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig);
            var userBus = new UserBusiness.UserBusiness(PersistenceFactory);

            var search =
                new Dictionary <string, string>
            {
                { "Email", "" }
            };
            var resultCreated = userBus.GetUserInfo(search);

            Console.WriteLine(JsonHelper.SerializeObject(resultCreated));
        }
        public void UserLog()
        {
            Console.WriteLine("start");
            var repositoryConfig = new RepositoryConfiguration
            {
                ConnectionString = AppSettingHelper.GetDbConnection()
            };

            Console.WriteLine("New Address");
            PersistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig);
            var userBus = new UserBusiness.UserBusiness(PersistenceFactory);

            var log = new UserActionLog
            {
                Description = "aaaa",
                Ip          = "192.168.1.157",
                ActionName  = "loggin",
                UserId      = "aaaaaaaaaa",
            };
            var resultCreated = userBus.AddActionLog(log.Description, log.UserId, log.ActionName, log.Ip);

            Console.WriteLine(JsonHelper.SerializeObject(resultCreated));
            Assert.IsNotNull(resultCreated);
        }