improvements, fixes, etc...

This commit is contained in:
jozsef.b@aycode.com 2024-04-24 17:58:43 +02:00
parent 3af9cb10e0
commit 7d0117f4dd
8 changed files with 56 additions and 66 deletions

View File

@ -236,7 +236,7 @@ namespace TIAM.Database.Test
NullValueHandling = NullValueHandling.Ignore NullValueHandling = NullValueHandling.Ignore
}; };
var userModel = Dal.GetUserModelDtoById(userId); var userModel = Dal.GetUserModelDtoById(userId, false);
var serializedUserModel = JsonConvert.SerializeObject(userModel, options); var serializedUserModel = JsonConvert.SerializeObject(userModel, options);
userModel = JsonConvert.DeserializeObject<UserModelDto>(serializedUserModel); userModel = JsonConvert.DeserializeObject<UserModelDto>(serializedUserModel);
@ -263,7 +263,7 @@ namespace TIAM.Database.Test
public void GetSerializedUserEntity_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString) public void GetSerializedUserEntity_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
{ {
var userId = Guid.Parse(userIdString); var userId = Guid.Parse(userIdString);
var userJson = Dal.GetUserJsonById(userId); var userJson = Dal.GetUserJsonById(userId, false);
Assert.IsFalse(userJson?.IsNullOrWhiteSpace()); Assert.IsFalse(userJson?.IsNullOrWhiteSpace());

View File

@ -60,7 +60,7 @@ namespace TIAM.Database.Test
Assert.IsTrue(errorCode == AcErrorCode.Unset); Assert.IsTrue(errorCode == AcErrorCode.Unset);
var user = Dal.GetUserByEmail(RegisterEmail); var user = Dal.GetUserByEmail(RegisterEmail, false);
Assert.IsNotNull(user); Assert.IsNotNull(user);
Assert.IsNotNull(user.Profile); Assert.IsNotNull(user.Profile);
@ -149,7 +149,7 @@ namespace TIAM.Database.Test
NullValueHandling = NullValueHandling.Ignore NullValueHandling = NullValueHandling.Ignore
}; };
var userModel = await Dal.GetUserModelDtoByIdAsync(userId).ConfigureAwait(false); var userModel = await Dal.GetUserModelDtoByIdAsync(userId, false).ConfigureAwait(false);
var serializedUserModel = JsonConvert.SerializeObject(userModel, options); var serializedUserModel = JsonConvert.SerializeObject(userModel, options);
userModel = JsonConvert.DeserializeObject<UserModelDto>(serializedUserModel); userModel = JsonConvert.DeserializeObject<UserModelDto>(serializedUserModel);
@ -200,7 +200,7 @@ namespace TIAM.Database.Test
user.Profile.Address = address; user.Profile.Address = address;
Assert.IsTrue(await Dal.AddUserAsync(user)); Assert.IsTrue(await Dal.AddUserAsync(user));
user = Dal.GetUserById(userId); user = Dal.GetUserById(userId, false);
Assert.IsNotNull(user); Assert.IsNotNull(user);
Assert.IsNotNull(user.Profile); Assert.IsNotNull(user.Profile);
@ -208,7 +208,7 @@ namespace TIAM.Database.Test
Assert.IsTrue(await Dal.RemoveUserAsync(userId)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J. Assert.IsTrue(await Dal.RemoveUserAsync(userId)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
user = Dal.GetUserById(userId); user = Dal.GetUserById(userId, false);
Assert.IsNull(user); //a korábbi törlés miatt NULL kell legyen - J. Assert.IsNull(user); //a korábbi törlés miatt NULL kell legyen - J.
} }
//[TestMethod] //[TestMethod]

View File

