refactoring, improvements, fixes, etc...
This commit is contained in:
parent
65173cea1c
commit
764bc71386
|
|
@ -1,22 +1,12 @@
|
|||
using AyCode.Database.DataLayers;
|
||||
using AyCode.Database.Tests;
|
||||
using AyCode.Database.Tests.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using AyCode.Database.Tests.Users;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using AyCode.Core.Consts;
|
||||
using TIAM.Database.DataLayers.Users;
|
||||
using TIAM.Database.DbContexts.Users;
|
||||
using TIAM.Entities.Profiles;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAM.Models.Dtos.Users;
|
||||
using AyCode.Interfaces.Users.Dtos;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using TIAM.Core.Consts;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Addresses;
|
||||
using TIAMWebApp.Server.Services.Logins;
|
||||
|
|
@ -27,7 +17,14 @@ namespace TIAM.Database.Test
|
|||
[TestClass]
|
||||
public class UserDalTests : AcUserDalTestBase<UserDal, UserDbContext, User, Profile, UserToken, TiamServiceProvider, UserToServiceProvider, Address>
|
||||
{
|
||||
private WebAssemblyHostConfiguration _configuration = new WebAssemblyHostConfiguration();
|
||||
private Guid _registerUserId = Guid.Parse("1f7e0591-330b-463b-81ad-d01f2e65e23e");
|
||||
private const string RegisterEmail = "qwerty@xxxxx.com";
|
||||
private const string RegisterPassword = "elem'r";
|
||||
|
||||
private const string LoginEmail = "asdfsdf@ggggg.hu";
|
||||
private const string LoginPassword = "alad'r";
|
||||
|
||||
private WebAssemblyHostConfiguration _configuration = new();
|
||||
//private Mock<UserDbContext> _mockContext;
|
||||
|
||||
[TestInitialize]
|
||||
|
|
@ -53,27 +50,53 @@ namespace TIAM.Database.Test
|
|||
//_userDal = new UserDal(_mockContext.Object);
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
[TestMethod]
|
||||
public async Task RegisterUser_ReturnsUser_WhenUserExist()
|
||||
{
|
||||
//var a = TiamConst.ProjectIdString;
|
||||
|
||||
var userId = Guid.Parse("1ded6045-1278-4b92-a10a-3eb9426e41a3");
|
||||
//await Dal.RemoveUserAsync(userId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
||||
await Dal.RemoveUserAsync(_registerUserId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
||||
|
||||
var loginService = new LoginService(Dal, new WebAssemblyHostConfiguration());
|
||||
var user = await loginService.RegistrationAsync(userId, "asdfsdf@ggggg.hu", "alad'r", null);
|
||||
Assert.IsNotNull(user);
|
||||
var loginService = new LoginService(Dal, _configuration);
|
||||
var errorCode = await loginService.RegistrationAsync(_registerUserId, RegisterEmail, RegisterPassword, null);
|
||||
|
||||
Assert.IsTrue(errorCode == AcErrorCode.Unset);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LoginUser_ReturnsUser_WhenUserExist()
|
||||
{
|
||||
//var a = TiamConst.ProjectIdString;
|
||||
|
||||
|
||||
var loginService = new LoginService(Dal, _configuration);
|
||||
var user = loginService.Login("asdfsdf@ggggg.hu", "alad'r", out _);
|
||||
Assert.IsNotNull(user);
|
||||
|
||||
#region Valid email+password test
|
||||
var loggedInModel = loginService.Login(LoginEmail, LoginPassword);
|
||||
|
||||
Assert.IsNotNull(loggedInModel);
|
||||
Assert.IsNotNull(loggedInModel.LoggedInUser);
|
||||
Assert.IsNotNull(loginService.LoggedInModel?.LoggedInUser);
|
||||
|
||||
Assert.IsTrue(loggedInModel.LoginErrorCode == AcErrorCode.Unset, $"errorCode: {loggedInModel.LoginErrorCode}");
|
||||
Assert.IsTrue(loggedInModel.IsLoggedIn, $"loggedInModel.IsLoggedIn == false; errorCode: {loggedInModel.LoginErrorCode}");
|
||||
Assert.IsTrue(string.Equals(loggedInModel.LoggedInUser.EmailAddress, LoginEmail, StringComparison.CurrentCultureIgnoreCase));
|
||||
#endregion Valid email+password test
|
||||
|
||||
#region Wrong email test
|
||||
loggedInModel = loginService.Login("gffsdgdfg@gu.hu", LoginPassword);
|
||||
|
||||
Assert.IsNotNull(loggedInModel);
|
||||
Assert.IsFalse(loggedInModel.IsLoggedIn);
|
||||
Assert.IsTrue(loggedInModel.LoginErrorCode == AcErrorCode.WrongLoginData);
|
||||
#endregion Wrong email test
|
||||
|
||||
#region Wrong password test
|
||||
loggedInModel = loginService.Login(LoginEmail, "fsdgfsdg");
|
||||
|
||||
Assert.IsNotNull(loggedInModel);
|
||||
Assert.IsFalse(loggedInModel.IsLoggedIn);
|
||||
Assert.IsTrue(loggedInModel.LoginErrorCode == AcErrorCode.WrongLoginData);
|
||||
#endregion Wrong password test
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
});
|
||||
}
|
||||
|
||||
public Task<bool> RemoveUserAsync(User user) => TransactionAsync(ctx => ctx.RemoveUserAsync(user));
|
||||
public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx => ctx.RemoveUserAsync(userId));
|
||||
public Task<bool> RemoveUserAsync(User user) => TransactionAsync(ctx => ctx.RemoveUser(user));
|
||||
public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx => ctx.RemoveUser(userId));
|
||||
|
||||
public Product? GetProductById(Guid contextId, bool includeUsers = true) => Session(ctx => ctx.GetProductById(contextId, includeUsers));
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
public bool CreateProductAsync(Product product)
|
||||
{
|
||||
Context.CreateProduct(product);
|
||||
Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}");
|
||||
Console.WriteLine($@"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}");
|
||||
var result = Context.SaveChangesAsync();
|
||||
return result.Result > 0;
|
||||
}
|
||||
|
|
@ -236,7 +236,7 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
|
||||
public virtual Task<TiamServiceProvider?> GetServiceProviderByIdAsync(Guid id)
|
||||
{
|
||||
Console.WriteLine($"Getting serviceProvider from db {id}");
|
||||
Console.WriteLine($@"Getting serviceProvider from db {id}");
|
||||
return Context.ServiceProviders.SingleOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
|
|
@ -449,7 +449,7 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
}
|
||||
foreach (var row in result)
|
||||
{
|
||||
Console.WriteLine($"GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}");
|
||||
Console.WriteLine($@"GetPermissionsOfUserProductMappingsAndGroupsAsyncByContextId: {row.ContextId}, {row.SubjectId}, {row.SubjectType}, {row.Name}, {row.PermissionsValue}");
|
||||
}
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,14 +40,14 @@ namespace TIAM.Database.DataLayers.Users
|
|||
|
||||
public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber)
|
||||
{
|
||||
Console.WriteLine($"Getting user from db {phoneNumber}");
|
||||
Console.WriteLine($@"Getting user from db {phoneNumber}");
|
||||
var phoneNumberLower = phoneNumber.ToLower();
|
||||
return Context.Users.SingleOrDefaultAsync(x=>x.PhoneNumber.Equals(phoneNumberLower, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public Task<User?> GetUserByEmailOrPhoneNumberAsync(string emailOrPhoneNumber)
|
||||
{
|
||||
Console.WriteLine($"Getting user from db {emailOrPhoneNumber}");
|
||||
Console.WriteLine($@"Getting user from db {emailOrPhoneNumber}");
|
||||
var emailOrPhoneNumberLower = emailOrPhoneNumber.ToLower();
|
||||
return Context.Users.SingleOrDefaultAsync(x=>x.EmailAddress.Equals(emailOrPhoneNumberLower, StringComparison.CurrentCultureIgnoreCase) || x.PhoneNumber.Equals(emailOrPhoneNumberLower, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
|
|
@ -62,29 +62,11 @@ namespace TIAM.Database.DataLayers.Users
|
|||
public async Task<bool> CreateUserAsync(User user)
|
||||
{
|
||||
Context.Users.Add(user);
|
||||
Console.WriteLine($"Saving user to db {user.Id}, {user.EmailAddress}, {user.PhoneNumber}, {user.Password}");
|
||||
Console.WriteLine($@"Saving user to db {user.Id}, {user.EmailAddress}, {user.PhoneNumber}, {user.Password}");
|
||||
return await Context.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateJwtRefreshTokenAsync(string email, string refreshToken)
|
||||
{
|
||||
Console.WriteLine("UserDal Update refresh token");
|
||||
var existingUser = Context.Users.FirstOrDefault(u => u.EmailAddress == email);
|
||||
if (existingUser != null)
|
||||
{
|
||||
//user.Modified = DateTime.UtcNow; //ezt nem kell megadni, a háttérben ezt magától megcsinálja a DbContextBase - J.
|
||||
existingUser.RefreshToken = refreshToken;
|
||||
|
||||
Context.Users.Update(existingUser);
|
||||
return await Context.SaveChangesAsync() > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("User not found");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserAsync(User user)
|
||||
{
|
||||
var existingUser = await Context.Users.CountAsync(u => u.EmailAddress == user.EmailAddress);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace TIAMWebApp.Client.Services
|
|||
return result as TModelType;
|
||||
|
||||
case "TransferWizardModel":
|
||||
Console.WriteLine("TransferWizardModel");
|
||||
Console.WriteLine(@"TransferWizardModel");
|
||||
var transferResult = await TransferDataService.CreateTransfer((TransferWizardModel)data);
|
||||
return transferResult as TModelType;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ using System.Text;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Database.DataLayers.Users;
|
||||
using AyCode.Utils.Helpers;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models;
|
||||
using TIAMWebApp.Shared.Application.Utility;
|
||||
|
|
@ -66,7 +65,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
if (SerializedMessageSenderModel.MessageType == MessageTypesEnum.email && SerializedMessageSenderModel.Message is EmailMessage)
|
||||
{
|
||||
|
||||
Console.WriteLine($"EmailMessage!!!");
|
||||
Console.WriteLine($@"EmailMessage!!!");
|
||||
|
||||
var result = await _messageSenderService.SendMessageAsync(SerializedMessageSenderModel.Message, (int)SerializedMessageSenderModel.MessageType);
|
||||
//_adminDal.AddEmailMessageAsync((TIAM.Entities.Emails.EmailMessage)SerializedMessageSenderModel.Message);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.UploadImageRouteName)]
|
||||
public ActionResult UploadImage([FromForm] IFormFile file)
|
||||
{
|
||||
Console.WriteLine($"Upload file called: {file.FileName}");
|
||||
Console.WriteLine($@"Upload file called: {file.FileName}");
|
||||
if (file == null || file.Length == 0)
|
||||
return BadRequest("File not selected");
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[EndpointSummary("Create assigned user")]
|
||||
public async Task<IActionResult> CreateServiceProvider([FromBody] ServiceProviderModel serializedServiceProviderModel)
|
||||
{
|
||||
Console.WriteLine("CreateUser called");
|
||||
Console.WriteLine(@"CreateUser called");
|
||||
if (serializedServiceProviderModel == null)
|
||||
{
|
||||
return BadRequest("SerializedLoginModel is required");
|
||||
|
|
@ -72,7 +72,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
else
|
||||
{
|
||||
|
||||
Console.WriteLine($"ServiceProvider to be created: {id}, {name}, {ownerId}");
|
||||
Console.WriteLine($@"ServiceProvider to be created: {id}, {name}, {ownerId}");
|
||||
|
||||
await _adminDal.CreateServiceProviderAsync(new TiamServiceProvider(id, name, ownerId, Guid.NewGuid()));
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.GetServiceProviderByIdRouteName)]
|
||||
public async Task<TiamServiceProvider?> GetServiceProviderById([FromBody] Guid id)
|
||||
{
|
||||
Console.WriteLine($"GetServiceProviderById called with id: {id}");
|
||||
Console.WriteLine($@"GetServiceProviderById called with id: {id}");
|
||||
|
||||
return await _adminDal.GetServiceProviderByIdAsync(id);
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("Finished", "ServiceProvider")]
|
||||
public async Task<Dictionary<Guid, string>> GetServiceProvidersByOwnerId([FromBody] Guid ownerId)
|
||||
{
|
||||
Console.WriteLine($"GetServiceProvidersByOwnerId called with ownerId: {ownerId}");
|
||||
Console.WriteLine($@"GetServiceProvidersByOwnerId called with ownerId: {ownerId}");
|
||||
|
||||
var serviceProviders = await _adminDal.GetServiceProvidersAsync();
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
||||
Console.WriteLine($@"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
||||
|
||||
var userProductMapping = new UserProductMapping(createUserProductMappingModel.ContextId, createUserProductMappingModel.ContextId);
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.GetUserProductMappingsForProductRouteName)]
|
||||
public async Task<Dictionary<Guid, string>> GetUserProductMappingsForProduct(Guid serviceProviderId)
|
||||
{
|
||||
Console.WriteLine($"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
||||
Console.WriteLine($@"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
||||
|
||||
var userProductMappingDictionary = new Dictionary<Guid, string>();
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("In-Progress", "Product")]
|
||||
public async Task<IActionResult> AddProduct([FromBody] Product product)
|
||||
{
|
||||
Console.WriteLine("AddProduct called");
|
||||
Console.WriteLine(@"AddProduct called");
|
||||
if (product == null)
|
||||
{
|
||||
return BadRequest("Product is required");
|
||||
|
|
@ -183,11 +183,11 @@ namespace TIAMWebApp.Server.Controllers
|
|||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.GetQRCodeByProductIdRouteName)]
|
||||
[Route(APIUrls.GetQrCodeByProductIdRouteName)]
|
||||
[Tags("In-Progress", "Product")]
|
||||
public async Task<IActionResult> GetQRCodeByProductId([FromBody] Guid productId)
|
||||
{
|
||||
Console.WriteLine("GetQRCode called");
|
||||
Console.WriteLine(@"GetQRCode called");
|
||||
if (productId == Guid.Empty)
|
||||
{
|
||||
return BadRequest("Product is required");
|
||||
|
|
@ -202,7 +202,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
//Bitmap qrCodeImage = qrCode.GetGraphic(20);
|
||||
var rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "assets");
|
||||
var qrCodeImage = qrCode.GetGraphic(20, Color.DarkMagenta, Color.White, (Bitmap)Bitmap.FromFile(rootpath + "/myimage.png"));
|
||||
Console.WriteLine($"qrCodeLogo: {rootpath}/myimage.png");
|
||||
Console.WriteLine($@"qrCodeLogo: {rootpath}/myimage.png");
|
||||
var ms = new MemoryStream();
|
||||
qrCodeImage.Save(ms, ImageFormat.Jpeg);
|
||||
var byteImage = ms.ToArray();
|
||||
|
|
@ -219,7 +219,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("In-Progress", "Product")]
|
||||
public IActionResult GetProductsByServiceProviderId([FromBody] Guid serviceProviderId)
|
||||
{
|
||||
Console.WriteLine($"GetProductsByServiceProviderId called with serviceProviderId: {serviceProviderId}");
|
||||
Console.WriteLine($@"GetProductsByServiceProviderId called with serviceProviderId: {serviceProviderId}");
|
||||
|
||||
if (serviceProviderId == Guid.Empty)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.CreateTransferDestinationRouteName)]
|
||||
public async Task<IActionResult> CreateTransferDestination([FromBody] JsonElement serializedTransferDestinationModel)
|
||||
{
|
||||
Console.WriteLine("CreateTransferDestination called!");
|
||||
Console.WriteLine(@"CreateTransferDestination called!");
|
||||
if (string.IsNullOrEmpty(serializedTransferDestinationModel.GetRawText()))
|
||||
{
|
||||
return BadRequest("SerializedTramsferDestinationWizardModel is required");
|
||||
|
|
@ -108,16 +108,16 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"TransferDestination to be created: {id}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressId}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Name}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price2}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price3}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.ExtraPrice}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {id}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.AddressId}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.Name}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.Price}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.Price2}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.Price3}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.ExtraPrice}");
|
||||
//Console.WriteLine($"TransferDestination to be created: {transferDestination.ExtraPriceType}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressString}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transferDestination.Description}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.AddressString}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transferDestination.Description}");
|
||||
|
||||
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
|
||||
await _adminDal.AddTransferDestinationAsync(transferDestination);
|
||||
|
|
@ -140,18 +140,18 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.UpdateTransferDestinationRouteName)]
|
||||
public async Task<IActionResult> UpdateTransferDestination([FromBody]JsonElement serializedTransferDestination)
|
||||
{
|
||||
Console.WriteLine("UpdateTransferDestination called!");
|
||||
Console.WriteLine(@"UpdateTransferDestination called!");
|
||||
if (string.IsNullOrEmpty(serializedTransferDestination.GetRawText()))
|
||||
{
|
||||
Console.WriteLine("Bad request!");
|
||||
Console.WriteLine(@"Bad request!");
|
||||
return BadRequest("SerializedTramsferDestinationWizardModel is required");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Serialized model not empty!");
|
||||
Console.WriteLine(@"Serialized model not empty!");
|
||||
TransferDestination? transferDestination = JObject.Parse(serializedTransferDestination.GetRawText()).ToObject<TransferDestination>();
|
||||
Console.WriteLine($"TransferDestination to be updated: {serializedTransferDestination.GetRawText()}");
|
||||
Console.WriteLine($"TransferDestination to be updated: {transferDestination.AddressString}");
|
||||
Console.WriteLine($@"TransferDestination to be updated: {serializedTransferDestination.GetRawText()}");
|
||||
Console.WriteLine($@"TransferDestination to be updated: {transferDestination.AddressString}");
|
||||
|
||||
|
||||
if (transferDestination != null)
|
||||
|
|
@ -162,20 +162,20 @@ namespace TIAMWebApp.Server.Controllers
|
|||
|
||||
if (transferDestination.Id == Guid.Empty || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString))
|
||||
{
|
||||
Console.WriteLine("Serialized model not empty, but bad request!");
|
||||
Console.WriteLine(@"Serialized model not empty, but bad request!");
|
||||
return BadRequest("Invalid request");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Console.WriteLine($"TransferDestination to be updated: {transferDestination.Id}");
|
||||
Console.WriteLine($"TransferDestination to be updated new name: {transferDestination.Name}");
|
||||
Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price}");
|
||||
Console.WriteLine($@"TransferDestination to be updated: {transferDestination.Id}");
|
||||
Console.WriteLine($@"TransferDestination to be updated new name: {transferDestination.Name}");
|
||||
Console.WriteLine($@"TransferDestination to be updated new price: {transferDestination.Price}");
|
||||
//Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price2}");
|
||||
//Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price3}");
|
||||
//Console.WriteLine($"TransferDestination to be updated new priceType: {transferDestination.PriceType}");
|
||||
Console.WriteLine($"TransferDestination to be updated new address: {transferDestination.AddressString}");
|
||||
Console.WriteLine($"TransferDestination to be updated new description: {transferDestination.Description}");
|
||||
Console.WriteLine($@"TransferDestination to be updated new address: {transferDestination.AddressString}");
|
||||
Console.WriteLine($@"TransferDestination to be updated new description: {transferDestination.Description}");
|
||||
|
||||
//var dbTransferDestinationJson = _adminDal.GetTransferDestinationJsonById(transferDestination.Id);
|
||||
//Console.WriteLine($"TransferDestination JSON to be updated: {dbTransferDestinationJson}");
|
||||
|
|
@ -216,7 +216,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.CreateTransferRouteName)]
|
||||
public async Task<IActionResult> CreateTransfer([FromBody] JsonElement serializedTransferModel)
|
||||
{
|
||||
Console.WriteLine("CreateTransfer called!");
|
||||
Console.WriteLine(@"CreateTransfer called!");
|
||||
if (string.IsNullOrEmpty(serializedTransferModel.GetRawText()))
|
||||
{
|
||||
return BadRequest("SerializedTramsferDestinationWizardModel is required");
|
||||
|
|
@ -238,11 +238,11 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"TransferDestination to be created: {id}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transfer.FromAddress}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transfer.ToAddress}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transfer.ProductId}");
|
||||
Console.WriteLine($"TransferDestination to be created: {transfer.Price}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {id}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transfer.FromAddress}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transfer.ToAddress}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transfer.ProductId}");
|
||||
Console.WriteLine($@"TransferDestination to be created: {transfer.Price}");
|
||||
|
||||
var from = await _adminDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.AddressString == transfer.FromAddress);
|
||||
var to = await _adminDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.AddressString == transfer.ToAddress);
|
||||
|
|
@ -273,14 +273,14 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.CreateTransfersRouteName)]
|
||||
public async Task<IActionResult> CreateTransfers([FromBody] JsonElement serializedTransferModel)
|
||||
{
|
||||
Console.WriteLine("CreateTransfers called!");
|
||||
Console.WriteLine(@"CreateTransfers called!");
|
||||
if (string.IsNullOrEmpty(serializedTransferModel.GetRawText()))
|
||||
{
|
||||
return BadRequest("SerializedTramsferDestinationWizardModel is required");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Serialized model: {serializedTransferModel.GetRawText()}");
|
||||
Console.WriteLine($@"Serialized model: {serializedTransferModel.GetRawText()}");
|
||||
|
||||
var settings = new JsonSerializerSettings
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,15 +18,16 @@ using AyCode.Core.Logger;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Database.DataLayers.Users;
|
||||
using AyCode.Utils.Helpers;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAM.Models.Dtos.Users;
|
||||
using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models;
|
||||
using TIAMWebApp.Shared.Application.Utility;
|
||||
using TIAM.Database.DataLayers.Admins;
|
||||
using System;
|
||||
using AyCode.Core.Helpers;
|
||||
using TIAM.Entities.Profiles;
|
||||
using TIAM.Entities.Addresses;
|
||||
using TIAMWebApp.Server.Services.Logins;
|
||||
|
||||
namespace TIAMWebApp.Server.Controllers
|
||||
{
|
||||
|
|
@ -35,6 +36,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route("api/v1/[controller]")]
|
||||
public class UserAPIController : ControllerBase
|
||||
{
|
||||
private LoginService _loginService;
|
||||
private UserDal _userDal;
|
||||
private AdminDal _adminDal;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
|
@ -58,105 +60,54 @@ namespace TIAMWebApp.Server.Controllers
|
|||
_webHostEnvironment = webHostEnvironment;
|
||||
_userDal = userDal;
|
||||
_adminDal = adminDal;
|
||||
|
||||
_loginService = new LoginService(_userDal, _configuration);
|
||||
}
|
||||
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.AuthenticateUserRouteName)]
|
||||
public async Task<IActionResult> AuthenticateUser([FromBody] JsonElement SerializedLoginModel)
|
||||
[Route(APIUrls.LogoutUserRouteName)]
|
||||
public IActionResult LogoutUser()
|
||||
{
|
||||
Console.WriteLine("AuthenticateUser called");
|
||||
var authenticateUser = JObject.Parse(SerializedLoginModel.GetRawText()).ToObject<LoginModel>();
|
||||
_loginService.Logout();
|
||||
|
||||
//check if userModel exists
|
||||
//var userModel = await _userManager.FindByNameAsync(authenticateUser.UserName);
|
||||
//if (userModel == null) return Unauthorized();
|
||||
Console.WriteLine(authenticateUser.Email);
|
||||
|
||||
//var dbUser = await GetUserByEmail(authenticateUser.Email);
|
||||
var dbUser = await _userDal.GetUserByEmailAsync(authenticateUser.Email);
|
||||
|
||||
//check if password is valid
|
||||
//bool isValidUser = await _userManager.CheckPasswordAsync(userModel, authenticateUser.Password);
|
||||
|
||||
//mocking
|
||||
if (dbUser is null)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
else
|
||||
{
|
||||
var isValidUser = false;
|
||||
|
||||
if (dbUser.Password == authenticateUser.Password)
|
||||
{
|
||||
Console.WriteLine("Password is valid");
|
||||
isValidUser = true;
|
||||
|
||||
}
|
||||
|
||||
if (isValidUser)
|
||||
{
|
||||
Console.WriteLine("UserModel authenticated, let's start JWT");
|
||||
var accessToken = GenerateAccessToken(dbUser);
|
||||
Console.WriteLine("Generate refresh token");
|
||||
var refreshToken = GenerateRefreshToken();
|
||||
dbUser.RefreshToken = refreshToken;
|
||||
//Update userModel with refreshToken!!
|
||||
await _userDal.UpdateJwtRefreshTokenAsync(dbUser.EmailAddress, dbUser.RefreshToken);
|
||||
|
||||
var response = new MainResponse
|
||||
{
|
||||
Content = new AuthenticationResponse
|
||||
{
|
||||
RefreshToken = refreshToken,
|
||||
AccessToken = accessToken
|
||||
},
|
||||
IsSuccess = true,
|
||||
ErrorMessage = ""
|
||||
};
|
||||
return Ok(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("User not valid");
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
//TODO: Implementálni a Logout-ot kliens és szerver oldalon is! - J.
|
||||
return new RedirectToActionResult(APIUrls.BaseUrlWithSlashAndVersion, null, null);
|
||||
}
|
||||
|
||||
private string GenerateAccessToken(User user)
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.AuthenticateUserRouteName)]
|
||||
public async Task<IActionResult> AuthenticateUser([FromBody] JsonElement serializedLoginModel)
|
||||
{
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
Console.WriteLine("----------------------------------------------------------");
|
||||
Console.WriteLine(@"AuthenticateUser called");
|
||||
var authenticateUser = JObject.Parse(serializedLoginModel.GetRawText()).ToObject<LoginModel>();
|
||||
|
||||
if (_configuration["JWT:Key"] == null)
|
||||
throw new SecurityTokenException("Token is null");
|
||||
if (authenticateUser == null) throw new NullReferenceException("authenticateUser == null");
|
||||
|
||||
var keyDetail = Encoding.UTF8.GetBytes(_configuration["JWT:Key"] ?? string.Empty);
|
||||
Console.WriteLine(_configuration["JWT:Key"]);
|
||||
Console.WriteLine(authenticateUser.Email);
|
||||
|
||||
var claims = new List<Claim>
|
||||
var loggedInModel = _loginService.Login(authenticateUser.Email, authenticateUser.Password);
|
||||
if (loggedInModel.IsLoggedIn)
|
||||
{
|
||||
new(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||
new(ClaimTypes.Email, user.EmailAddress)
|
||||
};
|
||||
var response = new MainResponse
|
||||
{
|
||||
Content = new AuthenticationResponse
|
||||
{
|
||||
RefreshToken = loggedInModel.AccessToken,
|
||||
AccessToken = loggedInModel.LoggedInUser.RefreshToken
|
||||
},
|
||||
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Audience = _configuration["JWT:Audience"],
|
||||
Issuer = _configuration["JWT:Issuer"],
|
||||
Expires = DateTime.UtcNow.AddMinutes(30),
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(keyDetail), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
IsSuccess = true,
|
||||
ErrorMessage = ""
|
||||
};
|
||||
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor) as JwtSecurityToken;
|
||||
var writtenToken = tokenHandler.WriteToken(token);
|
||||
Console.WriteLine(writtenToken);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
return writtenToken;
|
||||
Console.WriteLine(@"User not valid! errorCode: " + loggedInModel.LoginErrorCode);
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
@ -164,21 +115,21 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.RefreshTokenRouteName)]
|
||||
public async Task<IActionResult> RefreshToken(RefreshTokenRequest? refreshTokenRequest)
|
||||
{
|
||||
Console.WriteLine("RefreshToken called");
|
||||
Console.WriteLine(@"RefreshToken called");
|
||||
|
||||
var response = new MainResponse();
|
||||
if (refreshTokenRequest is null)
|
||||
{
|
||||
Console.WriteLine("RefreshTokenRequest is null");
|
||||
Console.WriteLine(@"RefreshTokenRequest is null");
|
||||
response.ErrorMessage = "Invalid request";
|
||||
return BadRequest(response);
|
||||
}
|
||||
|
||||
var principal = GetPrincipalFromExpiredToken(refreshTokenRequest.AccessToken);
|
||||
var principal = _loginService.GetPrincipalFromExpiredToken(refreshTokenRequest.AccessToken);
|
||||
|
||||
if (principal != null)
|
||||
{
|
||||
Console.WriteLine("Principal is not null");
|
||||
Console.WriteLine(@"Principal is not null");
|
||||
var email = principal.Claims.FirstOrDefault(f => f.Type == ClaimTypes.Email);
|
||||
|
||||
//var userModel = await _userManager.FindByEmailAsync(email?.Value);
|
||||
|
|
@ -189,7 +140,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
{
|
||||
//get user from db
|
||||
dbUser = await _userDal.GetUserByEmailAsync(email.Value);
|
||||
Console.WriteLine("DbUser email: " + dbUser?.EmailAddress);
|
||||
Console.WriteLine($@"DbUser email: {dbUser?.EmailAddress}");
|
||||
}
|
||||
|
||||
//mocking - update userModel with new refreshToken so it returns true after the check below
|
||||
|
|
@ -198,12 +149,12 @@ namespace TIAMWebApp.Server.Controllers
|
|||
if (dbUser is null || dbUser.RefreshToken != refreshTokenRequest.RefreshToken)
|
||||
{
|
||||
response.ErrorMessage = "Invalid Request";
|
||||
Console.WriteLine($"{dbUser?.RefreshToken}, {refreshTokenRequest.RefreshToken}");
|
||||
Console.WriteLine($@"{dbUser?.RefreshToken}, {refreshTokenRequest.RefreshToken}");
|
||||
return BadRequest(response);
|
||||
}
|
||||
|
||||
var newAccessToken = GenerateAccessToken(dbUser);
|
||||
var refreshToken = GenerateRefreshToken();
|
||||
var newAccessToken = _loginService.GenerateAccessToken(dbUser);
|
||||
var refreshToken = _loginService.GenerateRefreshToken();
|
||||
|
||||
//mocking - update userModel with new refreshToken
|
||||
dbUser.RefreshToken = refreshToken;
|
||||
|
|
@ -220,56 +171,16 @@ namespace TIAMWebApp.Server.Controllers
|
|||
return Ok(response);
|
||||
}
|
||||
|
||||
Console.WriteLine("Principal is null");
|
||||
Console.WriteLine(@"Principal is null");
|
||||
return NotFound("Invalid Token Found");
|
||||
}
|
||||
|
||||
private ClaimsPrincipal GetPrincipalFromExpiredToken(string token)
|
||||
{
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
|
||||
if (_configuration["JWT:Key"] == null)
|
||||
throw new SecurityTokenException("Token is null");
|
||||
|
||||
var keyDetail = Encoding.UTF8.GetBytes(_configuration["JWT:Key"] ?? string.Empty);
|
||||
|
||||
var tokenValidationParameter = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false,
|
||||
ValidateLifetime = false,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = _configuration["JWT:Issuer"],
|
||||
ValidAudience = _configuration["JWT:Audience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(keyDetail),
|
||||
};
|
||||
|
||||
var principal = tokenHandler.ValidateToken(token, tokenValidationParameter, out var securityToken);
|
||||
|
||||
if (securityToken is not JwtSecurityToken jwtSecurityToken || !jwtSecurityToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha256, StringComparison.InvariantCultureIgnoreCase))
|
||||
throw new SecurityTokenException("Invalid token");
|
||||
|
||||
return principal;
|
||||
}
|
||||
|
||||
private string GenerateRefreshToken()
|
||||
{
|
||||
|
||||
var randomNumber = new byte[32];
|
||||
using (var rng = RandomNumberGenerator.Create())
|
||||
{
|
||||
rng.GetBytes(randomNumber);
|
||||
return Convert.ToBase64String(randomNumber);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route("CreateUser")]
|
||||
public async Task<IActionResult> CreateUser([FromBody] JsonElement SerializedRegistrationModel)
|
||||
{
|
||||
Console.WriteLine("CreateUser called");
|
||||
Console.WriteLine(@"CreateUser called");
|
||||
|
||||
if (string.IsNullOrEmpty(SerializedRegistrationModel.GetRawText()))
|
||||
{
|
||||
|
|
@ -297,10 +208,10 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"User to be created: {userId}");
|
||||
Console.WriteLine($"User to be created: {email}");
|
||||
Console.WriteLine($"User to be created: {phoneNumber}");
|
||||
Console.WriteLine($"User to be created: {password}");
|
||||
Console.WriteLine($@"User to be created: {userId}");
|
||||
Console.WriteLine($@"User to be created: {email}");
|
||||
Console.WriteLine($@"User to be created: {phoneNumber}");
|
||||
Console.WriteLine($@"User to be created: {password}");
|
||||
|
||||
await _userDal.CreateUserAsync(new User(userId, email, phoneNumber, password));
|
||||
}
|
||||
|
|
@ -315,7 +226,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.CreateGuestUserRouteName)]
|
||||
public async Task<IActionResult> CreateGuestUser([FromBody] JsonElement SerializedRegistrationModel)
|
||||
{
|
||||
Console.WriteLine("CreateGuestUser called");
|
||||
Console.WriteLine(@"CreateGuestUser called");
|
||||
bool result = false;
|
||||
UserModelDtoDetail? guestUser = null;
|
||||
|
||||
|
|
@ -347,10 +258,10 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"User to be created: {userId}");
|
||||
Console.WriteLine($"User to be created: {email}");
|
||||
Console.WriteLine($"User to be created: {phoneNumber}");
|
||||
Console.WriteLine($"User to be created: {password}");
|
||||
Console.WriteLine($@"User to be created: {userId}");
|
||||
Console.WriteLine($@"User to be created: {email}");
|
||||
Console.WriteLine($@"User to be created: {phoneNumber}");
|
||||
Console.WriteLine($@"User to be created: {password}");
|
||||
User userToCreate = new(userId, email, phoneNumber, password);
|
||||
userToCreate.ProfileId = Guid.NewGuid();
|
||||
|
||||
|
|
@ -391,7 +302,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
public Task<UserModelDto?> GetUserByEmail(string email)
|
||||
{
|
||||
Logger.Info($"GetUserByEmail called with email: {email}");
|
||||
Console.WriteLine($"GetUserByEmail called with email: {email}");
|
||||
Console.WriteLine($@"GetUserByEmail called with email: {email}");
|
||||
return _userDal.GetUserModelDtoByEmailAsync(email);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"GetPermissionContextByUserId called with userId: {userId}");
|
||||
Console.WriteLine($@"GetPermissionContextByUserId called with userId: {userId}");
|
||||
//List<AssignedPermissionModel> response = await _serviceProviderDal.GetPermissionModelByUserIdAsync(userId);
|
||||
//return Ok(response);
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
else
|
||||
{
|
||||
|
||||
Console.WriteLine($"GetPermissionsForContextByContextId called with contextId: {contextId}");
|
||||
Console.WriteLine($@"GetPermissionsForContextByContextId called with contextId: {contextId}");
|
||||
Dictionary<Guid, int> permissionsDictionary = new Dictionary<Guid, int>();
|
||||
var permissions = await _adminDal.GetPermissionsForContextByContextIdAsync(contextId);
|
||||
return Ok(permissions);
|
||||
|
|
@ -82,7 +82,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route("AssignPermissionToUserForContext")]
|
||||
public async Task<IActionResult> AssignPermissionToUserForContext(AssignPermissionModel assignPermissionModel)
|
||||
{
|
||||
Console.WriteLine("AssignPermissionToUserForContext called");
|
||||
Console.WriteLine(@"AssignPermissionToUserForContext called");
|
||||
if (assignPermissionModel == null)
|
||||
{
|
||||
return BadRequest("ContextId and UserId are required");
|
||||
|
|
@ -116,7 +116,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route("CreatePermissionType")]
|
||||
public async Task<IActionResult> CreatePermissionType(string name, Guid contextId)
|
||||
{
|
||||
Console.WriteLine("CreatePermissionType called");
|
||||
Console.WriteLine(@"CreatePermissionType called");
|
||||
if (String.IsNullOrEmpty(name) || contextId == Guid.Empty)
|
||||
{
|
||||
return BadRequest("SerializedPermissionTypeModel is required");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
using AyCode.Models.Server.Logins;
|
||||
using TIAM.Entities.Addresses;
|
||||
using TIAM.Entities.Profiles;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAMWebApp.Server.Services.Logins;
|
||||
|
||||
namespace TIAMWebApp.Server.Models.Logins;
|
||||
|
||||
public class LoggedInModel : AcLoggedInModelServer<LoggedInModel, User, UserToken, Profile, TiamServiceProvider, UserToServiceProvider, Address>, ILoginModel
|
||||
{
|
||||
}
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
using AyCode.Interfaces.Server.Logins;
|
||||
using AyCode.Models.Logins;
|
||||
using AyCode.Models.Server.Logins;
|
||||
using TIAM.Entities.Addresses;
|
||||
using TIAM.Entities.Profiles;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAMWebApp.Server.Models.Logins;
|
||||
|
||||
namespace TIAMWebApp.Server.Services.Logins;
|
||||
|
||||
public interface ILoginModel : IAcLoggedInModelBase<User, Profile, TiamServiceProvider, UserToServiceProvider, Address>
|
||||
public interface ILoginModel : IAcLoggedInModelBase<User, UserToken, Profile, TiamServiceProvider, UserToServiceProvider, Address>
|
||||
{}
|
||||
|
||||
public interface ILoginService : IAcLoginServiceServer<User, UserToken, Profile, TiamServiceProvider, UserToServiceProvider, Address>
|
||||
public interface ILoginService : IAcLoginServiceServer<LoggedInModel, User, UserToken, Profile, TiamServiceProvider, UserToServiceProvider, Address>
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -2,10 +2,8 @@
|
|||
using System.Security;
|
||||
using AyCode.Core.Consts;
|
||||
using AyCode.Interfaces.Server.Logins;
|
||||
using AyCode.Models.Server.Logins;
|
||||
using AyCode.Services.Server.Logins;
|
||||
using AyCode.Utils.Extensions;
|
||||
using AyCode.Utils.Helpers;
|
||||
using TIAM.Database.DataLayers.Admins;
|
||||
using TIAM.Database.DataLayers.Users;
|
||||
using TIAM.Database.DbContexts.Admins;
|
||||
|
|
@ -14,18 +12,16 @@ using TIAM.Entities.Addresses;
|
|||
using TIAM.Entities.Profiles;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAMWebApp.Server.Models.Logins;
|
||||
|
||||
namespace TIAMWebApp.Server.Services.Logins;
|
||||
|
||||
public class LoggedInModel : AcLoggedInModelServer<User, Profile, TiamServiceProvider, UserToServiceProvider, Address>, ILoginModel
|
||||
{}
|
||||
|
||||
public class LoginService(UserDal userDal, IConfiguration configuration) : AcLoginServiceServer<LoggedInModel, UserDal, UserDbContext, User, UserToken, Profile, TiamServiceProvider, UserToServiceProvider, Address>(userDal, configuration), ILoginService
|
||||
|
||||
{
|
||||
public override User? Login(string email, string password, out string accessToken)
|
||||
public override LoggedInModel Login(string? email, string? password)
|
||||
{
|
||||
return base.Login(email, password, out accessToken);
|
||||
return base.Login(email, password);
|
||||
}
|
||||
|
||||
public override bool Logout()
|
||||
|
|
@ -33,14 +29,9 @@ public class LoginService(UserDal userDal, IConfiguration configuration) : AcLog
|
|||
return base.Logout();
|
||||
}
|
||||
|
||||
public override Task<User?> RegistrationAsync(string email, string password, string? phoneNumber = null)
|
||||
public override Task<AcErrorCode> RegistrationAsync(string email, string password, string? phoneNumber = null)
|
||||
{
|
||||
return base.RegistrationAsync(email, password, phoneNumber);
|
||||
}
|
||||
|
||||
public override string GenerateDynamicSalt(Guid userId)
|
||||
{
|
||||
return base.GenerateDynamicSalt(userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ namespace TIAMWebApp.Server.Services
|
|||
case (int)MessageTypesEnum.email:
|
||||
if (message is EmailMessage emailMessage)
|
||||
{
|
||||
Console.WriteLine($"EmailMessage!!!");
|
||||
Console.WriteLine($@"EmailMessage!!!");
|
||||
// Access DerivedClass properties
|
||||
var _subject = emailMessage.Subject;
|
||||
result = await SendMailWithSendgrid(emailMessage);
|
||||
|
|
@ -60,8 +60,8 @@ namespace TIAMWebApp.Server.Services
|
|||
|
||||
public async Task<string> SendMailWithSendgrid(EmailMessage message)
|
||||
{
|
||||
Console.WriteLine($"Sender: {message.SenderId}");
|
||||
Console.WriteLine($"Message: {message.Message}");
|
||||
Console.WriteLine($@"Sender: {message.SenderId}");
|
||||
Console.WriteLine($@"Message: {message.Message}");
|
||||
//resolve user!!!
|
||||
var senderUser = _userDal.Context.Users.FirstOrDefault(x => x.Id == message.SenderId);
|
||||
var receiverUser = _userDal.Context.Users.FirstOrDefault(x => x.Id == message.ReceiverId);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ namespace TIAMWebApp.Shared.Application.Models
|
|||
|
||||
public const string AuthenticateUserRouteName = "AuthenticateUser";
|
||||
public const string AuthenticateUser = UserAPI + AuthenticateUserRouteName;
|
||||
|
||||
|
||||
public const string LogoutUserRouteName = "LogoutUser";
|
||||
public const string LogoutUser = UserAPI + LogoutUserRouteName;
|
||||
|
||||
public const string CreateUserRouteName = "CreateUser";
|
||||
public const string CreateUser = UserAPI + CreateUserRouteName;
|
||||
|
||||
|
|
@ -92,8 +95,8 @@ namespace TIAMWebApp.Shared.Application.Models
|
|||
public const string GetServiceProvidersByOwnerIdRouteName = "GetServiceProvidersByOwnerId";
|
||||
public const string GetServiceProvidersByOwnerId = ServiceProviderAPI+GetServiceProvidersByOwnerIdRouteName;
|
||||
|
||||
public const string GetQRCodeByProductIdRouteName = "GetQRCodeByProductId";
|
||||
public const string GetQRCodeByProductId = ServiceProviderAPI+GetQRCodeByProductIdRouteName;
|
||||
public const string GetQrCodeByProductIdRouteName = "GetQRCodeByProductId";
|
||||
public const string GetQrCodeByProductId = ServiceProviderAPI+GetQrCodeByProductIdRouteName;
|
||||
|
||||
public const string AddProductRouteName = "AddProduct";
|
||||
public const string AddProductRouteUrl = ServiceProviderAPI + AddProductRouteName;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ namespace TIAMWebApp.Shared.Application.Services
|
|||
{
|
||||
|
||||
|
||||
var url = APIUrls.GetQRCodeByProductId;
|
||||
var url = APIUrls.GetQrCodeByProductId;
|
||||
var response = await http.PostAsJsonAsync(url, productId);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="NewFolder\**" />
|
||||
<EmbeddedResource Remove="NewFolder\**" />
|
||||
<None Remove="NewFolder\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
|
|
@ -13,7 +19,6 @@
|
|||
<ItemGroup>
|
||||
<Folder Include="Models\DTO\" />
|
||||
<Folder Include="Models\ServerSide\Messages\" />
|
||||
<Folder Include="NewFolder\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in New Issue