source: iknow-api/Repository/Implementations/UserRepository.cs@ 5b42c8d

Last change on this file since 5b42c8d was 5b42c8d, checked in by stefansaveski <stefansaveski19@…>, 11 months ago

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.

  • Property mode set to 100644
File size: 1.0 KB
Line 
1using iknow_api.Core.Models;
2using iknow_api.Core.Data;
3using iknow_api.Core.Data;
4using iknow_api.Core.Models;
5using Microsoft.EntityFrameworkCore;
6
7namespace FinXaccesApi.Repositories
8{
9 public class UserRepository : IUserRepository
10 {
11 private readonly AppDbContext _context;
12
13 public UserRepository(AppDbContext context)
14 {
15 _context = context;
16 }
17
18 public async Task<bool> UserExistsAsync(string username)
19 {
20 return await _context.User.AnyAsync(u => u.Email == username);
21 }
22
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 }
38 }
39}
Note: See TracBrowser for help on using the repository browser.