Ignore:
Timestamp:
09/18/22 18:09:53 (2 years ago)
Author:
Danilo <danilo.najkov@…>
Branches:
master
Parents:
49b0bbd
Message:

vip functionallity + menu fields + alergens filtering + google/fb login + email queueing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • resTools_backend/backend/Services/UserService.cs

    r49b0bbd r13f1472  
    2020    Task<AuthenticateResponse> Register(CreateUserRequest req, bool isFirst);
    2121    Task<User> GetById(int id);
     22    Task<User> GetByEmail(string email);
    2223    Task SendEmailConfirmation(string email);
    2324    Task SendPasswordReset(string email);
    2425    Task ConfirmEmail(User user, string checkValid);
    2526    Task ResetPassword(string checkValid, string password);
     27    Task<List<UserResponse>> GetUsers();
     28    Task UpdateVipStatus(int id, bool isVip);
     29
    2630}
    2731
     
    3943    }
    4044
     45    public async Task<User> GetByEmail(string email)
     46    {
     47        return await _context.Users.FirstOrDefaultAsync(x => x.Email == email);
     48    }
     49
    4150    public async Task<AuthenticateResponse> Authenticate(AuthenticateRequest model)
    4251    {
     
    4958        var token = generateJwtToken(user);
    5059
    51         return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token, IsAdmin = user.IsAdmin, IsConfirmed = user.IsConfirmed};
     60        return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token, IsAdmin = user.IsAdmin, IsConfirmed = user.IsConfirmed, isVip = user.IsVip};
    5261    }
    5362
     
    7584    public async Task<AuthenticateResponse> Register(CreateUserRequest req, bool isFirst)
    7685    {
    77         User user = new User() { Email = req.Email, Password = req.Password, IsAdmin = isFirst, IsConfirmed = false };
     86        var exists = await _context.Users.FirstOrDefaultAsync(x => x.Email == req.Email);
     87        if(exists != null && req.IsConfirmed)
     88        {
     89            return new AuthenticateResponse { Email = exists.Email, Id = exists.Id, IsAdmin = exists.IsAdmin, IsConfirmed = true };
     90        }
     91        User user = new User() { Email = req.Email, Password = req.Password, IsAdmin = isFirst, IsConfirmed = req.IsConfirmed, IsVip = false };
    7892        await _context.Users.AddAsync(user);
    7993        await _context.SaveChangesAsync();
    8094        var token = generateJwtToken(user);
    81         return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token, IsAdmin = user.IsAdmin, IsConfirmed = false };
     95        return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token, IsAdmin = user.IsAdmin, IsConfirmed = req.IsConfirmed, isVip = user.IsVip };
    8296    }
    8397
     
    125139    }
    126140
     141    public async Task<List<UserResponse>> GetUsers()
     142    {
     143        return await _context.Users.Select(x => new UserResponse()
     144        {
     145            Email = x.Email,
     146            Id = x.Id,
     147            IsVip = x.IsVip
     148        }).OrderBy(x => x.Id).ToListAsync();
     149    }
     150
     151    public async Task UpdateVipStatus(int id, bool isVip)
     152    {
     153        var user = await _context.Users.FindAsync(id);
     154        user.IsVip = isVip;
     155        _context.Users.Update(user);
     156        await _context.SaveChangesAsync();
     157    }
     158
    127159    private string generateJwtToken(User user)
    128160    {
Note: See TracChangeset for help on using the changeset viewer.