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)
{
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}");
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: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="/" />
<link rel="stylesheet" href="_content/TIAMSharedUI/css/bootstrap/bootstrap.min.css" />

View File

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

View File

@ -12,6 +12,7 @@ using AyCode.Services.Loggers;
using Microsoft.AspNetCore.Components.Authorization;
using TIAM.Core.Consts;
using TIAM.Entities.Users;
using TIAMWebApp.Shared.Application.Services;
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.
/// </summary>
/// <param name="user"></param>
protected void SaveToSessionInfo(UserSessionModel user)
protected async Task SaveToSessionInfo(UserSessionModel user)
{
sessionService.User = user;
sessionService.IsAuthenticated = true;
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])
{
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}");
}
public bool CheckIfDriver(List<UserProductMapping> Permissions)
public async Task<bool> CheckIfDriver(List<UserProductMapping> Permissions)
{
bool _isDriver = false;
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;
sessionService.DriverPersmissionId = Permission.Id;
@ -191,10 +196,16 @@ namespace TIAMSharedUI.Pages
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
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.Services.Server.Logins;
using ILogger = TIAM.Core.Loggers.ILogger;
using AyCode.Core.Helpers;
namespace TIAMWebApp.Server.Controllers
{
@ -197,7 +198,7 @@ namespace TIAMWebApp.Server.Controllers
else
{
var user = JObject.Parse(serializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>();
bool result = false;
if (user != null)
{
//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: {phoneNumber}");
_logger.Info($@"User to be created: {password}");
await _userDal.CreateUserAsync(new User(userId, email, phoneNumber, password));
//var hashedPassword = PasswordHasher.HashPassword(user.Password, PasswordHasher.GenerateDynamicSalt(userId));
//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());
}
}
@ -298,6 +309,7 @@ namespace TIAMWebApp.Server.Controllers
var email = user?.Email;
var phoneNumber = user?.PhoneNumber;
var password = user?.Password;
var referralId = user?.ReferralId;
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: {phoneNumber}");
_logger.Info($@"User to be created: {password}");
User userToCreate = new(userId, email, phoneNumber, password);
userToCreate.ProfileId = Guid.NewGuid();
//User userToCreate = new(userId, email, phoneNumber, hashedPassword);
//userToCreate.ProfileId = Guid.NewGuid();
userToCreate.Profile = new Profile();
userToCreate.Profile.Id = userToCreate.ProfileId;
userToCreate.Profile.Name = "Guest - " + nameExtension;
userToCreate.RefferalId = referralId;
userToCreate.Profile.AddressId = Guid.NewGuid();
//userToCreate.Profile = new Profile();
//userToCreate.Profile.Id = userToCreate.ProfileId;
//userToCreate.Profile.Name = "Guest - " + nameExtension;
//userToCreate.RefferalId = referralId;
//userToCreate.Profile.AddressId = Guid.NewGuid();
//Random rnd = new Random();
userToCreate.Profile.Address = new Address();
userToCreate.Profile.Address.Id = userToCreate.Profile.AddressId;
userToCreate.Profile.Address.AddressText = null;
userToCreate.Profile.Address.Latitude = null; //Math.Round(90 + rnd.NextDouble(), 8);
userToCreate.Profile.Address.Longitude = null; //Math.Round(180 + rnd.NextDouble(), 8);
result = await _userDal.AddUserAsync(userToCreate);
guestUser = await _userDal.GetUserModelDtoByIdAsync<UserModelDtoDetail>(userId, false);
////Random rnd = new Random();
//userToCreate.Profile.Address = new Address();
//userToCreate.Profile.Address.Id = userToCreate.Profile.AddressId;
//userToCreate.Profile.Address.AddressText = null;
//userToCreate.Profile.Address.Latitude = null; //Math.Round(90 + rnd.NextDouble(), 8);
//userToCreate.Profile.Address.Longitude = null; //Math.Round(180 + rnd.NextDouble(), 8);
//result = await _userDal.AddUserAsync(userToCreate);
//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;
}
}
}