public ActionResult AllowIps(string id, ICollection <string> ipAddress)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator użytkownika nie może być pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator użytkownika."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteś zalogowany."),
                new Validation(() => !CurrentUser.IsAdministrator(), "Nie masz uprawnień do wywoływania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    IUser user = UserRepository.FindById(id.ToGuid());

                    if (user == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Podany użytkownik nie istnieje."
                        };
                    }
                    else
                    {
                        ICollection <string> usedIpAddresses = UserRepository.FindIPAddresses(user.Id);
                        var blockedIps = new List <string>();

                        ipAddress = ipAddress ?? new List <string>();

                        if (!usedIpAddresses.IsNullOrEmpty())
                        {
                            foreach (string usedIpAddress in usedIpAddresses)
                            {
                                if (!ipAddress.Contains(usedIpAddress))
                                {
                                    blockedIps.Add(usedIpAddress);
                                }
                            }
                        }

                        if (blockedIps.Count > 0)
                        {
                            _blockedIPList.AddRange(blockedIps);
                        }

                        if (ipAddress.Count > 0)
                        {
                            _blockedIPList.RemoveRange(ipAddress);
                        }

                        viewData = new JsonViewData {
                            isSuccessful = true
                        };
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("odblokowywania adresów Ip użytkownika")
                    };
                }
            }

            return(Json(viewData));
        }
예제 #2
0
        public ActionResult AllowIps(string id, ICollection <string> ipAddress)
        {
            var viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "User Id cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid user identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.IsAdministrator(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    IUser user = UserRepository.FindById(id.ToGuid());

                    if (user == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified user no longer exist."
                        };
                    }
                    else
                    {
                        ICollection <string> usedIpAddresses = UserRepository.FindIPAddresses(user.Id);
                        var blockedIps = new List <string>();

                        ipAddress = ipAddress ?? new List <string>();

                        if (!usedIpAddresses.IsNullOrEmpty())
                        {
                            foreach (string usedIpAddress in usedIpAddresses)
                            {
                                if (!ipAddress.Contains(usedIpAddress))
                                {
                                    blockedIps.Add(usedIpAddress);
                                }
                            }
                        }

                        if (blockedIps.Count > 0)
                        {
                            _blockedIPList.AddRange(blockedIps);
                        }

                        if (ipAddress.Count > 0)
                        {
                            _blockedIPList.RemoveRange(ipAddress);
                        }

                        viewData = new JsonViewData {
                            isSuccessful = true
                        };
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("allowing the user Ip Addresses")
                    };
                }
            }

            return(Json(viewData));
        }