Example #1
0
        public async Task<RegistrationResponseDto> RegisterUser(RegistrationRequestDto dto)
        {
            var response = new RegistrationResponseDto()
            {
                EmailExists = await _userRepository.EmailExists(dto.EmailAddress) // check user repository
            };

            if (!response.EmailExists)
            {
                var authentication = _passwordHasher.HashPassword(dto.Password);

                try
                {
                    if (dto.IsLandlord)
                    {
                        _landlordRepository.Register(dto, authentication);
                    }
                    else
                    {
                        _tenantRepository.Register(dto, authentication);
                    }
                    response.Success = true;
                }
                catch (Exception)
                {
                    response.Success = false;
                }
            }

            return response;
        }
Example #2
0
        public UserDto Register(RegistrationRequestDto dto, SaltedHashResult auth)
        {
            var tenant = new Tenant()
            {
                TenantUser = new User()
                {
                    EmailAddress = dto.EmailAddress,
                    FirstName = dto.FirstName,
                    LastName = dto.LastName,
                    DateOfBirth = dto.DateOfBirth,
                    DateRegistered = DateTime.UtcNow,
                    Authentication = new UserAuthentication()
                    {
                        PasswordHash = auth.Hash,
                        PasswordSalt = auth.Salt
                    },
                    Role = dto.Role
                }
            };

            _entities.Tenants.Add(tenant);
            _entities.SaveChanges();

            return tenant.TenantUser.ToDto();
        }
Example #3
0
        public async Task<UserDto> RegisterUser(RegistrationRequestDto dto, SaltedHashResult auth)
        {
            var user = new User()
            {
                EmailAddress = dto.EmailAddress,
                FirstName = dto.FirstName,
                LastName = dto.LastName,
                DateOfBirth = dto.DateOfBirth,
                DateRegistered = DateTime.UtcNow,
                Authentication = new UserAuthentication()
                {
                    PasswordHash = auth.Hash,
                    PasswordSalt = auth.Salt
                },
                Role = dto.Role
            };

            _entities.Users.Add(user);

            await _entities.SaveChangesAsync();

            return user.ToDto();
        }
Example #4
0
        public async Task<RegistrationResponseDto> RegisterUser(RegistrationRequestDto dto)
        {
            var result = await _userManager.RegisterUser(dto);

            return result;
        }