register fix

This commit is contained in:
Adam 2024-07-03 14:41:11 +02:00
parent 6aa594025d
commit ce9181ff5c
5 changed files with 66 additions and 32 deletions

View File

@ -23,6 +23,11 @@ namespace TIAM.Database.DataLayers.Users
public async Task<bool> CreateUserAsync(User user) public async Task<bool> CreateUserAsync(User user)
{ {
Context.Users.Add(user); Context.Users.Add(user);
Profile profile = new Profile();
profile.Id = Guid.NewGuid();
var parts = user.EmailAddress.Split('@');
profile.Name = parts[0];
Context.Profiles.Add(profile);
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; return await Context.SaveChangesAsync() > 0;
} }

View File

@ -22,9 +22,6 @@
<meta name="twitter:description" content="Book reliable and affordable airport transfers with Tour I Am. Enjoy a hassle-free ride to and from the airport with our professional drivers."> <meta name="twitter:description" content="Book reliable and affordable airport transfers with Tour I Am. Enjoy a hassle-free ride to and from the airport with our professional drivers.">
<meta name="twitter:image" content="https://touriam.com/images/airport-transfer.jpg"> <meta name="twitter:image" content="https://touriam.com/images/airport-transfer.jpg">
<!-->link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0/css/bootstrap.min.css"-->
<base href="/" /> <base href="/" />
<link rel="stylesheet" href="_content/TIAMSharedUI/css/bootstrap/bootstrap.min.css" /> <link rel="stylesheet" href="_content/TIAMSharedUI/css/bootstrap/bootstrap.min.css" />

View File

