Beispiel #1
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());
            }
        public string GetConfirmedDevices()
        {
            try
            {
                var queryStringValue = Request.Query;

                if (!queryStringValue.ContainsKey("offset") || !queryStringValue.ContainsKey("limit"))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                StringValues sort;
                StringValues filter;
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_OFFSET, out var offset);
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_LIMIT, out var limit);
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER, out filter);
                }
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT, out sort);
                }

                sort = ConvertSortDevice(sort);

                var ip = HelpersApi.GetIp(Request);

                var checkConfirmedDevices = new ConfirmedDevices();

                if (!string.IsNullOrEmpty(ip))
                {
                    var browser = HelpersApi.GetBrowser(Request);

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

                    //save web session
                    checkConfirmedDevices = _userBusiness.GetConfirmedDevices(search);
                }

                var userModel = (User)RouteData.Values["UserModel"];

                int numberData;
                var resultDevice = _userBusiness.GetListConfirmedDevices(out numberData, userModel.Id,
                                                                         checkConfirmedDevices,
                                                                         Convert.ToInt32(offset),
                                                                         Convert.ToInt32(limit), sort, filter);

                if (resultDevice.Status != Status.STATUS_SUCCESS)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.DATA_NOT_FOUND));
                }

                var listDevice = JsonHelper.DeserializeObject <List <ConfirmedDevices> >(resultDevice.Data);
                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = new ResultList <ConfirmedDevices>
                    {
                        List = listDevice,
                        Total = numberData
                    }.ToJson()
                }.ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.DEVICE_LIST + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }