Ignore:
Timestamp:
10/22/25 22:40:03 (11 months ago)
Author:
stefansaveski <stefansaveski19@…>
Branches:
master
Children:
41e4f9f
Parents:
d025ba3
Message:

Implement JWT Authentication and Update User Schema

Replaced repository interface with FinXaccesApi.Repositories in UsersControllers.cs. Updated database schema to use PasswordHash instead of Password. Added new migration files reflecting these changes. Updated service registration in Program.cs to include IAuthService and IUserRepository. Refactored UserRepository.cs and IUserRepository.cs with new methods and namespace changes. Commented out UserService.cs. Updated appsettings with new connection strings and JWT settings. Added BCrypt.Net-Next and System.IdentityModel.Tokens.Jwt packages. Introduced AuthController, UserDTO, AuthService, and IAuthService for handling authentication and user management.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • iknow-api/Repository/Implementations/UserRepository.cs

    rd025ba3 r5b42c8d  
    1 using System.Threading;
    2 using System.Threading.Tasks;
     1using iknow_api.Core.Models;
     2using iknow_api.Core.Data;
     3using iknow_api.Core.Data;
     4using iknow_api.Core.Models;
    35using Microsoft.EntityFrameworkCore;
    4 using iknow_api.Core.Models;
    5 using iknow_api.Repository.Interfaces;
    6 using iknow_api.Core.Data;
    76
    8 namespace iknow_api.Repository
     7namespace FinXaccesApi.Repositories
    98{
    109    public class UserRepository : IUserRepository
     
    1716        }
    1817
    19         public Task<bool> EmailExistsAsync(string email, CancellationToken cancellationToken = default)
    20             => _context.User.AnyAsync(u => u.Email == email, cancellationToken);
    21 
    22         public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default)
     18        public async Task<bool> UserExistsAsync(string username)
    2319        {
    24             await _context.User.AddAsync(user, cancellationToken);
    25             await _context.SaveChangesAsync(cancellationToken);
    26             return user;
     20            return await _context.User.AnyAsync(u => u.Email == username);
    2721        }
    2822
    29         public Task<User?> GetUserByIdAsync(int id, CancellationToken cancellationToken = default)
    30             => _context.User.FindAsync(new object[] { id }, cancellationToken).AsTask();
     23        public async Task<User?> GetUserByUsernameAsync(string username)
     24        {
     25            return await _context.User.FirstOrDefaultAsync(u => u.Email == username);
     26        }
     27
     28        public async Task AddUserAsync(User user)
     29        {
     30            _context.User.Add(user);
     31            await _context.SaveChangesAsync();
     32        }
     33
     34        public async Task<int> GetUsersCountAsync()
     35        {
     36            return await _context.User.CountAsync();
     37        }
    3138    }
    3239}
Note: See TracChangeset for help on using the changeset viewer.