@ -151,9 +151,9 @@
foreach (UserProductMapping Permission in Permissions) foreach (UserProductMapping Permission in Permissions)
{ {
var permissionToCheck = await ServiceProviderDataService.GetUserProductMappingByIdAsync(Permission.Id); //var permissionToCheck = await ServiceProviderDataService.GetUserProductMappingByIdAsync(Permission.Id);
_logger.Debug($"calling IsPowerOf with values: {Permission.Id}, {Permission.Permissions}, {permissionToCheck.Permissions}, {3}"); _logger.Debug($"calling IsPowerOf with values: {Permission.Id}, {Permission.Permissions}, {1}");
var driverPermissionResult = IsBitSet(permissionToCheck.Permissions, 3); var driverPermissionResult = IsBitSet(Permission.Permissions, 1);
if (driverPermissionResult) if (driverPermissionResult)
{ {
_isDriver = true; _isDriver = true;

View File

@ -12,6 +12,7 @@ using AyCode.Services.Loggers;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using TIAM.Core.Consts; using TIAM.Core.Consts;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAMWebApp.Shared.Application.Services;
namespace TIAMSharedUI.Pages namespace TIAMSharedUI.Pages
{ {
@ -157,12 +158,12 @@ namespace TIAMSharedUI.Pages
/// This method stores the user data in the session service so we know during navigation that the user is logged in. /// This method stores the user data in the session service so we know during navigation that the user is logged in.
/// </summary> /// </summary>
/// <param name="user"></param> /// <param name="user"></param>
protected void SaveToSessionInfo(UserSessionModel user) protected async Task SaveToSessionInfo(UserSessionModel user)
{ {
sessionService.User = user; sessionService.User = user;
sessionService.IsAuthenticated = true; sessionService.IsAuthenticated = true;
sessionService.HasCompany = user.UserModelDto.UserProductMappings.Count > 0; sessionService.HasCompany = user.UserModelDto.UserProductMappings.Count > 0;
sessionService.IsDriver = CheckIfDriver(user.UserModelDto.UserProductMappings); sessionService.IsDriver = await CheckIfDriver(user.UserModelDto.UserProductMappings);
if (user.UserModelDto.Id == TiamConstClient.DevAdminIds[0] || user.UserModelDto.Id == TiamConstClient.DevAdminIds[1]) if (user.UserModelDto.Id == TiamConstClient.DevAdminIds[0] || user.UserModelDto.Id == TiamConstClient.DevAdminIds[1])
{ {
sessionService.IsDevAdmin = true; sessionService.IsDevAdmin = true;
@ -177,12 +178,16 @@ namespace TIAMSharedUI.Pages
BrowserConsoleLogWriter.Debug($"Saved to session: IsAuthenticated: {sessionService.IsAuthenticated}, HasCompany: {sessionService.HasCompany}, IsDriver: {sessionService.IsDriver}, IsDevAdmin: {sessionService.IsDevAdmin}, IsSysAdmin: {sessionService.IsSysAdmin}"); BrowserConsoleLogWriter.Debug($"Saved to session: IsAuthenticated: {sessionService.IsAuthenticated}, HasCompany: {sessionService.HasCompany}, IsDriver: {sessionService.IsDriver}, IsDevAdmin: {sessionService.IsDevAdmin}, IsSysAdmin: {sessionService.IsSysAdmin}");
} }
public bool CheckIfDriver(List<UserProductMapping> Permissions) public async Task<bool> CheckIfDriver(List<UserProductMapping> Permissions)
{ {
bool _isDriver = false; bool _isDriver = false;
foreach (UserProductMapping Permission in Permissions) foreach (UserProductMapping Permission in Permissions)
{ {
if (IsPowerOfTwoInSum(2, Permission.Permissions)) //var permissionToCheck = await ServiceProviderDataService.GetUserProductMappingByIdAsync(Permission.Id);
BrowserConsoleLogWriter.Debug($"calling IsPowerOf with values: {Permission.Id}, {Permission.Permissions}, {1}");
var driverPermissionResult = IsBitSet(Permission.Permissions, 1);
if (driverPermissionResult)
{ {
_isDriver = true; _isDriver = true;
sessionService.DriverPersmissionId = Permission.Id; sessionService.DriverPersmissionId = Permission.Id;
@ -191,10 +196,16 @@ namespace TIAMSharedUI.Pages
return _isDriver; return _isDriver;
} }
public static bool IsPowerOfTwoInSum(int number, int power) public bool IsBitSet(int number, int power)
{ {
BrowserConsoleLogWriter.Debug($"called IsBitSet with values: {number}, {power}");
int powerOfTwo = 1 << power; // Calculate 2^power int powerOfTwo = 1 << power; // Calculate 2^power
return (number & powerOfTwo) != 0; // Check if the bit at position `power` is set
BrowserConsoleLogWriter.Debug($"powerOfTwo: {powerOfTwo}, {power}");
bool result = (number & powerOfTwo) != 0; // Check if the bit at position `power` is set
return result;
} }
} }
} }

View File

@ -14,6 +14,7 @@ using TIAM.Entities.Profiles;
using TIAM.Entities.Addresses; using TIAM.Entities.Addresses;
using TIAM.Services.Server.Logins; using TIAM.Services.Server.Logins;
using ILogger = TIAM.Core.Loggers.ILogger; using ILogger = TIAM.Core.Loggers.ILogger;
using AyCode.Core.Helpers;
namespace TIAMWebApp.Server.Controllers namespace TIAMWebApp.Server.Controllers
{ {
@ -197,7 +198,7 @@ namespace TIAMWebApp.Server.Controllers
else else
{ {
var user = JObject.Parse(serializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>(); var user = JObject.Parse(serializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>();
bool result = false;
if (user != null) if (user != null)
{ {
//add userModel to users array //add userModel to users array
@ -220,12 +221,22 @@ namespace TIAMWebApp.Server.Controllers
_logger.Info($@"User to be created: {email}"); _logger.Info($@"User to be created: {email}");
_logger.Info($@"User to be created: {phoneNumber}"); _logger.Info($@"User to be created: {phoneNumber}");
_logger.Info($@"User to be created: {password}"); _logger.Info($@"User to be created: {password}");
//var hashedPassword = PasswordHasher.HashPassword(user.Password, PasswordHasher.GenerateDynamicSalt(userId));
await _userDal.CreateUserAsync(new User(userId, email, phoneNumber, password)); //await _userDal.CreateUserAsync(new User(userId, email, phoneNumber, hashedPassword));
var createResult = await _loginService.RegistrationAsync(userId, email, password, phoneNumber);
if (createResult != AyCode.Core.Consts.AcErrorCode.Unset)
{
_logger.Error("Error:" + createResult.ToString());
result = false;
}
else
{
result = true;
}
} }
} }
return Ok("yes"); return Ok(result.ToString());
} }
} }
@ -297,7 +308,8 @@ namespace TIAMWebApp.Server.Controllers
var userId = Guid.NewGuid(); var userId = Guid.NewGuid();
var email = user?.Email; var email = user?.Email;
var phoneNumber = user?.PhoneNumber; var phoneNumber = user?.PhoneNumber;
var password = user?.Password; var password = user?.Password;
var 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)
@ -310,23 +322,32 @@ namespace TIAMWebApp.Server.Controllers
_logger.Info($@"User to be created: {email}"); _logger.Info($@"User to be created: {email}");
_logger.Info($@"User to be created: {phoneNumber}"); _logger.Info($@"User to be created: {phoneNumber}");
_logger.Info($@"User to be created: {password}"); _logger.Info($@"User to be created: {password}");
User userToCreate = new(userId, email, phoneNumber, password); //User userToCreate = new(userId, email, phoneNumber, hashedPassword);
userToCreate.ProfileId = Guid.NewGuid(); //userToCreate.ProfileId = Guid.NewGuid();
userToCreate.Profile = new Profile(); //userToCreate.Profile = new Profile();
userToCreate.Profile.Id = userToCreate.ProfileId; //userToCreate.Profile.Id = userToCreate.ProfileId;
userToCreate.Profile.Name = "Guest - " + nameExtension; //userToCreate.Profile.Name = "Guest - " + nameExtension;
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 = null; //Math.Round(90 + rnd.NextDouble(), 8); //userToCreate.Profile.Address.Latitude = null; //Math.Round(90 + rnd.NextDouble(), 8);
userToCreate.Profile.Address.Longitude = null; //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.GetUserModelDtoByIdAsync<UserModelDtoDetail>(userId, false); //guestUser = await _userDal.GetUserModelDtoByIdAsync<UserModelDtoDetail>(userId, false);
var createResult = await _loginService.RegistrationAsync(userId, email, password, phoneNumber);
if (createResult != AyCode.Core.Consts.AcErrorCode.Unset)
{
_logger.Error("Error:" + createResult.ToString());
}
else
{
result = true;
}
} }
} }