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);
        }
Exemple #2
0
        public async Task <string> GetCurrentUser()
        {
            try
            {
                var email = User.Claims.Where(c => c.Type == ClaimTypes.Email).Select(c => c.Value)
                            .SingleOrDefault();

                if (string.IsNullOrEmpty(email))
                {
                    return(CreateDataError("Can't not email"));
                }

                var query = new Dictionary <string, string> {
                    { "Email", email }
                };


                var userModel = _userBusiness.GetUserInfo(query);

                var ip = HelpersApi.GetIp(Request);
                IpGeographicalLocation location = null;
                if (!string.IsNullOrEmpty(ip))
                {
                    //get location for ip
                    location = await IpGeographicalLocation.QueryGeographicalLocationAsync(ip);
                }

                if (userModel == null)
                {
                    var jsonUser = User.Claims.Where(c => c.Type == "userInfo").Select(c => c.Value)
                                   .SingleOrDefault();

                    var userClaims = Vakapay.Models.Entities.User.FromJson(jsonUser);
                    userClaims.Notifications = "1,2,3";
                    if (location != null)
                    {
                        if (location.Currency?.Code != null)
                        {
                            userClaims.CurrencyKey = location.Currency.Code;
                        }

                        if (location.TimeZone?.Id != null)
                        {
                            userClaims.TimezoneKey = location.TimeZone.Id;
                        }
                    }

                    var resultData = _userBusiness.Login(userClaims);

                    if (resultData.Status == Status.STATUS_ERROR)
                    {
                        return(CreateDataError(resultData.Message));
                    }


                    userModel = Vakapay.Models.Entities.User.FromJson(resultData.Data);


                    return(_walletBusiness.MakeAllWalletForNewUser(userModel).ToJson());
                }

                if (string.IsNullOrEmpty(ip))
                {
                    return new ReturnObject
                           {
                               Status = Status.STATUS_SUCCESS,
                               Data   = Vakapay.Models.Entities.User.ToJson(userModel)
                           }
                }
                .ToJson();

                UpdateCurrencyAndTimeZone(userModel, location);

                var browser = HelpersApi.GetBrowser(Request);

                var confirmedDevices = new ConfirmedDevices
                {
                    Browser  = browser,
                    Ip       = ip,
                    Location = location != null && !string.IsNullOrEmpty(location.CountryName)
                        ? location.City + "," + location.CountryName
                        : "localhost",
                    UserId = userModel.Id
                };

                var search = new Dictionary <string, string> {
                    { "Ip", ip }, { "Browser", browser }
                };


                //save devices
                var checkConfirmedDevices = _userBusiness.GetConfirmedDevices(search);
                if (checkConfirmedDevices == null)
                {
                    _userBusiness.SaveConfirmedDevices(confirmedDevices);
                }


                userModel.SecretAuthToken = null;
                userModel.TwoFactorSecret = null;
                userModel.SecondPassword  = null;
                userModel.Id          = null;
                userModel.PhoneNumber = !string.IsNullOrEmpty(userModel.PhoneNumber)
                    ? "*********" + userModel.PhoneNumber.Remove(0, 9)
                    : null;
                if (userModel.Birthday.Contains("1900-01-01"))
                {
                    userModel.Birthday = null;
                }

                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = userModel.ToJson()
                }.ToJson());
            }