Merge branch 'feature/track-user-location-mongodb' into dev
# Conflicts: # src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs
This commit is contained in:
commit
a56a795981
@ -16,7 +16,7 @@ namespace eShopOnContainers.Core.Services.Identity
|
||||
dic.Add("client_id", "xamarin");
|
||||
dic.Add("client_secret", "secret");
|
||||
dic.Add("response_type", "code id_token token");
|
||||
dic.Add("scope", "openid profile basket orders offline_access");
|
||||
dic.Add("scope", "openid profile basket orders locations offline_access");
|
||||
|
||||
dic.Add("redirect_uri", GlobalSetting.Instance.IdentityCallback);
|
||||
dic.Add("nonce", Guid.NewGuid().ToString("N"));
|
||||
|
@ -5,6 +5,6 @@
|
||||
|
||||
public interface ILocationService
|
||||
{
|
||||
Task UpdateUserLocation(LocationRequest newLocReq);
|
||||
Task UpdateUserLocation(LocationRequest newLocReq, string token);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
_requestProvider = requestProvider;
|
||||
}
|
||||
|
||||
public async Task UpdateUserLocation(LocationRequest newLocReq)
|
||||
public async Task UpdateUserLocation(LocationRequest newLocReq, string token)
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.LocationEndpoint);
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
string uri = builder.ToString();
|
||||
|
||||
var result = await _requestProvider.PostAsync(uri, newLocReq);
|
||||
await _requestProvider.PostAsync(uri, newLocReq, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,8 +215,10 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
if(Settings.UseMocks)
|
||||
{
|
||||
Settings.AuthAccessToken = string.Empty;
|
||||
Settings.AuthIdToken = string.Empty;
|
||||
Settings.AuthIdToken = string.Empty;
|
||||
}
|
||||
|
||||
Settings.UseFakeLocation = false;
|
||||
}
|
||||
|
||||
private async Task NavigateAsync(string url)
|
||||
|
@ -140,6 +140,8 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool UserIsLogged => !string.IsNullOrEmpty(Settings.AuthAccessToken);
|
||||
|
||||
public ICommand ToggleMockServicesCommand => new Command(async () => await ToggleMockServicesAsync());
|
||||
|
||||
public ICommand ToggleFakeLocationCommand => new Command(() => ToggleFakeLocationAsync());
|
||||
@ -194,8 +196,9 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
Latitude = _latitude,
|
||||
Longitude = _longitude
|
||||
};
|
||||
var authToken = Settings.AuthAccessToken;
|
||||
|
||||
await _locationService.UpdateUserLocation(locationRequest);
|
||||
await _locationService.UpdateUserLocation(locationRequest, authToken);
|
||||
}
|
||||
|
||||
private void UpdateInfo()
|
||||
|
@ -163,7 +163,8 @@
|
||||
Grid.ColumnSpan="2"/>
|
||||
<StackLayout
|
||||
Grid.Column="0"
|
||||
Grid.Row="4">
|
||||
Grid.Row="4"
|
||||
IsVisible="{Binding UserIsLogged}">
|
||||
<Label
|
||||
Text="{Binding TitleUseFakeLocation}"
|
||||
TextColor="{StaticResource GreenColor}"
|
||||
@ -179,7 +180,8 @@
|
||||
Animate="True"
|
||||
Checked="{Binding UseFakeLocation, Mode=TwoWay}"
|
||||
Command="{Binding ToggleFakeLocationCommand}"
|
||||
Style="{StaticResource SettingsToggleButtonStyle}">
|
||||
Style="{StaticResource SettingsToggleButtonStyle}"
|
||||
IsVisible="{Binding UserIsLogged}">
|
||||
<controls:ToggleButton.CheckedImage>
|
||||
<OnPlatform x:TypeArguments="ImageSource"
|
||||
Android="switch_on.png"
|
||||
@ -193,7 +195,7 @@
|
||||
WinPhone="Assets/switchOff.png"/>
|
||||
</controls:ToggleButton.UnCheckedImage>
|
||||
</controls:ToggleButton>
|
||||
<!-- ENDPOINT -->
|
||||
<!-- FAKE LOCATIONS -->
|
||||
<StackLayout
|
||||
Grid.Row="5"
|
||||
Grid.Column="0"
|
||||
@ -205,7 +207,7 @@
|
||||
Style="{StaticResource HeaderLabelStyle}"/>
|
||||
<Entry
|
||||
Text="{Binding Latitude, Mode=TwoWay}"
|
||||
Keyboard="Numeric">
|
||||
Keyboard="Text">
|
||||
<Entry.Style>
|
||||
<OnPlatform
|
||||
x:TypeArguments="Style"
|
||||
@ -219,7 +221,7 @@
|
||||
Style="{StaticResource HeaderLabelStyle}"/>
|
||||
<Entry
|
||||
Text="{Binding Longitude, Mode=TwoWay}"
|
||||
Keyboard="Numeric">
|
||||
Keyboard="Text">
|
||||
<Entry.Style>
|
||||
<OnPlatform
|
||||
x:TypeArguments="Style"
|
||||
|
@ -77,7 +77,8 @@ namespace Identity.API.Configuration
|
||||
"locations"
|
||||
},
|
||||
//Allow requesting refresh tokens for long lived API access
|
||||
AllowOfflineAccess = true
|
||||
AllowOfflineAccess = true,
|
||||
AllowAccessTokensViaBrowser = true
|
||||
},
|
||||
new Client
|
||||
{
|
||||
|
@ -21,11 +21,11 @@ namespace Locations.API.Controllers
|
||||
}
|
||||
|
||||
//GET api/v1/[controller]/user/1
|
||||
[Route("user/{userId:int}")]
|
||||
[Route("user/{userId:guid}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetUserLocation(int userId)
|
||||
public async Task<IActionResult> GetUserLocation(Guid userId)
|
||||
{
|
||||
var userLocation = await _locationsService.GetUserLocation(userId);
|
||||
var userLocation = await _locationsService.GetUserLocation(userId.ToString());
|
||||
return Ok(userLocation);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
Task<List<Locations>> GetLocationListAsync();
|
||||
|
||||
Task<UserLocation> GetUserLocationAsync(int userId);
|
||||
Task<UserLocation> GetUserLocationAsync(string userId);
|
||||
|
||||
Task<List<Locations>> GetCurrentUserRegionsListAsync(LocationRequest currentPosition);
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<UserLocation> GetUserLocationAsync(int userId)
|
||||
public async Task<UserLocation> GetUserLocationAsync(string userId)
|
||||
{
|
||||
var filter = Builders<UserLocation>.Filter.Eq("UserId", userId);
|
||||
return await _context.UserLocation
|
||||
|
@ -9,7 +9,7 @@
|
||||
{
|
||||
Task<Locations> GetLocation(string locationId);
|
||||
|
||||
Task<UserLocation> GetUserLocation(int id);
|
||||
Task<UserLocation> GetUserLocation(string id);
|
||||
|
||||
Task<List<Locations>> GetAllLocation();
|
||||
|
||||
|
@ -23,9 +23,14 @@
|
||||
return await _locationsRepository.GetAsync(locationId);
|
||||
}
|
||||
|
||||
public async Task<UserLocation> GetUserLocation(int id)
|
||||
public async Task<UserLocation> GetUserLocation(string id)
|
||||
{
|
||||
return await _locationsRepository.GetUserLocationAsync(id);
|
||||
if (!Guid.TryParse(id, out Guid userId))
|
||||
{
|
||||
throw new ArgumentException("Not valid userId");
|
||||
}
|
||||
|
||||
return await _locationsRepository.GetUserLocationAsync(userId.ToString());
|
||||
}
|
||||
|
||||
public async Task<List<Locations>> GetAllLocation()
|
||||
@ -35,7 +40,7 @@
|
||||
|
||||
public async Task<bool> AddOrUpdateUserLocation(string id, LocationRequest currentPosition)
|
||||
{
|
||||
if (!int.TryParse(id, out int userId))
|
||||
if (!Guid.TryParse(id, out Guid userId))
|
||||
{
|
||||
throw new ArgumentException("Not valid userId");
|
||||
}
|
||||
@ -50,7 +55,7 @@
|
||||
|
||||
// If current area found, then update user location
|
||||
var locationAncestors = new List<string>();
|
||||
var userLocation = await _locationsRepository.GetUserLocationAsync(userId);
|
||||
var userLocation = await _locationsRepository.GetUserLocationAsync(userId.ToString());
|
||||
userLocation = userLocation ?? new UserLocation();
|
||||
userLocation.UserId = userId;
|
||||
userLocation.LocationId = currentUserAreaLocationList[0].Id;
|
||||
|
@ -9,7 +9,7 @@
|
||||
[BsonIgnoreIfDefault]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public int UserId { get; set; } = 0;
|
||||
public Guid UserId { get; set; }
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string LocationId { get; set; }
|
||||
public DateTime UpdateDate { get; set; }
|
||||
|
@ -27,7 +27,7 @@ namespace IntegrationTests.Services.Locations
|
||||
return $"api/v1/locations/{id}";
|
||||
}
|
||||
|
||||
public static string UserLocationBy(int id)
|
||||
public static string UserLocationBy(Guid id)
|
||||
{
|
||||
return $"api/v1/locations/user/{id}";
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using System;
|
||||
|
||||
namespace IntegrationTests.Services.Locations
|
||||
{
|
||||
@ -18,7 +19,7 @@ namespace IntegrationTests.Services.Locations
|
||||
{
|
||||
using (var server = CreateServer())
|
||||
{
|
||||
var userId = 1234;
|
||||
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
|
||||
var content = new StringContent(BuildLocationsRequest(-122.315752, 47.604610), UTF8Encoding.UTF8, "application/json");
|
||||
|
||||
// Expected result
|
||||
@ -50,7 +51,7 @@ namespace IntegrationTests.Services.Locations
|
||||
{
|
||||
using (var server = CreateServer())
|
||||
{
|
||||
var userId = 1234;
|
||||
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
|
||||
var content = new StringContent(BuildLocationsRequest(-122.119998, 47.690876), UTF8Encoding.UTF8, "application/json");
|
||||
|
||||
// Expected result
|
||||
@ -82,7 +83,7 @@ namespace IntegrationTests.Services.Locations
|
||||
{
|
||||
using (var server = CreateServer())
|
||||
{
|
||||
var userId = 1234;
|
||||
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
|
||||
var content = new StringContent(BuildLocationsRequest(-121.040360, 48.091631), UTF8Encoding.UTF8, "application/json");
|
||||
|
||||
// Expected result
|
||||
|
@ -3,7 +3,10 @@
|
||||
using IntegrationTests.Middleware;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.eShopOnContainers.Services.Locations.API;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class LocationsTestsStartup : Startup
|
||||
{
|
||||
@ -15,12 +18,29 @@
|
||||
{
|
||||
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
||||
{
|
||||
app.UseMiddleware<AutoAuthorizeMiddleware>();
|
||||
app.UseMiddleware<LocationAuthorizeMiddleware>();
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ConfigureAuth(app);
|
||||
}
|
||||
}
|
||||
|
||||
class LocationAuthorizeMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
public LocationAuthorizeMiddleware(RequestDelegate rd)
|
||||
{
|
||||
_next = rd;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext httpContext)
|
||||
{
|
||||
var identity = new ClaimsIdentity("cookies");
|
||||
identity.AddClaim(new Claim("sub", "4611ce3f-380d-4db5-8d76-87a8689058ed"));
|
||||
httpContext.User.AddIdentity(identity);
|
||||
await _next.Invoke(httpContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user