public HttpResponseMessage GetSuggestRoles(string keyword, int count)
        {
            try
            {
                if (string.IsNullOrEmpty(keyword))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, new List <UserRoleInfo>()));
                }
                var isAdmin = Components.UsersController.IsAdmin(PortalSettings);

                var roles = RoleController.Instance.GetRoles(PortalId,
                                                             x => x.RoleName.ToUpperInvariant().Contains(keyword.ToUpperInvariant()));
                var matchedRoles = roles
                                   .Where(
                    r =>
                    (isAdmin || r.RoleID != PortalSettings.AdministratorRoleId) &&
                    r.Status == RoleStatus.Approved)
                                   .ToList().Take(count).Select(u => new UserRoleInfo
                {
                    RoleID       = u.RoleID,
                    RoleName     = $"{u.RoleName}",
                    SecurityMode = u.SecurityMode
                });

                return(Request.CreateResponse(HttpStatusCode.OK,
                                              matchedRoles.ToList().Select(r => UserRoleDto.FromRoleInfo(PortalSettings, r))));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Beispiel #2
0
        public HttpResponseMessage GetUserRoles(string keyword, int userId, int pageIndex, int pageSize)
        {
            try
            {
                HttpResponseMessage response;
                var user = GetUser(userId, out response);
                if (user == null)
                {
                    return(response);
                }

                var allUserRoles = RoleController.Instance.GetUserRoles(user, true);
                if (!string.IsNullOrEmpty(keyword))
                {
                    allUserRoles =
                        allUserRoles.Where(
                            u => u.FullName.StartsWith(keyword, StringComparison.InvariantCultureIgnoreCase))
                        .ToList();
                }

                var userRoles = allUserRoles
                                .Skip(pageIndex * pageSize)
                                .Take(pageSize)
                                .Select(r => UserRoleDto.FromRoleInfo(PortalSettings, r));

                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new { UserRoles = userRoles, TotalRecords = allUserRoles.Count }));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public HttpResponseMessage GetUserRoles(string keyword, int userId, int pageIndex, int pageSize)
        {
            try
            {
                KeyValuePair <HttpStatusCode, string> response;
                var user = Components.UsersController.GetUser(userId, PortalSettings, UserInfo, out response);
                if (user == null)
                {
                    return(Request.CreateErrorResponse(response.Key, response.Value));
                }
                int totalRoles;
                var userRoles = Components.UsersController.Instance.GetUserRoles(user, keyword, out totalRoles, pageIndex, pageSize)
                                .Select(r => UserRoleDto.FromRoleInfo(PortalSettings, r));

                return(Request.CreateResponse(HttpStatusCode.OK, new { UserRoles = userRoles, TotalRecords = totalRoles }));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Beispiel #4
0
        public static List <IUIData> GetData(string Identifier, Dictionary <string, string> UIEngineInfo, UserInfo userInfo, Dictionary <string, string> parameters)
        {
            int uid = 0;

            if (parameters.Count > 0)
            {
                int.TryParse(parameters["uid"], out uid);
            }

            PortalSettings ps = PortalController.Instance.GetCurrentSettings() as PortalSettings;
            Dictionary <string, IUIData> Settings = new Dictionary <string, IUIData>();

            switch (Identifier)
            {
            case "setting_updateprofile":
            {
                if (uid > 0)
                {
                    Settings.Add("BrowseUrl", new UIData {
                            Name = "BrowseUrl", Value = Common.Utilities.Utils.BrowseUrl(-1, "Manage")
                        });
                    Settings.Add("AllowedAttachmentFileExtensions", new UIData {
                            Name = "AllowedAttachmentFileExtensions", Value = FileSetting.FileType
                        });
                    Settings.Add("MaxFileSize", new UIData {
                            Name = "MaxFileSize", Value = FileSetting.FileSize.ToString()
                        });

                    if (!(parameters.ContainsKey("username") && parameters.ContainsKey("password")))
                    {
                        return(Settings.Values.ToList());
                    }

                    int    UserID  = uid;
                    string keyword = string.Empty;

                    UserInfo     user        = DotNetNuke.Entities.Users.UserController.GetUserById(ps.PortalId, UserID);
                    UserBasicDto userDetails = UsersController.Instance.GetUserDetail(ps.PortalId, UserID);
                    ProfileController.GetUserProfile(ref user);
                    Settings.Add("UserDetails", new UIData {
                            Name = "UserDetails", Options = UserManager.MapUserBasicDto(user, userDetails)
                        });
                    Settings.Add("UserRoles", new UIData {
                            Name = "UserRoles", Options = UsersController.Instance.GetUserRoles(user, keyword, out int totalRoles).Select(r => UserRoleDto.FromRoleInfo(ps, r))
                        });
                    Settings.Add("IsAdmin", new UIData {
                            Name = "IsAdmin", Value = userInfo.IsInRole("Administrators").ToString()
                        });
                    Settings.Add("ProfilePropertiesByCategories", new UIData {
                            Name = "ProfilePropertiesByCategories", Options = Managers.UserManager.GetLocalizedCategories(user.Profile.ProfileProperties, user, true).Select(x => new { x.Key, x.Value })
                        });

                    if (string.IsNullOrEmpty(user.Profile.PreferredLocale))
                    {
                        if (string.IsNullOrEmpty(DotNetNuke.Entities.Users.UserController.GetUserById(ps.PortalId, ps.AdministratorId).Profile.PreferredLocale))
                        {
                            user.Profile.SetProfileProperty("PreferredLocale", !string.IsNullOrEmpty(ps.DefaultLanguage) ? ps.DefaultLanguage : Thread.CurrentThread.CurrentCulture.Name);
                        }
                        else
                        {
                            user.Profile.SetProfileProperty("PreferredLocale", DotNetNuke.Entities.Users.UserController.GetUserById(ps.PortalId, ps.AdministratorId).Profile.PreferredLocale);
                        }
                    }

                    List <Entities.ProfileProperties> profileProperties = new List <Entities.ProfileProperties>();
                    ListController listController = new ListController();
                    foreach (ProfilePropertyDefinition d in user.Profile.ProfileProperties)
                    {
                        string ControlType = UserManager.GetControlType(d.DataType);
                        if (ControlType == "Country" || ControlType == "Region" || ControlType == "List")
                        {
                            d.PropertyValue = string.IsNullOrEmpty(d.PropertyValue) ? "-1" : d.PropertyValue;
                        }
                        List <ListEntryInfo> data = listController.GetListEntryInfoItems(d.PropertyName, "", PortalSettings.Current.PortalId).ToList();
                        data.Insert(0, new ListEntryInfo {
                                Text = Localization.GetString("NotSpecified", Components.Constants.LocalResourcesFile), Value = d.PropertyValue
                            });
                        profileProperties.Add(new Entities.ProfileProperties {
                                ProfilePropertyDefinition = d, ListEntries = data
                            });
                    }
                    Settings.Add("ProfileProperties", new UIData {
                            Name = "ProfileProperties", Options = profileProperties
                        });

                    //Profile URL
                    dynamic Profile = null;
                    if (!string.IsNullOrEmpty(user.Profile.Photo))
                    {
                        Profile = BrowseUploadFactory.GetFile(ps, Convert.ToInt32(user.Profile.Photo));
                    }

                    Settings.Add("PhotoURL", new UIData {
                            Name = "PhotoURL", Options = Profile ?? user.Profile, Value = Vanjaro.Common.Utilities.UserUtils.GetProfileImage(PortalSettings.Current.PortalId, user.UserID, user.Email)
                        });
                    var countries = GetCountryList(Thread.CurrentThread.CurrentCulture.Name).Values.OrderBy(x => x.NormalizedFullName).Select(x => new
                        {
                            Id = x.Id.ToString(),
                            x.FullName,
                            x.Name
                        }).ToList();
                    countries.Insert(0, new { Id = "-1", FullName = Localization.GetString("NotSpecified", Components.Constants.LocalResourcesFile), Name = Localization.GetString("NotSpecified", Components.Constants.LocalResourcesFile) });
                    Settings.Add("Countries", new UIData {
                            Name = "Countries", OptionsText = "Key", OptionsValue = "Value", Options = countries
                        });
                    ReadOnlyCollection <TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
                    var Timezones = timeZones.Cast <TimeZoneInfo>().Select(x => new
                        {
                            Id = x.Id.ToString(),
                            x.DisplayName
                        });

                    Settings.Add("Time_Zones", new UIData {
                            Name = "Time_Zones", OptionsText = "Key", OptionsValue = "Value", Options = Timezones
                        });
                    Dictionary <string, Locale> ActiveLocales = new LocaleController().GetLocales(ps.PortalId);
                    var activeLocales = ActiveLocales.Values.Cast <Locale>().Select(x => new
                        {
                            x.Code,
                            x.Culture,
                            x.EnglishName,
                            x.NativeName,
                            KeyID = x.KeyID.ToString(),
                            x.Text
                        }).ToList();
                    Settings.Add("Active_Locales", new UIData {
                            Name = "Active_Locales", OptionsText = "Key", OptionsValue = "Value", Options = activeLocales
                        });
                }