@ -90,15 +90,15 @@ namespace TIAM.Database.DataLayers.Admins
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude)); public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude));
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude)); public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude));
public UserModelDtoDetail? GetUserModelDtoDetailById(Guid userId) => Session(ctx => ctx.GetUserModelDtoDetailById(userId)); public UserModelDtoDetail? GetUserModelDtoDetailById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
public Task<UserModelDtoDetail?> GetUserModelDtoDetailByIdAsync(Guid userId) => SessionAsync(ctx => ctx.GetUserModelDtoDetailById(userId)); public Task<UserModelDtoDetail?> GetUserModelDtoDetailByIdAsync(Guid userId, bool onlyConfirmed) => SessionAsync(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
public UserModelDtoDetail? GetUserModelDtoDetailByEmail(string email) => Session(ctx => ctx.GetUserModelDtoDetailByEmail(email)); public UserModelDtoDetail? GetUserModelDtoDetailByEmail(string email, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailByEmail(email, onlyConfirmed));
public UserModelDto? GetUserModelDtoById(Guid userId) => Session(ctx => ctx.GetUserModelDtoById(userId)); public UserModelDto? GetUserModelDtoById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoById(userId, onlyConfirmed));
public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(ctx => ctx.GetUserModelDtoById(userId)); public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId, bool onlyConfirmed) => SessionAsync(ctx => ctx.GetUserModelDtoById(userId, onlyConfirmed));
public UserModelDto? GetUserModelDtoByEmail(string email) => Session(ctx => ctx.GetUserModelDtoByEmail(email)); public UserModelDto? GetUserModelDtoByEmail(string email, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoByEmail(email, onlyConfirmed));
public string? GetUserJsonById(Guid userId) => Session(ctx => ctx.GetUserById(userId)?.ToJson()); public string? GetUserJsonById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserById(userId, onlyConfirmed)?.ToJson());
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson()); public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
//public Task<bool> AddUserAsync(User user) => TransactionAsync(ctx => ctx.AddUser(user)); //public Task<bool> AddUserAsync(User user) => TransactionAsync(ctx => ctx.AddUser(user));

View File

@ -29,13 +29,13 @@ namespace TIAM.Database.DataLayers.Users
{ {
} }
public UserModelDtoDetail? GetUserModelDtoDetailById(Guid userId) => Session(ctx => ctx.GetUserModelDtoDetailById(userId)); public UserModelDtoDetail? GetUserModelDtoDetailById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
public Task<UserModelDtoDetail?> GetUserModelDtoDetailByIdAsync(Guid userId) => SessionAsync(ctx => ctx.GetUserModelDtoDetailById(userId)); public Task<UserModelDtoDetail?> GetUserModelDtoDetailByIdAsync(Guid userId, bool onlyConfirmed) => SessionAsync(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
public UserModelDtoDetail? GetUserModelDtoDetailByEmail(string email) => Session(ctx => ctx.GetUserModelDtoDetailByEmail(email)); public UserModelDtoDetail? GetUserModelDtoDetailByEmail(string email, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailByEmail(email, onlyConfirmed));
public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId)); public UserModelDto? GetUserModelDtoById(Guid userId, bool onlyConfirmed) => Session(x => x.GetUserModelDtoById(userId, onlyConfirmed));
public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId)); public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId, bool onlyConfirmed) => SessionAsync(x => x.GetUserModelDtoById(userId, onlyConfirmed));
public Task<UserModelDto?> GetUserModelDtoByEmailAsync(string email) => SessionAsync(x => x.GetUserModelDtoByEmail(email)); public Task<UserModelDto?> GetUserModelDtoByEmailAsync(string email, bool onlyConfirmed) => SessionAsync(x => x.GetUserModelDtoByEmail(email, onlyConfirmed));
public Task<List<UserModelDto>> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList()); public Task<List<UserModelDto>> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList());
public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber) public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber)

View File

