public override void OnActionExecuting(HttpActionContext actionContext)
  {
   string token;
 
   try
   {
    token = actionContext.Request.Headers.GetValues("Authorization-Token").First();
   }
   catch (Exception)
   {
    actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)
    {
     Content = new StringContent("Missing Authorization-Token")
    };
    return;
   }
 
   try
   {
    //This part is where you verify the incoming token
    AuthorizedUserRepository.GetUsers().First(x => x.Name == RSAClass.Decrypt(token));
    base.OnActionExecuting(actionContext);
   }
   catch (Exception)
   {
    actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
    {
     Content = new StringContent("Unauthorized User")
    };
    return;
   }
    }
Example #2
0
 public UnitOfWork(PsychoContext context)
 {
     _context           = context;
     Roles              = new RoleRepository(_context);
     Users              = new UserRepository(_context);
     Psychologists      = new PsychologistRepository(_context);
     AuthorizedUsers    = new AuthorizedUserRepository(_context);
     AnonymousUsers     = new AnonymousUserRepository(_context);
     Appointments       = new AppointmentRepository(_context);
     AppointmentResults = new AppointmentResultRepository(_context);
     Reports            = new ReportRepository(_context);
     Chats              = new ChatRepository(_context);
     WorkSchedules      = new WorkScheduleRepository(_context);
 }