Beispiel #1
0
        bool UserAuthorized(IRequest request)
        {
            var accessToken = request.Headers["AccessToken"];
            var userName    = request.Headers["username"];

            if (TruckGo.ValidateAccessToken(accessToken, userName) is Users requesterUser)
            {
                var companyIDCookie = new KeyValuePair <string, Cookie>("CompanyID", new Cookie("CompanyID", requesterUser.CompanyID.ToString()));
                var userIDCookie    = new KeyValuePair <string, Cookie>("UserID", new Cookie("UserID", requesterUser.UserID.ToString()));

                if (!request.Cookies.ContainsKey("CompanyID"))
                {
                    request.Cookies.Add(companyIDCookie);
                }
                if (!request.Cookies.ContainsKey("UserID"))
                {
                    request.Cookies.Add(userIDCookie);
                }

                if (!UserCookies.ContainsKey(accessToken))
                {
                    UserCookies.Add(accessToken, new List <KeyValuePair <string, Cookie> >());
                    UserCookies[accessToken].Add(companyIDCookie);
                    UserCookies[accessToken].Add(userIDCookie);
                }

                if (!ConfirmedUsers.ContainsKey(accessToken))
                {
                    ConfirmedUsers.Add(accessToken, userName);
                }

                return(true);
            }
            return(false);
        }
Beispiel #2
0
        private bool AlreadyConfirmed(string accessToken, string userName, IRequest request)
        {
            var confirmed = ConfirmedUsers.ContainsKey(accessToken) && ConfirmedUsers[accessToken] == userName;

            if (confirmed && request.Cookies.Count == 0)
            {
                foreach (var cookie in UserCookies[accessToken])
                {
                    request.Cookies.Add(cookie);
                }
            }

            return(confirmed);
        }