@ -21,20 +21,20 @@ public static class UserDbSetExtensions
public static User? GetUserByEmail(this IUserDbSet ctx, string email, bool autoInclude) public static User? GetUserByEmail(this IUserDbSet ctx, string email, bool autoInclude)
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email); => ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email);
public static UserModelDto? GetUserModelDtoById(this IUserDbSet ctx, Guid userId) public static UserModelDto? GetUserModelDtoById(this IUserDbSet ctx, Guid userId, bool onlyConfirmed)
=> ctx.GetUsersById(userId).Select(user => new UserModelDto(user)).FirstOrDefault(); => ctx.GetUsersById(userId, onlyConfirmed).Select(user => new UserModelDto(user)).FirstOrDefault();
public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email) public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email, bool onlyConfirmed)
=> ctx.GetUsersByEmail(email).Select(user => new UserModelDto(user)).FirstOrDefault(); => ctx.GetUsersByEmail(email, onlyConfirmed).Select(user => new UserModelDto(user)).FirstOrDefault();
public static IQueryable<UserModelDto> GetAllUsersModelDto(this IUserDbSet ctx) public static IQueryable<UserModelDto> GetAllUsersModelDto(this IUserDbSet ctx)
=> ctx.Users.Select(user => new UserModelDto(user)); => ctx.Users.Select(user => new UserModelDto(user));
public static UserModelDtoDetail? GetUserModelDtoDetailById(this IUserDbSet ctx, Guid userId) public static UserModelDtoDetail? GetUserModelDtoDetailById(this IUserDbSet ctx, Guid userId, bool onlyConfirmed)
=> ctx.GetUsersById(userId).Select(user => new UserModelDtoDetail(user)).FirstOrDefault(); => ctx.GetUsersById(userId, onlyConfirmed).Select(user => new UserModelDtoDetail(user)).FirstOrDefault();
public static UserModelDtoDetail? GetUserModelDtoDetailByEmail(this IUserDbSet ctx, string email) public static UserModelDtoDetail? GetUserModelDtoDetailByEmail(this IUserDbSet ctx, string email, bool onlyConfirmed)
=> ctx.GetUsersByEmail(email).Select(user => new UserModelDtoDetail(user)).FirstOrDefault(); => ctx.GetUsersByEmail(email, onlyConfirmed).Select(user => new UserModelDtoDetail(user)).FirstOrDefault();
public static IQueryable<UserModelDtoDetail> GetAllUsersModelDetailDto(this IUserDbSet ctx) public static IQueryable<UserModelDtoDetail> GetAllUsersModelDetailDto(this IUserDbSet ctx)
=> ctx.Users.Select(user => new UserModelDtoDetail(user)); => ctx.Users.Select(user => new UserModelDtoDetail(user));

View File

@ -86,7 +86,7 @@
</div> </div>
@code { @code {
LoginModel loginModel = new LoginModel("test@test", "test1234"); LoginModel loginModel = new LoginModel("test@tiam.hu", "test1234");
} }

View File

