public async Task <List <TEntity> > GetAllByFilter(Expression <Func <TEntity, bool> > filter) { using var context = new JwtContext(); return(await context.Set <TEntity>().Where(filter).ToListAsync()); //throw new NotImplementedException(); }
public override void OnActionExecuting(ActionExecutingContext context) { var authHeader = context.HttpContext.Request.GetHeader("Authorization"); if (authHeader == null || !authHeader.StartsWith("Bearer ")) { throw new Exception("Authorization Bearer token is missing"); } string token = authHeader.Replace("Bearer", "").Trim(); JwtContext jwtContext = null; try { jwtContext = Decode(token); } catch (Exception) { throw new UnauthorizedAccessException("Invalid token"); } if (jwtContext != null && _roles.Contains(jwtContext.UserRole)) { base.OnActionExecuting(context); } else { throw new UnauthorizedAccessException("Unauthorized"); } }
public async Task <TEntity> GetByFilter(Expression <Func <TEntity, bool> > filter) { using var context = new JwtContext(); return(await context.Set <TEntity>().FirstOrDefaultAsync(filter)); //throw new NotImplementedException(); }
public async Task <TEntity> GetById(int id) { using var context = new JwtContext(); return(await context.Set <TEntity>().FindAsync(id)); // throw new NotImplementedException(); }
public async Task Update(TEntity entity) { var context = new JwtContext(); context.Update(entity); await context.SaveChangesAsync(); }
public async Task <List <TEntity> > GetAll() { //throw new NotImplementedException(); using var context = new JwtContext(); return(await context.Set <TEntity>().ToListAsync()); }
public async Task <bool> CheckPasswordAsync(AppUserLoginDto appUserLoginDto) { var context = new JwtContext(); var appUser = await context.AppUsers.Where(x => x.UserName == appUserLoginDto.UserName).FirstOrDefaultAsync(); return(appUser.Password == appUserLoginDto.Password ? true : false); }
public async Task Add(TEntity entity) { using (var context = new JwtContext()) { context.Add(entity); await context.SaveChangesAsync(); } }
public async Task Update(TEntity entity) { using var context = new JwtContext(); context.Update(entity); await context.SaveChangesAsync(); // throw new NotImplementedException(); }
public static string Encode(JwtContext context) { IJwtAlgorithm algorithm = new HMACSHA256Algorithm(); IJsonSerializer serializer = new JsonNetSerializer(); IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder); return(encoder.Encode(context, Constants.JWT_SECRET)); }
public static JwtContext ContextFromUser(User user) { JwtContext context = new JwtContext(); context.UserId = user.Id; context.UserRole = user.Role; context.Expiry = DateTime.Now.AddMinutes(Constants.JWT_SESSION_LENGHT); return(context); }
public async Task <List <AppRole> > GetRolesByUserName(string userName) { using var context = new JwtContext(); return(await context.AppUsers.Join(context.AppUserRoles, u => u.Id, ur => ur.AppUserId, (user, userRole) => new { user = user, userRole = userRole }).Join(context.AppRoles, two => two.userRole.AppRoleId, r => r.Id, (twoTable, role) => new { user = twoTable.user, userRole = twoTable.userRole, role = role }).Where(I => I.user.UserName == userName).Select(I => new AppRole { Id = I.role.Id, Name = I.role.Name }).ToListAsync()); }
public async Task <T> GetById(int Id) { using var context = new JwtContext(); return(await context.Set <T>().FindAsync(Id)); }
public async Task <T> GetByFilter(Expression <Func <T, bool> > filter) { using var context = new JwtContext(); return(await context.Set <T>().FirstOrDefaultAsync(filter)); }
public async Task <List <T> > GetAllByFilter(Expression <Func <T, bool> > filter) { using var context = new JwtContext(); return(await context.Set <T>().Where(filter).ToListAsync()); }
public async Task <List <T> > GetAll() { using var context = new JwtContext(); return(await context.Set <T>().ToListAsync()); }
public UnitOfWork(JwtContext context) { _context = context; User = new UserRepository(_context); Token = new Token(_context); }
public async Task Add(TEntity entity) { using var context = new JwtContext(); context.Set <TEntity>().Add(entity); await context.SaveChangesAsync(); }
public async Task <TEntity> GetById(int id) { var context = new JwtContext(); return(await context.Set <TEntity>().FindAsync(id)); }
public async Task <TEntity> GetByFilter(Expression <Func <TEntity, bool> > filter) { var context = new JwtContext(); return(await context.Set <TEntity>().Where(filter).FirstOrDefaultAsync()); }
public async Task <AppUser> FindByUserNameAsync(string userName) { var context = new JwtContext(); return(await context.AppUsers.Where(x => x.UserName == userName).FirstOrDefaultAsync()); }
public Token(JwtContext context) { _context = context; }
public async Task Remove(T entity) { using var context = new JwtContext(); context.Remove(entity); await context.SaveChangesAsync(); }
public async Task <AppRole> FindByNameAsync(string roleName) { var contex = new JwtContext(); return(await contex.AppRoles.Where(x => x.Name == roleName).FirstOrDefaultAsync()); }
public UserRepository(JwtContext context) { _context = context; }
public AccountController(JwtContext context, IOptions <AuthOptions> options, IHostEnvironment hostEnvironment) { this.context = context; this.options = options; this.hostEnvironment = hostEnvironment; }
public async Task Delete(int id) { using var context = new JwtContext(); context.Remove(id); await context.SaveChangesAsync(); }