Пример #1
0
        private static void UpdateUserAccess(User user, string projectName, string applicationName, string cluster, Access access)
        {
            user.Access.AddRule(new AccessRules() { Project = projectName, Application = applicationName, Cluster = cluster, Access = access });

            var hostName = ApplicationConfiguration.Get("pandora_api_url");
            var url = hostName + "/api/Users/" + ClaimsPrincipal.Current.Id();

            var restClient = new RestSharp.RestClient(url);

            var editRequest = new RestSharp.RestRequest();
            editRequest.Method = RestSharp.Method.PUT;
            editRequest.RequestFormat = RestSharp.DataFormat.Json;
            editRequest.AddHeader("Content-Type", "application/json;charset=utf-8");
            editRequest.AddHeader("Authorization", "Bearer " + ClaimsPrincipal.Current.Token());

            editRequest.AddBody(user);

            var editResult = restClient.Execute(editRequest);
        }
Пример #2
0
        private void CreateUser(User user)
        {
            var workingDir = Path.Combine(Folders.Users, user.Id);

            var userFilePath = Path.Combine(workingDir, user.Id + ".json");

            if (!System.IO.File.Exists(userFilePath))
            {
                Directory.CreateDirectory(Path.Combine(workingDir));

                var serializedUser = JsonConvert.SerializeObject(user, Formatting.Indented);

                System.IO.File.WriteAllText(userFilePath, serializedUser);
            }
        }
Пример #3
0
        private User GetUser(ClaimsIdentity args)
        {
            var userId = args.Claims.Where(x => x.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value;

            var userFilePath = Path.Combine(Folders.Users, userId, userId + ".json");

            User user = null;

            if (System.IO.File.Exists(userFilePath))
            {
                user = JsonConvert.DeserializeObject<User>(System.IO.File.ReadAllText(userFilePath));
            }

            if (user == null)
            {
                user = new User();
                user.Id = userId;
                user.Access = new SecurityAccess();

                CreateUser(user);
            }

            return user;
        }