Ignore:
Timestamp:
10/22/25 23:34:14 (11 months ago)
Author:
stefansaveski <stefansaveski19@…>
Branches:
master
Children:
8e32210
Parents:
271178d
Message:

Refactor DTOs and remove user management

Updated AuthController to use RegisterDto and LoginDto for more specific DTO usage in registration and login methods. Removed UsersController and its methods, indicating a refactor or removal of user management functionality. Replaced UserDto with LoginDto, RegisterDto, and UserResponseDto in UserDTO.cs, and introduced a UserRole enum. Updated AuthService to use new DTOs and adjusted JWT token configuration. Removed UserService and IUserService, suggesting a redesign or deprecation of user service functionality. Updated IAuthService to align with AuthService changes.

Location:
iknow-api/Services/Implementations
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • iknow-api/Services/Implementations/AuthService.cs

    r271178d rcb8e531  
    2222        }
    2323
    24         public async Task<bool> RegisterAsync(UserDto userDto)
     24        public async Task<bool> RegisterAsync(RegisterDto registerDto)
    2525        {
    26             if (await _userRepository.UserExistsAsync(userDto.Username))
     26            if (await _userRepository.UserExistsAsync(registerDto.Email))
    2727                return false;
    2828
    2929            var user = new User
    3030            {
    31                 Email = userDto.Username,
    32                 PasswordHash = BCrypt.Net.BCrypt.HashPassword(userDto.Password)
     31                Name = registerDto.Name,
     32                Surname = registerDto.Surname,
     33                Index = registerDto.Index,
     34                Email = registerDto.Email,
     35                PasswordHash = BCrypt.Net.BCrypt.HashPassword(registerDto.Password),
     36                Bday = DateTime.SpecifyKind(registerDto.Bday, DateTimeKind.Utc),
     37                CreatedAt = DateTime.UtcNow,
     38                Role = (Core.Models.UserRole)registerDto.Role
    3339            };
    3440
     
    3743        }
    3844
    39         public async Task<string?> LoginAsync(UserDto userDto)
     45        public async Task<string?> LoginAsync(LoginDto loginDto)
    4046        {
    41             var user = await _userRepository.GetUserByUsernameAsync(userDto.Username);
    42             if (user == null || !BCrypt.Net.BCrypt.Verify(userDto.Password, user.PasswordHash))
     47            var user = await _userRepository.GetUserByUsernameAsync(loginDto.Email);
     48            if (user == null || !BCrypt.Net.BCrypt.Verify(loginDto.Password, user.PasswordHash))
    4349                return null;
    4450
     
    5662            {
    5763                new Claim("id", user.Id.ToString()),
    58                 new Claim("username", user.Email)
     64                new Claim("username", user.Email ?? string.Empty),
     65                new Claim("role", user.Role.ToString())
    5966            };
    6067
     
    6774
    6875            var token = new JwtSecurityToken(
    69                 issuer: "finxacces-api",
    70                 audience: "finxacces-api",
     76                issuer: "iknow-api",
     77                audience: "iknow-api",
    7178                claims: claims,
    72                 expires: DateTime.Now.AddHours(1),
     79                expires: DateTime.UtcNow.AddHours(1),
    7380                signingCredentials: creds
    7481            );
Note: See TracChangeset for help on using the changeset viewer.