@ -71,28 +71,28 @@ namespace TIAMSharedUI.Pages
//var Mainresponse = JsonSerializer.Deserialize<MainResponse>(response); //var Mainresponse = JsonSerializer.Deserialize<MainResponse>(response);
var Mainresponse = JsonSerializer.Deserialize<MainResponse>(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); var mainResponse = JsonSerializer.Deserialize<MainResponse>(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
if (Mainresponse != null) if (mainResponse != null)
{ {
//check for bad request //check for bad request
//TODO: fix hacky solution //TODO: fix hacky solution
string AuthResponseJson = JsonSerializer.Serialize(Mainresponse.Content); string authResponseJson = JsonSerializer.Serialize(mainResponse.Content);
var AuthResponse = JsonSerializer.Deserialize<AuthenticationResponse>(AuthResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); var authResponse = JsonSerializer.Deserialize<AuthenticationResponse>(authResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
string accessToken = AuthResponse.AccessToken; string accessToken = authResponse.AccessToken;
var token = ProcessToken(accessToken); var token = ProcessToken(accessToken);
string _userId = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value; string userId = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value;
string _email = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; string email = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value;
var myId = Guid.Parse(_userId); var myId = Guid.Parse(userId);
//userDataService.User.Email = _email; //userDataService.User.Email = _email;
var userBasicDetails = new UserBasicDetails(_userId, _email, AuthResponse.AccessToken, AuthResponse.RefreshToken); var userBasicDetails = new UserBasicDetails(userId, email, authResponse.AccessToken, authResponse.RefreshToken);
string userBasicDetailsJson = JsonSerializer.Serialize(userBasicDetails); string userBasicDetailsJson = JsonSerializer.Serialize(userBasicDetails);
@ -103,7 +103,7 @@ namespace TIAMSharedUI.Pages
if (!Mainresponse.IsSuccess) if (!mainResponse.IsSuccess)
{ {
//await App.Current.MainPage.DisplayAlert("Error", "Invalid credentials", "Ok"); //await App.Current.MainPage.DisplayAlert("Error", "Invalid credentials", "Ok");
//display error message via jsinterop //display error message via jsinterop

View File

@ -24,6 +24,7 @@ using TIAMWebApp.Server.ModelsTIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Utility; using TIAMWebApp.Shared.Application.Utility;
using TIAM.Database.DataLayers.Admins; using TIAM.Database.DataLayers.Admins;
using System; using System;
using AyCode.Core.Consts;
using AyCode.Core.Helpers; using AyCode.Core.Helpers;
using TIAM.Entities.Profiles; using TIAM.Entities.Profiles;
using TIAM.Entities.Addresses; using TIAM.Entities.Addresses;
@ -139,7 +140,7 @@ namespace TIAMWebApp.Server.Controllers
if (email != null) if (email != null)
{ {
//get user from db //get user from db
dbUser = await _userDal.GetUserByEmailAsync(email.Value); dbUser = await _userDal.GetUserByEmailAsync(email.Value, true);
Console.WriteLine($@"DbUser email: {dbUser?.EmailAddress}"); Console.WriteLine($@"DbUser email: {dbUser?.EmailAddress}");
} }
@ -178,17 +179,17 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route("CreateUser")] [Route("CreateUser")]
public async Task<IActionResult> CreateUser([FromBody] JsonElement SerializedRegistrationModel) public async Task<IActionResult> CreateUser([FromBody] JsonElement serializedRegistrationModel)
{ {
Console.WriteLine(@"CreateUser called"); Console.WriteLine(@"CreateUser called");
if (string.IsNullOrEmpty(SerializedRegistrationModel.GetRawText())) if (string.IsNullOrEmpty(serializedRegistrationModel.GetRawText()))
{ {
return BadRequest("SerializedLoginModel is required"); return BadRequest("SerializedLoginModel is required");
} }
else else
{ {
var user = JObject.Parse(SerializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>(); var user = JObject.Parse(serializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>();
if (user != null) if (user != null)
{ {
@ -227,7 +228,7 @@ namespace TIAMWebApp.Server.Controllers
public async Task<IActionResult> CreateGuestUser([FromBody] JsonElement SerializedRegistrationModel) public async Task<IActionResult> CreateGuestUser([FromBody] JsonElement SerializedRegistrationModel)
{ {
Console.WriteLine(@"CreateGuestUser called"); Console.WriteLine(@"CreateGuestUser called");
bool result = false; var result = false;
UserModelDtoDetail? guestUser = null; UserModelDtoDetail? guestUser = null;
if (string.IsNullOrEmpty(SerializedRegistrationModel.GetRawText())) if (string.IsNullOrEmpty(SerializedRegistrationModel.GetRawText()))
@ -240,9 +241,9 @@ namespace TIAMWebApp.Server.Controllers
if (user != null) if (user != null)
{ {
Random random = new Random(); var random = new Random();
string chars = "1234567890"; var chars = "1234567890";
string nameExtension = new string(Enumerable.Repeat(chars, 10) var nameExtension = new string(Enumerable.Repeat(chars, 10)
.Select(s => s[random.Next(s.Length)]).ToArray()); .Select(s => s[random.Next(s.Length)]).ToArray());
@ -250,7 +251,7 @@ namespace TIAMWebApp.Server.Controllers
var email = user?.Email; var email = user?.Email;
var phoneNumber = user?.PhoneNumber; var phoneNumber = user?.PhoneNumber;
var password = user?.Password; var password = user?.Password;
Guid? referralId = user?.ReferralId; var referralId = user?.ReferralId;
if (email is null || phoneNumber is null || password is null) if (email is null || phoneNumber is null || password is null)
{ {
@ -271,14 +272,14 @@ namespace TIAMWebApp.Server.Controllers
userToCreate.RefferalId = referralId; userToCreate.RefferalId = referralId;
userToCreate.Profile.AddressId = Guid.NewGuid(); userToCreate.Profile.AddressId = Guid.NewGuid();
Random rnd = new Random(); //Random rnd = new Random();
userToCreate.Profile.Address = new Address(); userToCreate.Profile.Address = new Address();
userToCreate.Profile.Address.Id = userToCreate.Profile.AddressId; userToCreate.Profile.Address.Id = userToCreate.Profile.AddressId;
userToCreate.Profile.Address.AddressText = null; userToCreate.Profile.Address.AddressText = null;
userToCreate.Profile.Address.Latitude = Math.Round(90 + rnd.NextDouble(), 8); userToCreate.Profile.Address.Latitude = null; //Math.Round(90 + rnd.NextDouble(), 8);
userToCreate.Profile.Address.Longitude = Math.Round(180 + rnd.NextDouble(), 8); userToCreate.Profile.Address.Longitude = null; //Math.Round(180 + rnd.NextDouble(), 8);
result = await _userDal.AddUserAsync(userToCreate); result = await _userDal.AddUserAsync(userToCreate);
guestUser = await _userDal.GetUserModelDtoDetailByIdAsync(userId); guestUser = await _userDal.GetUserModelDtoDetailByIdAsync(userId, false);
} }
} }
@ -303,7 +304,8 @@ namespace TIAMWebApp.Server.Controllers
{ {
Logger.Info($"GetUserByEmail called with email: {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);
return _userDal.GetUserModelDtoByEmailAsync(email, false);
} }
[AllowAnonymous] [AllowAnonymous]
@ -312,7 +314,7 @@ namespace TIAMWebApp.Server.Controllers
public Task<UserModelDto?> GetUserById([FromBody] Guid id) public Task<UserModelDto?> GetUserById([FromBody] Guid id)
{ {
Logger.Info($"GetUserById called with id: {id}"); Logger.Info($"GetUserById called with id: {id}");
return _userDal.GetUserModelDtoByIdAsync(id); return _userDal.GetUserModelDtoByIdAsync(id, true);
} }
[AllowAnonymous] [AllowAnonymous]
@ -321,19 +323,7 @@ namespace TIAMWebApp.Server.Controllers
public Task<UserModelDtoDetail?> GetUserDetailById([FromBody] Guid id) public Task<UserModelDtoDetail?> GetUserDetailById([FromBody] Guid id)
{ {
Logger.Info($"GetUserDetailById called with id: {id}"); Logger.Info($"GetUserDetailById called with id: {id}");
return _userDal.GetUserModelDtoDetailByIdAsync(id); return _userDal.GetUserModelDtoDetailByIdAsync(id, true);
}
private bool VerifyPassword(string password, string hashedPassword)
{
var isPasswordValid = PasswordHasher.VerifyPassword(password, hashedPassword);
return isPasswordValid;
}
private string HashPassword(string password)
{
var hashedPassword = PasswordHasher.HashPassword(password);
return hashedPassword;
} }
} }
} }