Add UserDbContext, UserDbDal, DbTestPage, etc...
This commit is contained in:
parent
4ba61ba048
commit
4bed3bc4f4
|
|
@ -11,11 +11,20 @@ namespace TIAM.Database.DataLayers.Users
|
||||||
{
|
{
|
||||||
public class UserDal : TiamDalBase<UserDbContext>
|
public class UserDal : TiamDalBase<UserDbContext>
|
||||||
{
|
{
|
||||||
private DbSet<User> Users { get; set; }
|
|
||||||
public UserDal() : base()
|
public UserDal() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//public User
|
public Task<List<User>> GetUsersAsync()
|
||||||
|
{
|
||||||
|
return Ctx.Users.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<User?> GetUserByEmailAsync(string email)
|
||||||
|
{
|
||||||
|
var emailLower = email.ToLower();
|
||||||
|
return Ctx.Users.SingleOrDefaultAsync(x=>x.Email.ToLower() == emailLower);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@ using System.Threading.Tasks;
|
||||||
using AyCode.Database.DbContexts;
|
using AyCode.Database.DbContexts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using TIAM.Entities.TransferDestinations;
|
using TIAM.Entities.TransferDestinations;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
namespace TIAM.Database.DbContexts
|
namespace TIAM.Database.DbContexts
|
||||||
{
|
{
|
||||||
public class UserDbContext : TiamDbContextBase
|
public class UserDbContext : TiamDbContextBase
|
||||||
{
|
{
|
||||||
public DbSet<TransferDestination> TransferDestinations { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
public UserDbContext() //: this(string.Empty)
|
public UserDbContext() //: this(string.Empty)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,9 @@ namespace TIAM.Entities.Users
|
||||||
{
|
{
|
||||||
public class User : UserBase
|
public class User : UserBase
|
||||||
{
|
{
|
||||||
|
public User() { }
|
||||||
|
public User(string email, string password) : this(Guid.NewGuid(), email, password) { }
|
||||||
|
public User(Guid id, string email, string password) : base(id, email, password)
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
|
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
|
||||||
IgnorableNamespaces="uap rescap">
|
IgnorableNamespaces="uap rescap">
|
||||||
|
|
||||||
<Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="0.0.0.0" />
|
<Identity Name="maui-package-name-placeholder" Publisher="CN=UserModel Name" Version="0.0.0.0" />
|
||||||
|
|
||||||
<mp:PhoneIdentity PhoneProductId="D715EEC2-0430-4284-94A2-9EC92B64BE9F" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
<mp:PhoneIdentity PhoneProductId="D715EEC2-0430-4284-94A2-9EC92B64BE9F" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||||
|
|
||||||
<Properties>
|
<Properties>
|
||||||
<DisplayName>$placeholder$</DisplayName>
|
<DisplayName>$placeholder$</DisplayName>
|
||||||
<PublisherDisplayName>User Name</PublisherDisplayName>
|
<PublisherDisplayName>UserModel Name</PublisherDisplayName>
|
||||||
<Logo>$placeholder$.png</Logo>
|
<Logo>$placeholder$.png</Logo>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
using TIAMWebApp.Shared.Application.Interfaces;
|
using TIAMWebApp.Shared.Application.Interfaces;
|
||||||
using TIAMWebApp.Shared.Application.Models;
|
using TIAMWebApp.Shared.Application.Models;
|
||||||
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
||||||
|
|
@ -14,7 +15,7 @@ namespace TIAMMobilApp.Services
|
||||||
{
|
{
|
||||||
private readonly HttpClient http;
|
private readonly HttpClient http;
|
||||||
private readonly ISecureStorageHandler secureStorageHandler;
|
private readonly ISecureStorageHandler secureStorageHandler;
|
||||||
public User? User { get; set; } = new User("", "", "");
|
public UserModel? User { get; set; } = new UserModel("", "", "");
|
||||||
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
|
||||||
public UserDataService(HttpClient http, ISecureStorageHandler secureStorageHandler)
|
public UserDataService(HttpClient http, ISecureStorageHandler secureStorageHandler)
|
||||||
|
|
@ -39,11 +40,11 @@ namespace TIAMMobilApp.Services
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public async Task<User> IsLoggedInAsync()
|
public async Task<UserModel> IsLoggedInAsync()
|
||||||
{
|
{
|
||||||
if (User == null)
|
if (User == null)
|
||||||
{
|
{
|
||||||
User = new User("", "", "");
|
User = new UserModel("", "", "");
|
||||||
User.IsLoggedIn = false;
|
User.IsLoggedIn = false;
|
||||||
User.UserType = UserType.User;
|
User.UserType = UserType.User;
|
||||||
return User;
|
return User;
|
||||||
|
|
@ -57,11 +58,11 @@ namespace TIAMMobilApp.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
//Mock method for now
|
//Mock method for now
|
||||||
public async Task<User> AuthorizeUserAsync(int userType)
|
public async Task<UserModel> AuthorizeUserAsync(int userType)
|
||||||
{
|
{
|
||||||
if (User == null)
|
if (User == null)
|
||||||
{
|
{
|
||||||
User = new User("", "", "");
|
User = new UserModel("", "", "");
|
||||||
}
|
}
|
||||||
//simply return true for now
|
//simply return true for now
|
||||||
User.IsLoggedIn = true;
|
User.IsLoggedIn = true;
|
||||||
|
|
@ -126,6 +127,16 @@ namespace TIAMMobilApp.Services
|
||||||
return (isSuccess, result);
|
return (isSuccess, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<User>> GetUsersAsync()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<User> GetUserByEmailAsync(string email)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> RefreshToken()
|
public async Task<bool> RefreshToken()
|
||||||
{
|
{
|
||||||
bool isTokenRefreshed = false;
|
bool isTokenRefreshed = false;
|
||||||
|
|
@ -169,10 +180,10 @@ namespace TIAMMobilApp.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Task<Dictionary<int, string>> GetUserRolesAsync(User user)
|
public Task<Dictionary<int, string>> GetUserRolesAsync(UserModel userModel)
|
||||||
{
|
{
|
||||||
|
|
||||||
//get the user's roles
|
//get the userModel's roles
|
||||||
int role = User.UserRoles;
|
int role = User.UserRoles;
|
||||||
|
|
||||||
foreach (var roleType in roleTypes)
|
foreach (var roleType in roleTypes)
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,16 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="7.0.1" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="7.0.1" Version="7.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="AyCode.Core">
|
||||||
|
<HintPath>..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AyCode.Entities">
|
||||||
|
<HintPath>..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Entities.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AyCode.Interfaces">
|
||||||
|
<HintPath>..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Interfaces.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
@if (Users == null)
|
||||||
|
{
|
||||||
|
<p>
|
||||||
|
<em>Loading ...</em>
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
<div class="form-field d-flex align-items-center">
|
||||||
|
|
||||||
|
@foreach (var dest in Users)
|
||||||
|
{
|
||||||
|
<p>@dest.Email</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
|
using TIAMWebApp.Shared.Application.Interfaces;
|
||||||
|
using TIAMWebApp.Shared.Application.Models;
|
||||||
|
|
||||||
|
namespace TIAMSharedUI.Pages
|
||||||
|
{
|
||||||
|
public partial class DbTestComponent: ComponentBase
|
||||||
|
{
|
||||||
|
[Parameter]
|
||||||
|
public string EmailAddress
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
public List<TIAM.Entities.Users.User>? Users
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
[Inject]
|
||||||
|
public IUserDataService UserDataService
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
[Parameter]
|
||||||
|
public string Value
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<string> ValueChanged
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
Users = (await UserDataService.GetUsersAsync())?.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task OnValueChanged(ChangeEventArgs e)
|
||||||
|
{
|
||||||
|
Value = e.Value.ToString();
|
||||||
|
DisplayCard();
|
||||||
|
return ValueChanged.InvokeAsync(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DisplayCard()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
<option value="2" selected>Transfer</option>
|
<option value="2" selected>Transfer</option>
|
||||||
<option value="3" selected>Guide</option>
|
<option value="3" selected>Guide</option>
|
||||||
<option value="4" selected>Admin</option>
|
<option value="4" selected>Admin</option>
|
||||||
<option value="5" selected>User</option>
|
<option value="5" selected>UserModel</option>
|
||||||
<option value="6" selected>Driver</option>
|
<option value="6" selected>Driver</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
@page "/dbtest"
|
||||||
|
<h3>TestPage</h3>
|
||||||
|
|
||||||
|
<ChooseDestination></ChooseDestination>
|
||||||
|
<hr/>
|
||||||
|
<DbTestComponent></DbTestComponent>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
@inherits LayoutComponentBase
|
@inherits LayoutComponentBase
|
||||||
@using TIAMSharedUI.Shared.User
|
@using TIAMSharedUI.Shared.Users
|
||||||
@using TIAMWebApp.Shared.Application.Interfaces
|
@using TIAMWebApp.Shared.Application.Interfaces
|
||||||
@using TIAMWebApp.Shared.Application.Models;
|
@using TIAMWebApp.Shared.Application.Models;
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@
|
||||||
|
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
|
|
||||||
<article class="content">
|
<article class="content">
|
||||||
@{
|
@{
|
||||||
if(isUserLoggedIn)
|
if(isUserLoggedIn)
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,16 @@
|
||||||
<ProjectReference Include="..\TIAMWebApp\Shared\TIAMWebApp.Shared.Application.csproj" />
|
<ProjectReference Include="..\TIAMWebApp\Shared\TIAMWebApp.Shared.Application.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="AyCode.Core">
|
||||||
|
<HintPath>..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AyCode.Entities">
|
||||||
|
<HintPath>..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Entities.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AyCode.Interfaces">
|
||||||
|
<HintPath>..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Interfaces.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using TIAM.Entities.TransferDestinations;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
using TIAMWebApp.Shared.Application.Interfaces;
|
using TIAMWebApp.Shared.Application.Interfaces;
|
||||||
using TIAMWebApp.Shared.Application.Models;
|
using TIAMWebApp.Shared.Application.Models;
|
||||||
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
||||||
|
|
@ -14,7 +16,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
{
|
{
|
||||||
private readonly HttpClient http;
|
private readonly HttpClient http;
|
||||||
private readonly ISecureStorageHandler secureStorageHandler;
|
private readonly ISecureStorageHandler secureStorageHandler;
|
||||||
public User? User { get; set; } = new User("", "", "");
|
public UserModel? User { get; set; } = new UserModel("", "", "");
|
||||||
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
|
||||||
public UserDataService(HttpClient http, ISecureStorageHandler secureStorageHandler)
|
public UserDataService(HttpClient http, ISecureStorageHandler secureStorageHandler)
|
||||||
|
|
@ -39,11 +41,11 @@ namespace TIAMWebApp.Client.Services
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public async Task<User> IsLoggedInAsync()
|
public async Task<UserModel> IsLoggedInAsync()
|
||||||
{
|
{
|
||||||
if (User == null)
|
if (User == null)
|
||||||
{
|
{
|
||||||
User = new User("", "", "");
|
User = new UserModel("", "", "");
|
||||||
User.IsLoggedIn = false;
|
User.IsLoggedIn = false;
|
||||||
User.UserType = UserType.User;
|
User.UserType = UserType.User;
|
||||||
return User;
|
return User;
|
||||||
|
|
@ -57,11 +59,11 @@ namespace TIAMWebApp.Client.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
//Mock method for now
|
//Mock method for now
|
||||||
public async Task<User> AuthorizeUserAsync(int userType)
|
public async Task<UserModel> AuthorizeUserAsync(int userType)
|
||||||
{
|
{
|
||||||
if (User == null)
|
if (User == null)
|
||||||
{
|
{
|
||||||
User = new User("", "", "");
|
User = new UserModel("", "", "");
|
||||||
}
|
}
|
||||||
//simply return true for now
|
//simply return true for now
|
||||||
User.IsLoggedIn = true;
|
User.IsLoggedIn = true;
|
||||||
|
|
@ -126,6 +128,16 @@ namespace TIAMWebApp.Client.Services
|
||||||
return (isSuccess, result);
|
return (isSuccess, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<User>?> GetUsersAsync()
|
||||||
|
{
|
||||||
|
return await http.GetFromJsonAsync<IEnumerable<User>>(APIUrls.GetUsers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<User?> GetUserByEmailAsync(string email)
|
||||||
|
{
|
||||||
|
return await http.GetFromJsonAsync<User?>(APIUrls.GetUserByEmail);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> RefreshToken()
|
public async Task<bool> RefreshToken()
|
||||||
{
|
{
|
||||||
bool isTokenRefreshed = false;
|
bool isTokenRefreshed = false;
|
||||||
|
|
@ -169,10 +181,10 @@ namespace TIAMWebApp.Client.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Task<Dictionary<int, string>> GetUserRolesAsync(User user)
|
public Task<Dictionary<int, string>> GetUserRolesAsync(UserModel userModel)
|
||||||
{
|
{
|
||||||
|
|
||||||
//get the user's roles
|
//get the userModel's roles
|
||||||
int role = User.UserRoles;
|
int role = User.UserRoles;
|
||||||
|
|
||||||
foreach (var roleType in roleTypes)
|
foreach (var roleType in roleTypes)
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,16 @@
|
||||||
<ProjectReference Include="..\Shared\TIAMWebApp.Shared.Application.csproj" />
|
<ProjectReference Include="..\Shared\TIAMWebApp.Shared.Application.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="AyCode.Core">
|
||||||
|
<HintPath>..\..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AyCode.Entities">
|
||||||
|
<HintPath>..\..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Entities.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AyCode.Interfaces">
|
||||||
|
<HintPath>..\..\..\AyCode.Core\AyCode.Database\bin\Debug\net7.0\AyCode.Interfaces.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -27,22 +27,19 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
//};
|
//};
|
||||||
|
|
||||||
private readonly UserDal _userDal;
|
private readonly TransferDestinationDal _transferDestinationDal;
|
||||||
private readonly ILogger<TransferDataAPIController> _logger;
|
private readonly ILogger<TransferDataAPIController> _logger;
|
||||||
|
|
||||||
public TransferDataAPIController(ILogger<TransferDataAPIController> logger, UserDal userDal)
|
public TransferDataAPIController(ILogger<TransferDataAPIController> logger, TransferDestinationDal transferDestinationDal)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_userDal = userDal;
|
_transferDestinationDal = transferDestinationDal;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IEnumerable<TransferDestination>> Get()
|
public async Task<IEnumerable<TransferDestination>> Get()
|
||||||
{
|
{
|
||||||
//return new JsonResult(await _transferDestinationDbContext.TransferDestinations.ToListAsync());
|
return await _transferDestinationDal.Ctx.TransferDestinations.ToListAsync();
|
||||||
|
|
||||||
var result = await _userDal.Ctx.TransferDestinations.ToListAsync();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,34 +15,39 @@ using TIAMWebApp.Shared.Application.Models.PageModels;
|
||||||
using TIAMWebApp.Server.Models;
|
using TIAMWebApp.Server.Models;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using TIAM.Database.DataLayers.Users;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models;
|
using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models;
|
||||||
|
|
||||||
namespace TIAMWebApp.Server.Controllers
|
namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class UserAPIController : ControllerBase
|
public class UserAPIController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private UserDal _userDal;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||||
PasswordHasher hasher = new PasswordHasher();
|
PasswordHasher hasher = new PasswordHasher();
|
||||||
|
|
||||||
|
|
||||||
private User[] users = new User[]
|
private UserModel[] users = new UserModel[]
|
||||||
{
|
{
|
||||||
new User(new Guid("540271f6-c604-4c16-8160-d5a7cafedf00"), "test@tiam.hu", "+36701234567", "Asdasd123456"),
|
new UserModel(new Guid("540271f6-c604-4c16-8160-d5a7cafedf00"), "test@tiam.hu", "+36701234567", "Asdasd123456"),
|
||||||
new User(new Guid("4cbaed43-2465-4d99-84f1-c8bc6b7025f7"), "adam@tiam.hu", "+36701234567", "Asdasd987654")
|
new UserModel(new Guid("4cbaed43-2465-4d99-84f1-c8bc6b7025f7"), "adam@tiam.hu", "+36701234567", "Asdasd987654")
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly ILogger<UserAPIController> _logger;
|
private readonly ILogger<UserAPIController> _logger;
|
||||||
|
|
||||||
public UserAPIController(ILogger<UserAPIController> logger, IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
|
public UserAPIController(ILogger<UserAPIController> logger, IConfiguration configuration, IWebHostEnvironment webHostEnvironment, UserDal userDal)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_webHostEnvironment = webHostEnvironment;
|
_webHostEnvironment = webHostEnvironment;
|
||||||
|
_userDal = userDal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -58,19 +63,19 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var user = JObject.Parse(SerializedLoginModel.GetRawText()).ToObject<LoginModel>();
|
var userModel = JObject.Parse(SerializedLoginModel.GetRawText()).ToObject<LoginModel>();
|
||||||
|
|
||||||
Console.WriteLine(user.Email);
|
Console.WriteLine(userModel.Email);
|
||||||
Console.WriteLine(user.Password);
|
Console.WriteLine(userModel.Password);
|
||||||
|
|
||||||
if (user.Email == "test@tiam.hu" && user.Password == "Asdasd123456")
|
if (userModel.Email == "test@tiam.hu" && userModel.Password == "Asdasd123456")
|
||||||
{
|
{
|
||||||
Console.WriteLine("User authenticated");
|
Console.WriteLine("UserModel authenticated");
|
||||||
return Ok("yes");
|
return Ok("yes");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("User NOT authenticated");
|
Console.WriteLine("UserModel NOT authenticated");
|
||||||
return Ok("no");
|
return Ok("no");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,15 +89,15 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
var authenticateUser = JObject.Parse(SerializedLoginModel.GetRawText()).ToObject<LoginModel>();
|
var authenticateUser = JObject.Parse(SerializedLoginModel.GetRawText()).ToObject<LoginModel>();
|
||||||
|
|
||||||
//check if user exists
|
//check if userModel exists
|
||||||
//var user = await _userManager.FindByNameAsync(authenticateUser.UserName);
|
//var userModel = await _userManager.FindByNameAsync(authenticateUser.UserName);
|
||||||
//if (user == null) return Unauthorized();
|
//if (userModel == null) return Unauthorized();
|
||||||
|
|
||||||
//mocking
|
//mocking
|
||||||
var user = users.FirstOrDefault(x => x.Email == authenticateUser.Email);
|
var user = users.FirstOrDefault(x => x.Email == authenticateUser.Email);
|
||||||
|
|
||||||
//check if password is valid
|
//check if password is valid
|
||||||
//bool isValidUser = await _userManager.CheckPasswordAsync(user, authenticateUser.Password);
|
//bool isValidUser = await _userManager.CheckPasswordAsync(userModel, authenticateUser.Password);
|
||||||
|
|
||||||
//mocking
|
//mocking
|
||||||
bool isValidUser = false;
|
bool isValidUser = false;
|
||||||
|
|
@ -105,13 +110,13 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
if (isValidUser)
|
if (isValidUser)
|
||||||
{
|
{
|
||||||
Console.WriteLine("User authenticated, let's start JWT");
|
Console.WriteLine("UserModel authenticated, let's start JWT");
|
||||||
string accessToken = GenerateAccessToken(user);
|
string accessToken = GenerateAccessToken(user);
|
||||||
Console.WriteLine("Generate refresh token");
|
Console.WriteLine("Generate refresh token");
|
||||||
var refreshToken = GenerateRefreshToken();
|
var refreshToken = GenerateRefreshToken();
|
||||||
user.RefreshToken = refreshToken;
|
user.RefreshToken = refreshToken;
|
||||||
//Update user with refreshToken!!
|
//Update userModel with refreshToken!!
|
||||||
//await _userManager.UpdateAsync(user);
|
//await _userManager.UpdateAsync(userModel);
|
||||||
|
|
||||||
var response = new MainResponse
|
var response = new MainResponse
|
||||||
{
|
{
|
||||||
|
|
@ -132,7 +137,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateAccessToken(User user)
|
private string GenerateAccessToken(UserModel userModel)
|
||||||
{
|
{
|
||||||
var tokenHandler = new JwtSecurityTokenHandler();
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
var token = new JwtSecurityToken();
|
var token = new JwtSecurityToken();
|
||||||
|
|
@ -142,8 +147,8 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
var claims = new List<Claim>
|
var claims = new List<Claim>
|
||||||
{
|
{
|
||||||
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
new Claim(ClaimTypes.NameIdentifier, userModel.Id.ToString()),
|
||||||
new Claim(ClaimTypes.Email, user.Email)
|
new Claim(ClaimTypes.Email, userModel.Email)
|
||||||
};
|
};
|
||||||
|
|
||||||
var tokenDescriptor = new SecurityTokenDescriptor
|
var tokenDescriptor = new SecurityTokenDescriptor
|
||||||
|
|
@ -177,7 +182,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
var email = principal.Claims.FirstOrDefault(f => f.Type == ClaimTypes.Email);
|
var email = principal.Claims.FirstOrDefault(f => f.Type == ClaimTypes.Email);
|
||||||
|
|
||||||
//var user = await _userManager.FindByEmailAsync(email?.Value);
|
//var userModel = await _userManager.FindByEmailAsync(email?.Value);
|
||||||
var user = users.FirstOrDefault(x => x.Email == email?.Value);
|
var user = users.FirstOrDefault(x => x.Email == email?.Value);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -190,9 +195,9 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
string newAccessToken = GenerateAccessToken(user);
|
string newAccessToken = GenerateAccessToken(user);
|
||||||
string refreshToken = GenerateRefreshToken();
|
string refreshToken = GenerateRefreshToken();
|
||||||
|
|
||||||
//mocking - update user with new refreshToken
|
//mocking - update userModel with new refreshToken
|
||||||
user.RefreshToken = refreshToken;
|
user.RefreshToken = refreshToken;
|
||||||
//await _userManager.UpdateAsync(user);
|
//await _userManager.UpdateAsync(userModel);
|
||||||
|
|
||||||
response.IsSuccess = true;
|
response.IsSuccess = true;
|
||||||
response.Content = new AuthenticationResponse
|
response.Content = new AuthenticationResponse
|
||||||
|
|
@ -261,9 +266,9 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
if (users != null)
|
if (users != null)
|
||||||
{
|
{
|
||||||
//add user to users array
|
//add userModel to users array
|
||||||
Array.Resize(ref users, users.Length + 1);
|
Array.Resize(ref users, users.Length + 1);
|
||||||
users[users.Length - 1] = new User(user.Email, user.PhoneNumber, user.Password);
|
users[users.Length - 1] = new UserModel(user.Email, user.PhoneNumber, user.Password);
|
||||||
return Ok("yes");
|
return Ok("yes");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -294,9 +299,18 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("GetUsers")]
|
[Route("GetUsers")]
|
||||||
public IEnumerable<Supplier> GetUsers()
|
public Task<List<User?>> GetUsers()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
//var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync();
|
||||||
|
//return users;
|
||||||
|
return _userDal.GetUsersAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("GetUserByEmail")]
|
||||||
|
public Task<User?> GetUserByEmail(string email)
|
||||||
|
{
|
||||||
|
return _userDal.GetUserByEmailAsync(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool VerifyPassword(string password, string hashedPassword)
|
private bool VerifyPassword(string password, string hashedPassword)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ using System.Text;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using TIAMWebApp.Shared.Application.Models;
|
using TIAMWebApp.Shared.Application.Models;
|
||||||
|
using TIAM.Database.DataLayers.Users;
|
||||||
|
using TIAM.Database.DataLayers.TransferDestinations;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
|
@ -18,7 +20,9 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
builder.Services.AddDbContext<TransferDestinationDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DeveloperDbConnection")));;
|
//builder.Services.AddDbContext<TransferDestinationDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DeveloperDbConnection")));;
|
||||||
|
builder.Services.AddScoped<UserDal>();
|
||||||
|
builder.Services.AddScoped<TransferDestinationDal>();
|
||||||
|
|
||||||
builder.Services.AddSwaggerGen(swagger =>
|
builder.Services.AddSwaggerGen(swagger =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
using TIAMWebApp.Shared.Application.Models;
|
using TIAMWebApp.Shared.Application.Models;
|
||||||
using TIAMWebApp.Shared.Application.Models.PageModels;
|
using TIAMWebApp.Shared.Application.Models.PageModels;
|
||||||
|
|
||||||
|
|
@ -10,20 +11,22 @@ namespace TIAMWebApp.Shared.Application.Interfaces
|
||||||
{
|
{
|
||||||
public interface IUserDataService
|
public interface IUserDataService
|
||||||
{
|
{
|
||||||
public User? User { get; set; }
|
public UserModel? User { get; set; }
|
||||||
public Dictionary<int, string> userRoleTypes { get; set; }
|
public Dictionary<int, string> userRoleTypes { get; set; }
|
||||||
|
|
||||||
public Task<User> IsLoggedInAsync();
|
public Task<UserModel> IsLoggedInAsync();
|
||||||
|
|
||||||
//mock method for now
|
//mock method for now
|
||||||
public Task<User> AuthorizeUserAsync(int userType);
|
public Task<UserModel> AuthorizeUserAsync(int userType);
|
||||||
|
|
||||||
public Task<string> AuthenticateUser(LoginModel loginModel);
|
public Task<string> AuthenticateUser(LoginModel loginModel);
|
||||||
public Task<(bool isSuccess, string ErrorMessage)> CreateUser(RegistrationModel regModel);
|
public Task<(bool isSuccess, string ErrorMessage)> CreateUser(RegistrationModel regModel);
|
||||||
public Task<string> TestUserApi(int Param);
|
public Task<string> TestUserApi(int Param);
|
||||||
|
|
||||||
public Task<Dictionary<int, string>> GetUserRolesAsync(User user);
|
public Task<Dictionary<int, string>> GetUserRolesAsync(UserModel userModel);
|
||||||
|
|
||||||
|
public Task<IEnumerable<User>?> GetUsersAsync();
|
||||||
|
public Task<User?> GetUserByEmailAsync(string email);
|
||||||
Task<bool> RefreshToken();
|
Task<bool> RefreshToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,6 +9,8 @@ namespace TIAMWebApp.Shared.Application.Models
|
||||||
public class APIUrls
|
public class APIUrls
|
||||||
{
|
{
|
||||||
public const string UserTest = "api/UserAPI/test1";
|
public const string UserTest = "api/UserAPI/test1";
|
||||||
|
public const string GetUserByEmail = "api/UserAPI/GetUserByEmail";
|
||||||
|
public const string GetUsers = "api/UserAPI/GetUsers";
|
||||||
public const string AuthenticateUser = "api/UserAPI/AuthenticateUser";
|
public const string AuthenticateUser = "api/UserAPI/AuthenticateUser";
|
||||||
public const string CreateUser = "api/UserAPI/CreateUser";
|
public const string CreateUser = "api/UserAPI/CreateUser";
|
||||||
public const string RefreshToken = "api/UserAPI/RefreshToken";
|
public const string RefreshToken = "api/UserAPI/RefreshToken";
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
namespace TIAMWebApp.Shared.Application.Models
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
|
namespace TIAMWebApp.Shared.Application.Models
|
||||||
{
|
{
|
||||||
public class User
|
public class UserModel : User
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
|
||||||
public string? Email { get; set; }
|
|
||||||
public string? Password { get; set; }
|
|
||||||
public string? PhoneNumber { get; set; }
|
public string? PhoneNumber { get; set; }
|
||||||
public bool IsLoggedIn { get; set; }
|
public bool IsLoggedIn { get; set; }
|
||||||
public UserType UserType { get; set; }
|
public UserType UserType { get; set; }
|
||||||
|
|
@ -12,20 +11,12 @@
|
||||||
public string? RefreshToken { get; set; }
|
public string? RefreshToken { get; set; }
|
||||||
public Dictionary<int, string> UserRolesDictionary { get; set; }
|
public Dictionary<int, string> UserRolesDictionary { get; set; }
|
||||||
|
|
||||||
public User(string email, string phonenumber, string password)
|
public UserModel(string email, string phonenumber, string password) : this(Guid.NewGuid(), email, phonenumber, password)
|
||||||
{
|
{
|
||||||
Id = new Guid();
|
|
||||||
Email = email;
|
|
||||||
Password = password;
|
|
||||||
PhoneNumber = phonenumber;
|
|
||||||
UserRolesDictionary = new Dictionary<int, string>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(Guid id, string email, string phonenumber, string password)
|
public UserModel(Guid id, string email, string phonenumber, string password) : base(id, email, password)
|
||||||
{
|
{
|
||||||
Id = id;
|
|
||||||
Email = email;
|
|
||||||
Password = password;
|
|
||||||
PhoneNumber = phonenumber;
|
PhoneNumber = phonenumber;
|
||||||
UserRolesDictionary = new Dictionary<int, string>();
|
UserRolesDictionary = new Dictionary<int, string>();
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TIAM.Entities", "TIAM.Entit
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TIAM.Entities.Server", "TIAM.Entities.Server\TIAM.Entities.Server.csproj", "{BDDF5F32-D275-4BBB-9C81-8DCB1025A935}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TIAM.Entities.Server", "TIAM.Entities.Server\TIAM.Entities.Server.csproj", "{BDDF5F32-D275-4BBB-9C81-8DCB1025A935}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TIAM.Core", "TIAM.Core\TIAM.Core.csproj", "{4FDE0CD3-5914-4919-933B-6B0E04275313}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TIAM.Core", "TIAM.Core\TIAM.Core.csproj", "{4FDE0CD3-5914-4919-933B-6B0E04275313}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue