Пример #1
0
        protected override System.Threading.Tasks.Task <HttpResponseMessage> SendAsync(HttpRequestMessage
                                                                                       request, System.Threading.CancellationToken cancellationToken)
        {
            if (request.RequestUri.ToString().Contains("api/auth"))
            {
                return(base.SendAsync(request, cancellationToken));
            }

            IEnumerable <string> sampleApiKeyHeaderValues = null;

            if (request.Headers.TryGetValues("authToken", out sampleApiKeyHeaderValues))
            {
                string[] apiKeyHeaderValue = sampleApiKeyHeaderValues.First().Split(':');

                if (apiKeyHeaderValue.Length == 2)
                {
                    if (!int.TryParse(apiKeyHeaderValue[0], out int userId))
                    {
                        return(requestCancel(request, cancellationToken, InvalidToken));
                    }

                    var accessToken = apiKeyHeaderValue[1];

                    string realAccessToken;

                    using (var db = new WorkItDbContext())
                    {
                        realAccessToken = db.Users.FirstOrDefault(u => u.UserId == userId).AccessToken;
                    }

                    if (realAccessToken == accessToken)
                    {
                        return(base.SendAsync(request, cancellationToken));
                    }
                    else
                    {
                        return(requestCancel(request, cancellationToken, InvalidToken));
                    }
                }
                else
                {
                    return(requestCancel(request, cancellationToken, MissingToken));
                }
            }
            else
            {
                return(requestCancel(request, cancellationToken, MissingToken));
            }
        }
Пример #2
0
 public RaitingBussinessLogic(WorkItDbContext db)
 {
     this.Db = db;
 }
Пример #3
0
 public UserBussinessLogic(WorkItDbContext db)
 {
     this.Db = db;
 }
Пример #4
0
 public DialogBussinessLogic(WorkItDbContext db)
 {
     this.Db = db;
 }
Пример #5
0
 public TaskRequestBussinessLogic(WorkItDbContext db)
 {
     this.Db = db;
 }
Пример #6
0
 public MessagesBussinessLogic(WorkItDbContext db)
 {
     this.Db = db;
 }