├── .gitignore ├── obj ├── Debug │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ ├── forDNN.Modules.UsersExportImport.dll │ ├── forDNN.Modules.UsersExportImport.pdb │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── UsersExportImport.csprojResolveAssemblyReference.cache │ ├── UsersImporter.csproj.FileListAbsolute.txt │ ├── UsersExportImport.csproj.FileListAbsolute.txt │ └── ImportUsers_.csproj.FileListAbsolute.txt └── Release │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ ├── forDNN.Modules.UsersExportImport.dll │ ├── forDNN.Modules.UsersExportImport.pdb │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── UsersExportImport.csprojResolveAssemblyReference.cache │ └── UsersExportImport.csproj.FileListAbsolute.txt ├── UsersImporter.suo ├── Install ├── resources.zip ├── UsersExportImportExample.xls ├── bin │ └── forDNN.Modules.UsersExportImport.dll ├── forDNN.UsersExportImport_v.01.00.00.zip ├── forDNN.UsersExportImport_v.01.01.00.zip ├── forDNN.UsersExportImport_v.01.01.01.zip ├── forDNN.UsersExportImport_v.01.01.02.zip ├── forDNN.UsersExportImport_v.01.01.03.zip ├── forDNN.UsersExportImport_v.01.01.04.zip ├── forDNN.UsersExportImport_v.01.01.05.zip ├── forDNN.UsersExportImport_v.01.01.06.zip ├── forDNN.UsersExportImport_v.01.01.07.zip ├── forDNN.UsersExportImport_v.01.02.00.zip ├── forDNN.UsersExportImport_v.01.02.01.zip ├── forDNN.UsersExportImport_v.01.02.02.zip ├── forDNN.UsersExportImport_v.01.02.04.zip ├── forDNN.UsersExportImport_v.01.02.05.zip ├── forDNN.UsersExportImport_v.01.02.03.21534.zip ├── Compiled.bat ├── Examples │ ├── Users_ExpotImport_CSV_Example.csv │ └── Users_ExpotImport_XML_Example.xml ├── UsersExportImport.dnn └── _UsersExportImport.dnn ├── UsersExportImport.suo ├── UsersExportImport.v11.suo ├── .vs ├── UsersExportImport │ └── v14 │ │ └── .suo └── config │ └── applicationhost.config ├── bin ├── forDNN.Modules.UsersExportImport.dll └── forDNN.Modules.UsersExportImport.pdb ├── README.md ├── WebApi ├── RouteMapper.cs └── ExportImportApiController.cs ├── Models └── ExportInfo.cs ├── UsersExportImport.sln ├── SQL └── UpdatePortals.SqlDataProvider ├── UsersExportImport.csproj.user ├── web.Debug.config ├── web.config ├── web.Release.config ├── Properties └── AssemblyInfo.cs ├── MainControl.ascx.cs ├── UsersExportImport.csproj ├── Components ├── ExportController.cs └── CommonController.cs ├── MainControl.ascx ├── App_LocalResources └── MainControl.ascx.resx └── MainControl.ascx.designer.cs /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | *.user 3 | 4 | .vs/ 5 | bin/ 6 | obj/ -------------------------------------------------------------------------------- /obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Release/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Release/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /obj/Release/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /UsersImporter.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/UsersImporter.suo -------------------------------------------------------------------------------- /Install/resources.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/resources.zip -------------------------------------------------------------------------------- /UsersExportImport.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/UsersExportImport.suo -------------------------------------------------------------------------------- /UsersExportImport.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/UsersExportImport.v11.suo -------------------------------------------------------------------------------- /.vs/UsersExportImport/v14/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/.vs/UsersExportImport/v14/.suo -------------------------------------------------------------------------------- /Install/UsersExportImportExample.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/UsersExportImportExample.xls -------------------------------------------------------------------------------- /bin/forDNN.Modules.UsersExportImport.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/bin/forDNN.Modules.UsersExportImport.dll -------------------------------------------------------------------------------- /bin/forDNN.Modules.UsersExportImport.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/bin/forDNN.Modules.UsersExportImport.pdb -------------------------------------------------------------------------------- /obj/Debug/forDNN.Modules.UsersExportImport.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Debug/forDNN.Modules.UsersExportImport.dll -------------------------------------------------------------------------------- /obj/Debug/forDNN.Modules.UsersExportImport.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Debug/forDNN.Modules.UsersExportImport.pdb -------------------------------------------------------------------------------- /Install/bin/forDNN.Modules.UsersExportImport.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/bin/forDNN.Modules.UsersExportImport.dll -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.00.00.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.00.00.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.00.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.00.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.01.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.01.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.02.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.02.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.03.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.03.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.04.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.04.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.05.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.05.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.06.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.06.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.01.07.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.01.07.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.02.00.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.02.00.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.02.01.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.02.01.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.02.02.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.02.02.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.02.04.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.02.04.zip -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.02.05.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.02.05.zip -------------------------------------------------------------------------------- /obj/Release/forDNN.Modules.UsersExportImport.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Release/forDNN.Modules.UsersExportImport.dll -------------------------------------------------------------------------------- /obj/Release/forDNN.Modules.UsersExportImport.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Release/forDNN.Modules.UsersExportImport.pdb -------------------------------------------------------------------------------- /obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /Install/forDNN.UsersExportImport_v.01.02.03.21534.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/Install/forDNN.UsersExportImport_v.01.02.03.21534.zip -------------------------------------------------------------------------------- /obj/Release/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Release/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /obj/Release/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /obj/Debug/UsersExportImport.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Debug/UsersExportImport.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /obj/Release/UsersExportImport.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fordnn/usersexportimport/HEAD/obj/Release/UsersExportImport.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # usersexportimport 2 |

Project Description
This module allows to export/import users, user profiles properties and roles to DotNetNuke from CSV/XML files. This is simple and fast way to create your users.

3 |

 

4 | -------------------------------------------------------------------------------- /Install/Compiled.bat: -------------------------------------------------------------------------------- 1 | copy "D:\Work\Projects\forDNN\UsersExportImport\App_LocalResources\*.*" "c:\WebSites\dnn629\DesktopModules\forDNN.UsersExportImport\App_LocalResources\" 2 | 3 | xcopy "D:\Work\Projects\forDNN\UsersExportImport\bin\forDNN.Modules.UsersExportImport.dll" "c:\WebSites\dnn629\bin\" /M /Y 4 | copy "D:\Work\Projects\forDNN\UsersExportImport\*.ascx" "c:\WebSites\dnn629\DesktopModules\forDNN.UsersExportImport\" 5 | 6 | -------------------------------------------------------------------------------- /obj/Debug/UsersImporter.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\WORK\Projects\DotNetNukeStudio\UsersImporter\obj\Debug\ResolveAssemblyReference.cache 2 | D:\WORK\Projects\DotNetNukeStudio\UsersImporter\bin\forDNN.Modules.UsersImporter.dll 3 | D:\WORK\Projects\DotNetNukeStudio\UsersImporter\bin\forDNN.Modules.UsersImporter.pdb 4 | D:\WORK\Projects\DotNetNukeStudio\UsersImporter\obj\Debug\forDNN.Modules.UsersImporter.dll 5 | D:\WORK\Projects\DotNetNukeStudio\UsersImporter\obj\Debug\forDNN.Modules.UsersImporter.pdb 6 | -------------------------------------------------------------------------------- /WebApi/RouteMapper.cs: -------------------------------------------------------------------------------- 1 | using DotNetNuke.Web.Api; 2 | 3 | namespace forDNN.UsersExportImport.WebApi 4 | { 5 | /// 6 | /// Class Routemapper. 7 | /// 8 | public class Routemapper : IServiceRouteMapper 9 | { 10 | /// 11 | /// Registers the routes. 12 | /// 13 | /// The route manager. 14 | public void RegisterRoutes(IMapRoute routeManager) 15 | { 16 | routeManager.MapHttpRoute("forDNN.UsersExportImport", "default", "{controller}/{action}", 17 | new[] { "forDNN.Modules.UsersExportImport.WebApi" }); 18 | } 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /obj/Release/UsersExportImport.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\Work\Projects\bin\forDNN.Modules.UsersExportImport.dll 2 | D:\Work\Projects\bin\forDNN.Modules.UsersExportImport.pdb 3 | D:\Work\Projects\forDNN\UsersExportImport\obj\Release\forDNN.Modules.UsersExportImport.dll 4 | D:\Work\Projects\forDNN\UsersExportImport\obj\Release\forDNN.Modules.UsersExportImport.pdb 5 | D:\Work\Projects\forDNN\UsersExportImport\bin\forDNN.Modules.UsersExportImport.dll 6 | D:\Work\Projects\forDNN\UsersExportImport\bin\forDNN.Modules.UsersExportImport.pdb 7 | D:\Work\Projects\forDNN\UsersExportImport\obj\Release\UsersExportImport.csprojResolveAssemblyReference.cache 8 | -------------------------------------------------------------------------------- /Install/Examples/Users_ExpotImport_CSV_Example.csv: -------------------------------------------------------------------------------- 1 | UserID,UserName,FirstName,LastName,DisplayName,IsSuperUser,Email,AffiliateId,Authorised,IsDeleted,RoleIDs,Roles,Prefix,MiddleName,Biography,Photo,Telephone,Cell,Fax,Website,IM,Twitter,Skype,LinkedIn,Facebook,Unit,Street,City,Region,Country,PostalCode,PreferredTimeZone,TimeZone,PreferredLocale 2 | 1,host,SuperUser,Account,SuperUser Account,True,host@change.me,,True,False,"1,2,0,","Registered Users,Subscribers,Administrators,",,,,,,,,,,,,,,,,,,,,Pacific Standard Time,, 3 | 2,test,,,test,True,test@forDNN.com,,True,False,"1,2,0,","Registered Users,Subscribers,Administrators,",,,,,,,,,,,,,,,,,,N/A,,Pacific Standard Time,, 4 | -------------------------------------------------------------------------------- /Models/ExportInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net.Mail; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using System.Web; 9 | using System.Web.Configuration; 10 | using DotNetNuke.Entities.Users; 11 | using DotNetNuke.Entities.Portals; 12 | 13 | namespace forDNN.Modules.UsersExportImport.Models 14 | { 15 | public class ExportInfo 16 | { 17 | public int ExportFileType { get; set; } 18 | public bool IncludeSuperUsers { get; set; } 19 | public bool IncludeDeleted { get; set; } 20 | public bool IncludeNonAuthorised { get; set; } 21 | public bool ExportRoles { get; set; } 22 | public bool ExportPasswords { get; set; } 23 | public string PropertiesToExport { get; set; } 24 | public int ExportByRole { get; set; } 25 | public bool ExportCreatedDate { get; set; } 26 | } 27 | } -------------------------------------------------------------------------------- /obj/Debug/UsersExportImport.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\Work\Projects\DNNstudio\UsersExportImport\bin\forDNN.Modules.UsersExportImport.dll 2 | D:\Work\Projects\DNNstudio\UsersExportImport\bin\forDNN.Modules.UsersExportImport.pdb 3 | D:\Work\Projects\DNNstudio\UsersExportImport\obj\Debug\forDNN.Modules.UsersExportImport.dll 4 | D:\Work\Projects\DNNstudio\UsersExportImport\obj\Debug\forDNN.Modules.UsersExportImport.pdb 5 | D:\Work\Projects\DNNstudio\UsersExportImport\obj\Debug\UsersExportImport.csprojResolveAssemblyReference.cache 6 | D:\Work\Projects\forDNN\UsersExportImport\obj\Debug\forDNN.Modules.UsersExportImport.dll 7 | D:\Work\Projects\forDNN\UsersExportImport\obj\Debug\forDNN.Modules.UsersExportImport.pdb 8 | D:\Work\Projects\forDNN\UsersExportImport\bin\forDNN.Modules.UsersExportImport.dll 9 | D:\Work\Projects\forDNN\UsersExportImport\bin\forDNN.Modules.UsersExportImport.pdb 10 | D:\Work\Projects\forDNN\UsersExportImport\obj\Debug\UsersExportImport.csprojResolveAssemblyReference.cache 11 | -------------------------------------------------------------------------------- /UsersExportImport.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsersExportImport", "UsersExportImport.csproj", "{83108CB8-3DF3-4332-9AF3-FCFFB133CFFA}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {83108CB8-3DF3-4332-9AF3-FCFFB133CFFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {83108CB8-3DF3-4332-9AF3-FCFFB133CFFA}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {83108CB8-3DF3-4332-9AF3-FCFFB133CFFA}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {83108CB8-3DF3-4332-9AF3-FCFFB133CFFA}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /SQL/UpdatePortals.SqlDataProvider: -------------------------------------------------------------------------------- 1 | if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}{objectQualifier}UpdateUserPortals') and OBJECTPROPERTY(id, N'IsProcedure') = 1) 2 | drop procedure {databaseOwner}{objectQualifier}UpdateUserPortals 3 | GO 4 | 5 | GO 6 | SET QUOTED_IDENTIFIER OFF 7 | GO 8 | SET ANSI_NULLS OFF 9 | GO 10 | CREATE PROCEDURE {databaseOwner}{objectQualifier}UpdateUserPortals 11 | @PortalID [int], 12 | @UserName [nvarchar] (50) 13 | AS 14 | DECLARE @UserID int; 15 | 16 | SELECT @UserID = UserID 17 | FROM {databaseOwner}{objectQualifier}users 18 | WHERE Username = @UserName; 19 | 20 | IF(NOT EXISTS(SELECT PortalID FROM {databaseOwner}{objectQualifier}UserPortals WHERE (UserID=@UserID) AND (PortalID=@PortalID))) AND (@UserID IS NOT NULL) 21 | BEGIN 22 | INSERT INTO {databaseOwner}{objectQualifier}UserPortals (UserID, PortalID, CreatedDate, Authorised, IsDeleted, RefreshRoles) 23 | VALUES(@UserID, @PortalID, GETDATE(), 1, 0, 0); 24 | END; 25 | GO 26 | SET QUOTED_IDENTIFIER OFF 27 | GO 28 | SET ANSI_NULLS ON 29 | -------------------------------------------------------------------------------- /obj/Debug/ImportUsers_.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\WORK\Projects\SalarO\ImportUsers\ImportUsers_\ImportUsers_\bin\forDNN.Modules.ImportUsers_.dll 2 | D:\WORK\Projects\SalarO\ImportUsers\ImportUsers_\ImportUsers_\bin\forDNN.Modules.ImportUsers_.pdb 3 | D:\WORK\Projects\SalarO\ImportUsers\ImportUsers_\ImportUsers_\obj\Debug\ResolveAssemblyReference.cache 4 | D:\WORK\Projects\SalarO\ImportUsers\ImportUsers_\ImportUsers_\obj\Debug\forDNN.Modules.ImportUsers_.dll 5 | D:\WORK\Projects\SalarO\ImportUsers\ImportUsers_\ImportUsers_\obj\Debug\forDNN.Modules.ImportUsers_.pdb 6 | D:\WORK\Projects\DotNetNukeStudio\ImportUsers_\ImportUsers_\bin\forDNN.Modules.ImportUsers_.dll 7 | D:\WORK\Projects\DotNetNukeStudio\ImportUsers_\ImportUsers_\bin\forDNN.Modules.ImportUsers_.pdb 8 | D:\WORK\Projects\DotNetNukeStudio\ImportUsers_\ImportUsers_\obj\Debug\ResolveAssemblyReference.cache 9 | D:\WORK\Projects\DotNetNukeStudio\ImportUsers_\ImportUsers_\obj\Debug\forDNN.Modules.ImportUsers_.dll 10 | D:\WORK\Projects\DotNetNukeStudio\ImportUsers_\ImportUsers_\obj\Debug\forDNN.Modules.ImportUsers_.pdb 11 | -------------------------------------------------------------------------------- /Install/Examples/Users_ExpotImport_XML_Example.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Install/UsersExportImport.dnn: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | forDNN.UsersExportImport 5 | forDNN.UsersExportImport 6 | forDNN.UsersExportImport 7 | forDNN.UsersExportImport 8 | This module allows to export/import users, user profiles properties and roles to DotNetNuke from CSV/XML files. This is simple and fast way to create your users accounts in one click. 9 | 01.01.05 10 | resources.zip 11 | 12 | 13 | forDNN.UsersExportImport 14 | 0 15 | 16 | 17 | DesktopModules/forDNN.UsersExportImport/MainControl.ascx 18 | View 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | forDNN.Modules.UsersExportImport.dll 27 | 28 | 29 | MainControl.ascx 30 | 31 | 32 | App_LocalResources 33 | MainControl.ascx.resx 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /UsersExportImport.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | C:\WebSites\dnn981\bin\ 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | CurrentPage 14 | True 15 | False 16 | False 17 | False 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | False 27 | True 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 | 20 | 21 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("forDNN.UsersExportImport")] 9 | [assembly: AssemblyDescription("This module allows to export/import users, user profiles properties and roles to DNN (former DotNetNuke) from CSV/XML files. This is simple and fast way to create your users accounts in one click.")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("forDNN")] 12 | [assembly: AssemblyProduct("Users Export/Import for DNN (former DotNetNuke)")] 13 | [assembly: AssemblyCopyright("(c) forDNN 2003-2024")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: GuidAttribute("a9a2f906-2bbe-44fa-9c6d-4c3137d872a8")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | 23 | // Version information for an assembly consists of the following four values: 24 | // 25 | // Major Version 26 | // Minor Version 27 | // Build Number 28 | // Revision 29 | // 30 | // You can specify all the values or you can default the Revision and Build Numbers 31 | // by using the '*' as shown below: 32 | [assembly: AssemblyVersion("1.2.9.*")] 33 | -------------------------------------------------------------------------------- /WebApi/ExportImportApiController.cs: -------------------------------------------------------------------------------- 1 | using DotNetNuke.Web.Api; 2 | using DotNetNuke.Security; 3 | using System.Net; 4 | using System.Net.Http; 5 | using System.Web.Http; 6 | 7 | namespace forDNN.Modules.UsersExportImport.WebApi 8 | { 9 | [SupportedModules("forDNN.UsersExportImport")] 10 | public class ExportImportController : DnnApiController 11 | { 12 | [HttpPost] 13 | [ActionName("DoExport")] 14 | [ValidateAntiForgeryToken] 15 | [DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)] 16 | public HttpResponseMessage DoExport([FromBody]Models.ExportInfo objValues) 17 | { 18 | try 19 | { 20 | return Request.CreateResponse(HttpStatusCode.OK, Controller.ExportController.DoExport(this.PortalSettings.PortalId, objValues)); 21 | } 22 | catch (System.Exception ex) 23 | { 24 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); 25 | return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); 26 | } 27 | } 28 | 29 | [HttpPost] 30 | [ActionName("DoImport")] 31 | [ValidateAntiForgeryToken] 32 | [DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)] 33 | public HttpResponseMessage DoImport() 34 | { 35 | try 36 | { 37 | string LocalResourceFile = CommonController.ResolveUrl("App_LocalResources/MainControl", true); 38 | string Result = CommonController.DoImport(this.PortalSettings, LocalResourceFile, this.UserInfo); 39 | return Request.CreateResponse(HttpStatusCode.OK, Result); 40 | } 41 | catch (System.Exception ex) 42 | { 43 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); 44 | return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); 45 | } 46 | } 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /MainControl.ascx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Web.UI; 4 | using System.Web.UI.WebControls; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Reflection; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | 11 | using DotNetNuke; 12 | using DotNetNuke.Common.Utilities; 13 | using DotNetNuke.Security; 14 | using DotNetNuke.Services.Exceptions; 15 | using DotNetNuke.Services.Localization; 16 | using DotNetNuke.Entities.Users; 17 | using DotNetNuke.Entities.Portals; 18 | using DotNetNuke.Entities.Modules; 19 | using DotNetNuke.Entities.Profile; 20 | using DotNetNuke.Entities.Modules.Actions; 21 | using DotNetNuke.UI.UserControls; 22 | 23 | using DotNetNuke.Security.Roles; 24 | 25 | 26 | namespace forDNN.Modules.UsersExportImport 27 | { 28 | partial class MainControl : PortalModuleBase, IActionable 29 | { 30 | 31 | #region "Event Handlers" 32 | 33 | private void FillProperties() 34 | { 35 | ProfilePropertyDefinitionCollection lst = new ProfilePropertyDefinitionCollection(); 36 | foreach (ProfilePropertyDefinition ppd in ProfileController.GetPropertyDefinitionsByPortal(this.PortalId)) 37 | { 38 | if (ppd.Deleted) continue; 39 | lst.Add(ppd); 40 | } 41 | 42 | cblPropertiesToExport.DataSource = lst; 43 | cblPropertiesToExport.DataTextField = "PropertyName"; 44 | cblPropertiesToExport.DataValueField = "PropertyDefinitionId"; 45 | cblPropertiesToExport.DataBind(); 46 | } 47 | 48 | 49 | 50 | private void ExtraPageLoad() 51 | { 52 | lblIcon.Visible = true; 53 | lblIcon.Style["display"] = "block"; 54 | lblIcon.Text = ""; 55 | 56 | lnkExampleCSV.NavigateUrl = ResolveUrl("Examples/Users_ExpotImport_CSV_Example.csv"); 57 | lnkExampleXML.NavigateUrl = ResolveUrl("Examples/Users_ExpotImport_XML_Example.xml"); 58 | 59 | cbImportProfileProperties.Attributes.Add("onchange", 60 | string.Format("javascript:importProfileProperties('#{0}', '#{1}');", cbImportProfileProperties.ClientID, cbCreateMissedProfileProperties.ClientID)); 61 | 62 | lblMaxAllowedFileSize.Text = string.Format(Localization.GetString("MaxAllowedFileSize", this.LocalResourceFile), CommonController.GetMaxAllowedFileSize()); 63 | 64 | if (this.UserInfo != null) 65 | { 66 | divIncludeSuperUsers.Visible = this.UserInfo.IsSuperUser; 67 | } 68 | 69 | if (!IsPostBack) 70 | { 71 | FillProperties(); 72 | 73 | cbPropertiesToExport.Attributes.Add("onchange", 74 | string.Format("javascript:$('#divPropertiesToExport input').prop('checked', $('#{0}').is(':checked'));", cbPropertiesToExport.ClientID)); 75 | 76 | if (!DotNetNuke.Security.Membership.MembershipProviderConfig.PasswordRetrievalEnabled) 77 | { 78 | cbExportPasswords.Enabled = false; 79 | lblExportPasswordsDisabled.Visible = true; 80 | } 81 | } 82 | 83 | ddlExportByRole.Items.Clear(); 84 | ddlExportByRole.Items.Add(new ListItem(Localization.GetString("AllRoles", this.LocalResourceFile), "-1")); 85 | RoleController objRoleController = new RoleController(); 86 | foreach (RoleInfo objRole in objRoleController.GetRoles(this.PortalId)) 87 | { 88 | ddlExportByRole.Items.Add(new ListItem(objRole.RoleName, objRole.RoleID.ToString())); 89 | } 90 | 91 | btnExportUsers.Attributes.Add("onclick", string.Format("javascript:return doExport({0});", this.ModuleId)); 92 | btnImport.Attributes.Add("onclick", string.Format("javascript:return doImport({0});", this.ModuleId)); 93 | } 94 | 95 | protected void Page_Load(object sender, System.EventArgs e) 96 | { 97 | try 98 | { 99 | ExtraPageLoad(); 100 | } 101 | 102 | catch (Exception exc) 103 | { 104 | //Module failed to load 105 | Exceptions.ProcessModuleLoadException(this, exc); 106 | } 107 | } 108 | 109 | #endregion 110 | 111 | #region "Optional Interfaces" 112 | 113 | /// ----------------------------------------------------------------------------- 114 | /// 115 | /// Registers the module actions required for interfacing with the portal framework 116 | /// 117 | /// 118 | /// 119 | /// 120 | /// 121 | /// 122 | /// ----------------------------------------------------------------------------- 123 | public ModuleActionCollection ModuleActions 124 | { 125 | get 126 | { 127 | ModuleActionCollection Actions = new ModuleActionCollection(); 128 | //Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), 129 | // ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit, 130 | // true, false); 131 | return Actions; 132 | } 133 | } 134 | 135 | #endregion 136 | 137 | } 138 | 139 | } -------------------------------------------------------------------------------- /UsersExportImport.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 9.0.30729 8 | 2.0 9 | {83108CB8-3DF3-4332-9AF3-FCFFB133CFFA} 10 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 11 | Library 12 | Properties 13 | forDNN.Modules.UsersExportImport 14 | forDNN.Modules.UsersExportImport 15 | 16 | 17 | 3.5 18 | 19 | 20 | v4.7.2 21 | 22 | false 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | true 31 | full 32 | bin\ 33 | TRACE;DEBUG 34 | prompt 35 | 4 36 | 37 | 38 | false 39 | 40 | 41 | pdbonly 42 | true 43 | bin\ 44 | prompt 45 | 4 46 | false 47 | 48 | 49 | 50 | False 51 | ..\..\..\bin\dotnetnuke.dll 52 | False 53 | 54 | 55 | False 56 | ..\..\..\..\WebSites\unpsa2\bin\DotNetNuke.Web.dll 57 | 58 | 59 | False 60 | ..\..\bin\Microsoft.ApplicationBlocks.Data.dll 61 | False 62 | 63 | 64 | False 65 | ..\..\..\..\WebSites\unpsa2\bin\Newtonsoft.Json.dll 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | False 80 | ..\..\..\..\WebSites\dnn910\bin\System.Web.Http.dll 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | MainControl.ascx 96 | ASPXCodeBehind 97 | 98 | 99 | MainControl.ascx 100 | 101 | 102 | 103 | 104 | 105 | 106 | Designer 107 | 108 | 109 | Designer 110 | 111 | 112 | 113 | web.config 114 | 115 | 116 | web.config 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 10.0 125 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 126 | 127 | 128 | 129 | 130 | 137 | 138 | 139 | 140 | 141 | False 142 | True 143 | 62596 144 | / 145 | http://production.local/482/DesktopModules/ImportUsers_ 146 | True 147 | http://production.local/482 148 | False 149 | False 150 | 151 | 152 | False 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /Components/ExportController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections; 4 | using System.Linq; 5 | using System.Net.Mail; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using System.Web; 9 | using System.Web.Configuration; 10 | using DotNetNuke.Entities.Users; 11 | using DotNetNuke.Entities.Portals; 12 | using DotNetNuke.Entities.Profile; 13 | using System.Collections.Generic; 14 | 15 | namespace forDNN.Modules.UsersExportImport.Controller 16 | { 17 | public class ExportController 18 | { 19 | #region Export 20 | 21 | public static string DoExport(int PortalId, Models.ExportInfo objExportInfo) 22 | { 23 | string ResultURL = ""; 24 | try 25 | { 26 | IDataReader idr = null; 27 | 28 | //get ProfileProperties with type List 29 | string sqlProfilePropertiesList = @" 30 | SELECT DISTINCT CAST(l.EntryID AS int) EntryID, [Value] 31 | FROM {databaseOwner}{objectQualifier}ProfilePropertyDefinition ppd 32 | LEFT JOIN {databaseOwner}{objectQualifier}Lists l ON (ppd.DataType=l.EntryID) AND (l.ListName='DataType') 33 | WHERE ppd.PortalID=0 34 | AND ppd.Deleted=0 35 | AND (l.Value in (SELECT DISTINCT ListName FROM {databaseOwner}{objectQualifier}Lists WHERE (ListName<>'DataType'))) 36 | "; 37 | idr = DotNetNuke.Data.DataProvider.Instance().ExecuteSQL(sqlProfilePropertiesList); 38 | List lstProfilePropertiesList = new List(); 39 | List lstProfilePropertiesNames = new List(); 40 | while (idr.Read()) 41 | { 42 | lstProfilePropertiesList.Add(idr.GetInt32(0)); 43 | lstProfilePropertiesNames.Add(idr.GetString(1)); 44 | } 45 | 46 | //check if IsDeleted column exists 47 | bool IsDeletedExists = true; 48 | try 49 | { 50 | idr = DotNetNuke.Data.DataProvider.Instance().ExecuteSQL("SELECT TOP 1 IsDeleted FROM {databaseOwner}{objectQualifier}vw_Users"); 51 | } 52 | catch 53 | { 54 | IsDeletedExists = false; 55 | } 56 | 57 | //build dynamic query to retireve data 58 | Hashtable htFieldNames = new Hashtable(); 59 | htFieldNames["UserID"] = 1; 60 | htFieldNames["UserName"] = 1; 61 | htFieldNames["FirstName"] = 1; 62 | htFieldNames["LastName"] = 1; 63 | htFieldNames["DisplayName"] = 1; 64 | htFieldNames["IsSuperUser"] = 1; 65 | htFieldNames["Email"] = 1; 66 | htFieldNames["AffiliateId"] = 1; 67 | htFieldNames["Authorised"] = 1; 68 | 69 | StringBuilder sbSelect = new StringBuilder( 70 | @"SELECT u.UserID, 71 | u.UserName, 72 | u.FirstName, 73 | u.LastName, 74 | u.DisplayName, 75 | u.IsSuperUser, 76 | u.Email, 77 | u.AffiliateId, 78 | u.Authorised"); 79 | 80 | StringBuilder sbFrom = new StringBuilder(@" 81 | FROM {databaseOwner}{objectQualifier}vw_Users u "); 82 | StringBuilder sbWhere = new StringBuilder(@" 83 | WHERE (1=1) 84 | AND ((u.PortalId={0}) OR (u.IsSuperUser=1)) ".Replace("{0}", PortalId.ToString())); 85 | 86 | //check SuperUsers 87 | if (!objExportInfo.IncludeSuperUsers) 88 | { 89 | sbWhere.Append(" AND (u.IsSuperUser=0) "); 90 | } 91 | 92 | //check deleted accounts 93 | if (IsDeletedExists) 94 | { 95 | sbSelect.Append(", u.IsDeleted"); 96 | if (!objExportInfo.IncludeDeleted) 97 | { 98 | sbWhere.Append(" AND (u.IsDeleted=0) "); 99 | } 100 | htFieldNames["IsDeleted"] = 1; 101 | } 102 | 103 | //check authorised accounts 104 | if (!objExportInfo.IncludeNonAuthorised) 105 | { 106 | sbWhere.Append(" AND ((u.Authorised=1) OR (u.IsSuperUser=1)) "); 107 | } 108 | 109 | //check if requires to export roles 110 | if (objExportInfo.ExportRoles) 111 | { 112 | sbSelect.Append(@", (SELECT CAST(ur.RoleID AS nvarchar(10)) + ',' 113 | FROM {databaseOwner}{objectQualifier}UserRoles ur 114 | WHERE (ur.UserID=u.UserID) AND (ur.RoleID IN (SELECT r.RoleID FROM {databaseOwner}{objectQualifier}Roles r WHERE (r.PortalID={0}))) 115 | FOR XML PATH('')) RoleIDs, 116 | 117 | (SELECT r.RoleName + ',' 118 | FROM {databaseOwner}{objectQualifier}UserRoles ur 119 | LEFT JOIN {databaseOwner}{objectQualifier}Roles r ON (ur.RoleID=r.RoleID) 120 | WHERE (ur.UserID=u.UserID) AND (ur.RoleID IN (SELECT r.RoleID FROM {databaseOwner}{objectQualifier}Roles r WHERE (r.PortalID={0}))) 121 | FOR XML PATH('')) Roles 122 | ").Replace("{0}", PortalId.ToString()); 123 | 124 | htFieldNames["RoleIDs"] = 1; 125 | htFieldNames["Roles"] = 1; 126 | } 127 | 128 | //define properties 129 | foreach (string li in objExportInfo.PropertiesToExport.Split(new char[] { ',' })) 130 | { 131 | if (li.Trim() == "") continue; 132 | 133 | string[] objParam = li.Split(new char[] { '=' }); 134 | if (htFieldNames[objParam[0]] != null) 135 | { 136 | continue; 137 | } 138 | 139 | htFieldNames[objParam[0]] = 1; 140 | 141 | sbSelect.Append(", up{0}.PropertyValue [{1}] " 142 | .Replace("{0}", objParam[1]) 143 | .Replace("{1}", objParam[0]) 144 | ); 145 | 146 | sbFrom.Append(" LEFT JOIN {databaseOwner}{objectQualifier}UserProfile up{0} ON ((u.UserID=up{0}.UserID) AND (up{0}.PropertyDefinitionID={0})) " 147 | .Replace("{0}", objParam[1])); 148 | 149 | ProfilePropertyDefinition objProperty = 150 | ProfileController.GetPropertyDefinitionByName(PortalId, objParam[0]); 151 | int ListID = lstProfilePropertiesList.IndexOf(objProperty.DataType); 152 | if (ListID>=0) 153 | { 154 | string ListName = lstProfilePropertiesNames[ListID]; 155 | //have to add column with "_Text" for "Lists" 156 | sbSelect.Append(", l{0}.Text [{1}_Text]" 157 | .Replace("{0}", objParam[1]) 158 | .Replace("{1}", objParam[0]) 159 | ); 160 | 161 | sbFrom.Append(" LEFT JOIN {databaseOwner}{objectQualifier}Lists l{0} ON (l{0}.ListName='{1}') AND (CAST(l{0}.EntryID AS nvarchar)=CAST(up{0}.PropertyValue AS nvarchar)) " 162 | .Replace("{0}", objParam[1]) 163 | .Replace("{1}", ListName) 164 | ); 165 | } 166 | } 167 | 168 | if (objExportInfo.ExportByRole != -1) 169 | { 170 | sbWhere.Append(" AND (u.UserID IN (SELECT UserID FROM {databaseOwner}{objectQualifier}UserRoles WHERE RoleID={0})) " 171 | .Replace("{0}", objExportInfo.ExportByRole.ToString())); 172 | } 173 | 174 | if (objExportInfo.ExportCreatedDate) 175 | { 176 | sbSelect.Append(", u.CreatedOnDate"); 177 | htFieldNames["CreatedOnDate"] = 1; 178 | } 179 | 180 | idr = DotNetNuke.Data.DataProvider.Instance().ExecuteSQL(sbSelect.ToString() + sbFrom.ToString() + sbWhere.ToString()); 181 | DataTable dt = DotNetNuke.Common.Globals.ConvertDataReaderToDataTable(idr); 182 | if (objExportInfo.ExportPasswords) 183 | { 184 | dt = AddPasswordsColumn(PortalId, dt); 185 | } 186 | 187 | 188 | 189 | string strResult = ""; 190 | 191 | switch (objExportInfo.ExportFileType) 192 | { 193 | case 0://temporary disabled for Excel 194 | break; 195 | case 1://XML - FOR XML RAW 196 | strResult = CommonController.ToXML(dt); 197 | ResultURL = CommonController.SaveFile(PortalId, 198 | strResult, 199 | string.Format("Users_{0:ddMMyyyy_HHmmss}_{1}.xml", DateTime.Now, System.Guid.NewGuid().ToString())); 200 | break; 201 | case 2://CSV 202 | strResult = CommonController.ToCSV(dt, true, ","); 203 | ResultURL = CommonController.SaveFile(PortalId, 204 | strResult, 205 | string.Format("Users_{0:ddMMyyyy_HHmmss}_{1}.csv", DateTime.Now, System.Guid.NewGuid().ToString())); 206 | break; 207 | } 208 | } 209 | catch (System.Exception ex) 210 | { 211 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); 212 | } 213 | 214 | return ResultURL; 215 | } 216 | 217 | private static DataTable AddPasswordsColumn(int PortalId, DataTable dt) 218 | { 219 | dt.Columns.Add("Password", "".GetType()); 220 | 221 | foreach (DataRow dr in dt.Rows) 222 | { 223 | if (DotNetNuke.Security.Membership.MembershipProviderConfig.PasswordRetrievalEnabled) 224 | { 225 | UserInfo objUser = UserController.GetUserById(PortalId, (int)dr["userid"]); 226 | dr["Password"] = UserController.GetPassword(ref objUser, objUser.Membership.PasswordAnswer); 227 | } 228 | else 229 | { 230 | dr["Password"] = ""; 231 | } 232 | } 233 | 234 | return dt; 235 | } 236 | 237 | #endregion 238 | 239 | } 240 | } -------------------------------------------------------------------------------- /Install/_UsersExportImport.dnn: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | forDNN.UsersExportImport 5 | This module allows to export/import users, user profiles properties and roles to DNN (former DotNetNuke) from CSV/XML files. This is simple and fast way to create your users accounts in one click. 6 | 7 | Sergiy Velychko 8 | forDNN Team 9 | <a href="http://forDNN.com" target="_blank">http://forDNN.com</a> 10 | support@forDNN.com 11 | 12 | 13 | Copyright (c) 2024, forDNN Team<br/> 14 | All rights reserved.<br/> 15 | <br/> 16 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:<br/> 17 | <br/> 18 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.<br/> 19 | <br/> 20 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.<br/> 21 | <br/> 22 | * Neither the name of forDNN Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.<br/> 23 | <br/> 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | 27 | Version 1.2.9:
29 | Fixed an issue with exporting deleted User Profile Properties (https://github.com/fordnn/usersexportimport/issues/18)
30 | Fixed an issue with importing "PreferredLocale" from CSV file (https://github.com/fordnn/usersexportimport/issues/17)
31 | Tested with DotNetNuke version 9.13.2
32 | 33 | Version 1.2.8:
34 | Fixed an issue with multiple fields with the same types "List" instead of numeric values (for example "Country", "Country2", "Region")
35 | 36 | Version 1.2.7:
37 | Export text values for Profile Properties with type "List" instead of numeric values (for example "Country", "Region")
38 | Fixed an issue with order of the Profile Properties columns for export
39 | Accepted pull request #13: include "CreatedOnDate" column into export
40 | 41 | Version 1.2.6:
42 | Fixed an issue with Import for existing users
43 | 44 | Version 1.2.5:
45 | Added support for DNN 9.8.1
46 | New feature "Export Users By Role"
47 | Fixed an issue with Export for SuperUsers account
48 | Fixed an issue with Import for version of DNN 9.8.1
49 | 50 | Version 1.2.4:
51 | Fixed an issue when CSV generated on UNIX systems (different NewLine)
52 | Fixed an issue when updating custom profiles on existing users accounts
53 | 54 | Version 1.2.3:
55 | New feature Auto Update Existing users when UserName already exists
56 | 57 | Version 1.2.2:
58 | Fixed an issue in import process for child portals, when no default roles in system (no Admins role)
59 | 60 | Version 1.2.1:
61 | Added auto create role on roles import. 62 | Tested with recent version of DNN 9.6.2
63 | 64 | Version 1.2.0:
65 | Added security check on roles import. It prevents from importing to system users with Admin and SuperUsers rights without necessary permissions.
66 | Tested with recent version of DNN 9.4.4
67 | 68 | Version 1.1.7:
69 | Fixed issue with special chars "Zero width space" and "Zero width no-break space" in the names of the columns.
70 | Improved import process when missed some required columns: DisplayName, IsSuperUser, Username, AffiliateId.
71 | 72 | Version 1.1.6:
73 | Added export support for versions 9.x.
74 | 75 | Version 1.1.5:
76 | Fixed an issue with multi portals DNN installation (there were dublicates of the users).
77 | Added notification on maximum allowed file size for import.
78 | 79 | Version 1.1.4:
80 | Fixed an issue with CSV export for passwords column.
81 | Fixed an issue with {objectQualifier}.
82 | 83 | Version 1.1.3:
84 | Fixed an issue with CSV export (was missed last column).
85 | 86 | Version 1.1.2:
87 | Added email verification (for blank and valid format) before notification for imported users
88 | 89 | Version 1.1.1:
90 | Added email notification for imported users
91 | Added possibility to include new password into email notification with token [User:Password].
92 | Redesigned export/import forms for DNN 7 style.
93 | Added documentation for export/import options.
94 | 95 | Version 1.1.0:
96 | Added support for DNN versions 7.x up to DNN 07.03.02.
97 | Added feature to generate random password on users import process.
98 | Added feature to set "Force Change Password On" on user import process.
99 | Examples of template for import process are available to download directly at the "Import Users" form.
100 | ]]>
101 | 102 | 103 | 104 | forDNN.UsersExportImport 105 | forDNN.UsersExportImport 106 | 107 | 108 | 109 | 110 | forDNN.UsersExportImport 111 | 0 112 | 113 | 114 | 115 | DesktopModules/forDNN.UsersExportImport/MainControl.ascx 116 | False 117 | 118 | View 119 | 120 | 121 | 0 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | bin 131 | 132 | bin 133 | forDNN.Modules.UsersExportImport.dll 134 | 135 | 136 | 137 | 138 | 139 | DesktopModules\forDNN.UsersExportImport 140 | 141 | App_LocalResources 142 | MainControl.ascx.resx 143 | 144 | 145 | MainControl.ascx 146 | 147 | 148 | 149 | 150 | 151 | DesktopModules\forDNN.UsersExportImport 152 | 153 | resources.zip 154 | 155 | 156 | 157 | 158 |
159 |
160 |
-------------------------------------------------------------------------------- /MainControl.ascx: -------------------------------------------------------------------------------- 1 | <%@ Control Language="C#" Inherits="forDNN.Modules.UsersExportImport.MainControl" AutoEventWireup="true" 2 | CodeBehind="MainControl.ascx.cs" %> 3 | <%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %> 4 | 5 | 19 | 20 |
21 | 27 |
28 |
29 |
30 | 31 | 32 | 33 | 34 | 35 |
36 |
37 | 38 | 39 | 40 |
41 |
42 | 43 | 44 |
45 |
46 | 47 | 48 |
49 |
50 | 51 | 52 |
53 |
54 | 55 | 56 |
57 |
58 | 59 | 60 |
61 |
62 | 63 | 64 |
65 |
66 | 67 |
68 |
69 | 70 | 71 |
72 |
73 | 74 |
75 |
76 | 77 | 80 |
81 |
82 |
83 |
84 | 85 | 86 |
87 |
88 | 89 |
90 |
91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
99 |
100 | 101 | 102 |
103 |
104 | 105 | 106 |
107 |
108 | 109 | 110 |
111 |
112 | 113 | 114 |
115 |
116 | 117 | 118 |
119 |
120 | 121 | 122 |
123 |
124 |
125 | 126 |
127 |
128 |
129 | 130 |
131 | 132 |
133 |
134 |
135 |
136 | 137 |
138 | 139 |
140 |
141 | 142 |
143 | 144 | 277 | -------------------------------------------------------------------------------- /App_LocalResources/MainControl.ascx.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Create Missed Profile Properties 122 | 123 | 124 | Example Excel File 125 | 126 | 127 | Example of CSV file 128 | 129 | 130 | Examples: 131 | 132 | 133 | Example of XML file 134 | 135 | 136 | Export File Type 137 | 138 | 139 | Excel 140 | 141 | 142 | XML 143 | 144 | 145 | CSV 146 | 147 | 148 | Export Passwords 149 | 150 | 151 | Export Passwords disabled for this portal, because enablePasswordRetrieval="false" in web.config file. 152 | 153 | 154 | Export Roles 155 | 156 | 157 | Export Users 158 | 159 | 160 | Set "Force Password Change On" on import 161 | 162 | 163 | Select File for Import: 164 | 165 | 166 | Import File is Missed! 167 | 168 | 169 | Import Profile Properties 170 | 171 | 172 | Do not import roles 173 | 174 | 175 | Import roles by RoleID from the "RoleIDs" column 176 | 177 | 178 | Import roles by RoleName from the "Roles" column 179 | 180 | 181 | Import Users 182 | 183 | 184 | Include Deleted Accounts 185 | 186 | 187 | Include Non Authorised Accounts 188 | 189 | 190 | Include SuperUsers 191 | 192 | 193 | List of profile properties to export (check/uncheck all): 194 | 195 | 196 | Generate random passwords on import 197 | 198 | 199 | Total users to import: {0}<br>Success users have been imported: {1}<br/>{2} 200 | 201 | 202 | RoleID={0} not found <br/> 203 | 204 | 205 | RoleName={0} not found <br/> 206 | 207 | 208 | Line {0}. Import error "{1}"<br/> 209 | 210 | 211 | Line {0}, UserName={1}. Import error "{2}"<br/> 212 | 213 | 214 | Line {0}, UserID={1}, updating roles error "{2}"<br/> 215 | 216 | 217 | When checked and due import process any profile property is absent for current portal, then this profile property will be automatically added. 218 | 219 | 220 | On success import an email will be sent to the user. Templates for subject and body can be defined in the localization "EmailUserSubject" and "EmailUserBody" entries. In the template can be used standard DNN tokens, like: [Portal:PortalName], [User:DisplayName], etc. For new generated passwords please use token [User:Password]. 221 | 222 | 223 | Email user after import 224 | 225 | 226 | Dear [User:DisplayName] your new password for [Portal:PortalName] is <b>[User:Password]</b> 227 | 228 | 229 | You have new password for [Portal:PortalName] 230 | 231 | 232 | Examples of the files to import. 233 | 234 | 235 | Type of file data will be exported to. There are 2 possible types: CSV and XML. 236 | 237 | 238 | Allows to export passwords. This option is available only when "enablePasswordRetrieval" in web.config is "true". 239 | 240 | 241 | Check this to include users roles into the exported list. When checked, resulted list will contain two extra fields: "RoleIDs" (contains comma delimited RoleIDs) and Roles (contains comma delimited RoleNames). 242 | 243 | 244 | When checked it sets "Force Password Change On" for all imported users, so users must change password on next login. 245 | 246 | 247 | File with users list to import. 248 | 249 | 250 | Check this to import users profile properties. 251 | 252 | 253 | The method how roles should be imported. 254 | 255 | 256 | Import roles 257 | 258 | 259 | Check this to include users accounts marked as "Deleted" into the exported list. 260 | 261 | 262 | Check this to include non-authorised users accounts into the exported list. 263 | 264 | 265 | Check this to include SuperUsers accounts into the exported list. 266 | 267 | 268 | Possible to define what users profile properties to include into the exported list. 269 | 270 | 271 | When checked it generates random password for all imported users. 272 | 273 | 274 | Line {0}, UserID={1}, SendEmail exception "{2}"<br/> 275 | 276 | 277 | Line {0}, UserID={1}, SendEmail exception due wrong email format "{2}"<br/> 278 | 279 | 280 | Max allowed file size for upload is {0} 281 | 282 | 283 | Export in progress... 284 | 285 | 286 | Line {0}: 287 | 288 | 289 | User "{0}" is denied to import "{1}"<br/> 290 | 291 | 292 | Import roles by RoleName from the "Roles" column (autocreate Role if it does not exist) 293 | 294 | 295 | Update existing user when UserName exists in DB 296 | 297 | 298 | Update existing user when UserName exists in DB 299 | 300 | 301 | All Roles 302 | 303 | 304 | Export By Role 305 | 306 | 307 | Export the date when the user account was created 308 | 309 | 310 | Export Created Date 311 | 312 | -------------------------------------------------------------------------------- /MainControl.ascx.designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // 5 | // Changes to this file may cause incorrect behavior and will be lost if 6 | // the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace forDNN.Modules.UsersExportImport 11 | { 12 | 13 | 14 | public partial class MainControl 15 | { 16 | 17 | /// 18 | /// lblExportUsers control. 19 | /// 20 | /// 21 | /// Auto-generated field. 22 | /// To modify move field declaration from designer file to code-behind file. 23 | /// 24 | protected global::System.Web.UI.WebControls.Label lblExportUsers; 25 | 26 | /// 27 | /// lblImportUsers control. 28 | /// 29 | /// 30 | /// Auto-generated field. 31 | /// To modify move field declaration from designer file to code-behind file. 32 | /// 33 | protected global::System.Web.UI.WebControls.Label lblImportUsers; 34 | 35 | /// 36 | /// lblExportFileType control. 37 | /// 38 | /// 39 | /// Auto-generated field. 40 | /// To modify move field declaration from designer file to code-behind file. 41 | /// 42 | protected global::System.Web.UI.UserControl lblExportFileType; 43 | 44 | /// 45 | /// ddlExportFileType control. 46 | /// 47 | /// 48 | /// Auto-generated field. 49 | /// To modify move field declaration from designer file to code-behind file. 50 | /// 51 | protected global::System.Web.UI.WebControls.DropDownList ddlExportFileType; 52 | 53 | /// 54 | /// lblbExportByRole control. 55 | /// 56 | /// 57 | /// Auto-generated field. 58 | /// To modify move field declaration from designer file to code-behind file. 59 | /// 60 | protected global::System.Web.UI.UserControl lblbExportByRole; 61 | 62 | /// 63 | /// ddlExportByRole control. 64 | /// 65 | /// 66 | /// Auto-generated field. 67 | /// To modify move field declaration from designer file to code-behind file. 68 | /// 69 | protected global::System.Web.UI.WebControls.DropDownList ddlExportByRole; 70 | 71 | /// 72 | /// divIncludeSuperUsers control. 73 | /// 74 | /// 75 | /// Auto-generated field. 76 | /// To modify move field declaration from designer file to code-behind file. 77 | /// 78 | protected global::System.Web.UI.HtmlControls.HtmlGenericControl divIncludeSuperUsers; 79 | 80 | /// 81 | /// lblIncludeSuperUsers control. 82 | /// 83 | /// 84 | /// Auto-generated field. 85 | /// To modify move field declaration from designer file to code-behind file. 86 | /// 87 | protected global::System.Web.UI.UserControl lblIncludeSuperUsers; 88 | 89 | /// 90 | /// cbIncludeSuperUsers control. 91 | /// 92 | /// 93 | /// Auto-generated field. 94 | /// To modify move field declaration from designer file to code-behind file. 95 | /// 96 | protected global::System.Web.UI.WebControls.CheckBox cbIncludeSuperUsers; 97 | 98 | /// 99 | /// lblIncludeDeleted control. 100 | /// 101 | /// 102 | /// Auto-generated field. 103 | /// To modify move field declaration from designer file to code-behind file. 104 | /// 105 | protected global::System.Web.UI.UserControl lblIncludeDeleted; 106 | 107 | /// 108 | /// cbIncludeDeleted control. 109 | /// 110 | /// 111 | /// Auto-generated field. 112 | /// To modify move field declaration from designer file to code-behind file. 113 | /// 114 | protected global::System.Web.UI.WebControls.CheckBox cbIncludeDeleted; 115 | 116 | /// 117 | /// lblIncludeNonAuthorised control. 118 | /// 119 | /// 120 | /// Auto-generated field. 121 | /// To modify move field declaration from designer file to code-behind file. 122 | /// 123 | protected global::System.Web.UI.UserControl lblIncludeNonAuthorised; 124 | 125 | /// 126 | /// cbIncludeNonAuthorised control. 127 | /// 128 | /// 129 | /// Auto-generated field. 130 | /// To modify move field declaration from designer file to code-behind file. 131 | /// 132 | protected global::System.Web.UI.WebControls.CheckBox cbIncludeNonAuthorised; 133 | 134 | /// 135 | /// lblExportCreatedDate control. 136 | /// 137 | /// 138 | /// Auto-generated field. 139 | /// To modify move field declaration from designer file to code-behind file. 140 | /// 141 | protected global::System.Web.UI.UserControl lblExportCreatedDate; 142 | 143 | /// 144 | /// cbExportCreatedDate control. 145 | /// 146 | /// 147 | /// Auto-generated field. 148 | /// To modify move field declaration from designer file to code-behind file. 149 | /// 150 | protected global::System.Web.UI.WebControls.CheckBox cbExportCreatedDate; 151 | 152 | /// 153 | /// lblExportRoles control. 154 | /// 155 | /// 156 | /// Auto-generated field. 157 | /// To modify move field declaration from designer file to code-behind file. 158 | /// 159 | protected global::System.Web.UI.UserControl lblExportRoles; 160 | 161 | /// 162 | /// cbExportRoles control. 163 | /// 164 | /// 165 | /// Auto-generated field. 166 | /// To modify move field declaration from designer file to code-behind file. 167 | /// 168 | protected global::System.Web.UI.WebControls.CheckBox cbExportRoles; 169 | 170 | /// 171 | /// lblExportPasswords control. 172 | /// 173 | /// 174 | /// Auto-generated field. 175 | /// To modify move field declaration from designer file to code-behind file. 176 | /// 177 | protected global::System.Web.UI.UserControl lblExportPasswords; 178 | 179 | /// 180 | /// cbExportPasswords control. 181 | /// 182 | /// 183 | /// Auto-generated field. 184 | /// To modify move field declaration from designer file to code-behind file. 185 | /// 186 | protected global::System.Web.UI.WebControls.CheckBox cbExportPasswords; 187 | 188 | /// 189 | /// lblExportPasswordsDisabled control. 190 | /// 191 | /// 192 | /// Auto-generated field. 193 | /// To modify move field declaration from designer file to code-behind file. 194 | /// 195 | protected global::System.Web.UI.WebControls.Label lblExportPasswordsDisabled; 196 | 197 | /// 198 | /// lblPropertiesToExport control. 199 | /// 200 | /// 201 | /// Auto-generated field. 202 | /// To modify move field declaration from designer file to code-behind file. 203 | /// 204 | protected global::System.Web.UI.UserControl lblPropertiesToExport; 205 | 206 | /// 207 | /// cbPropertiesToExport control. 208 | /// 209 | /// 210 | /// Auto-generated field. 211 | /// To modify move field declaration from designer file to code-behind file. 212 | /// 213 | protected global::System.Web.UI.WebControls.CheckBox cbPropertiesToExport; 214 | 215 | /// 216 | /// cblPropertiesToExport control. 217 | /// 218 | /// 219 | /// Auto-generated field. 220 | /// To modify move field declaration from designer file to code-behind file. 221 | /// 222 | protected global::System.Web.UI.WebControls.CheckBoxList cblPropertiesToExport; 223 | 224 | /// 225 | /// btnExportUsers control. 226 | /// 227 | /// 228 | /// Auto-generated field. 229 | /// To modify move field declaration from designer file to code-behind file. 230 | /// 231 | protected global::System.Web.UI.WebControls.HyperLink btnExportUsers; 232 | 233 | /// 234 | /// lblExportInProgress control. 235 | /// 236 | /// 237 | /// Auto-generated field. 238 | /// To modify move field declaration from designer file to code-behind file. 239 | /// 240 | protected global::System.Web.UI.WebControls.Label lblExportInProgress; 241 | 242 | /// 243 | /// lblImport control. 244 | /// 245 | /// 246 | /// Auto-generated field. 247 | /// To modify move field declaration from designer file to code-behind file. 248 | /// 249 | protected global::System.Web.UI.UserControl lblImport; 250 | 251 | /// 252 | /// objFile control. 253 | /// 254 | /// 255 | /// Auto-generated field. 256 | /// To modify move field declaration from designer file to code-behind file. 257 | /// 258 | protected global::System.Web.UI.HtmlControls.HtmlInputFile objFile; 259 | 260 | /// 261 | /// lblMaxAllowedFileSize control. 262 | /// 263 | /// 264 | /// Auto-generated field. 265 | /// To modify move field declaration from designer file to code-behind file. 266 | /// 267 | protected global::System.Web.UI.WebControls.Label lblMaxAllowedFileSize; 268 | 269 | /// 270 | /// lblImportRoles control. 271 | /// 272 | /// 273 | /// Auto-generated field. 274 | /// To modify move field declaration from designer file to code-behind file. 275 | /// 276 | protected global::System.Web.UI.UserControl lblImportRoles; 277 | 278 | /// 279 | /// rblImportRoles control. 280 | /// 281 | /// 282 | /// Auto-generated field. 283 | /// To modify move field declaration from designer file to code-behind file. 284 | /// 285 | protected global::System.Web.UI.WebControls.RadioButtonList rblImportRoles; 286 | 287 | /// 288 | /// lblImportProfileProperties control. 289 | /// 290 | /// 291 | /// Auto-generated field. 292 | /// To modify move field declaration from designer file to code-behind file. 293 | /// 294 | protected global::System.Web.UI.UserControl lblImportProfileProperties; 295 | 296 | /// 297 | /// cbImportProfileProperties control. 298 | /// 299 | /// 300 | /// Auto-generated field. 301 | /// To modify move field declaration from designer file to code-behind file. 302 | /// 303 | protected global::System.Web.UI.WebControls.CheckBox cbImportProfileProperties; 304 | 305 | /// 306 | /// lblUpdateExistingUser control. 307 | /// 308 | /// 309 | /// Auto-generated field. 310 | /// To modify move field declaration from designer file to code-behind file. 311 | /// 312 | protected global::System.Web.UI.UserControl lblUpdateExistingUser; 313 | 314 | /// 315 | /// cbUpdateExistingUser control. 316 | /// 317 | /// 318 | /// Auto-generated field. 319 | /// To modify move field declaration from designer file to code-behind file. 320 | /// 321 | protected global::System.Web.UI.WebControls.CheckBox cbUpdateExistingUser; 322 | 323 | /// 324 | /// lblCreateMissedProfileProperties control. 325 | /// 326 | /// 327 | /// Auto-generated field. 328 | /// To modify move field declaration from designer file to code-behind file. 329 | /// 330 | protected global::System.Web.UI.UserControl lblCreateMissedProfileProperties; 331 | 332 | /// 333 | /// cbCreateMissedProfileProperties control. 334 | /// 335 | /// 336 | /// Auto-generated field. 337 | /// To modify move field declaration from designer file to code-behind file. 338 | /// 339 | protected global::System.Web.UI.WebControls.CheckBox cbCreateMissedProfileProperties; 340 | 341 | /// 342 | /// lblRandomPassword control. 343 | /// 344 | /// 345 | /// Auto-generated field. 346 | /// To modify move field declaration from designer file to code-behind file. 347 | /// 348 | protected global::System.Web.UI.UserControl lblRandomPassword; 349 | 350 | /// 351 | /// cbRandomPassword control. 352 | /// 353 | /// 354 | /// Auto-generated field. 355 | /// To modify move field declaration from designer file to code-behind file. 356 | /// 357 | protected global::System.Web.UI.WebControls.CheckBox cbRandomPassword; 358 | 359 | /// 360 | /// lblForcePasswordChange control. 361 | /// 362 | /// 363 | /// Auto-generated field. 364 | /// To modify move field declaration from designer file to code-behind file. 365 | /// 366 | protected global::System.Web.UI.UserControl lblForcePasswordChange; 367 | 368 | /// 369 | /// cbForcePasswordChange control. 370 | /// 371 | /// 372 | /// Auto-generated field. 373 | /// To modify move field declaration from designer file to code-behind file. 374 | /// 375 | protected global::System.Web.UI.WebControls.CheckBox cbForcePasswordChange; 376 | 377 | /// 378 | /// lblEmailUser control. 379 | /// 380 | /// 381 | /// Auto-generated field. 382 | /// To modify move field declaration from designer file to code-behind file. 383 | /// 384 | protected global::System.Web.UI.UserControl lblEmailUser; 385 | 386 | /// 387 | /// cbEmailUser control. 388 | /// 389 | /// 390 | /// Auto-generated field. 391 | /// To modify move field declaration from designer file to code-behind file. 392 | /// 393 | protected global::System.Web.UI.WebControls.CheckBox cbEmailUser; 394 | 395 | /// 396 | /// btnImport control. 397 | /// 398 | /// 399 | /// Auto-generated field. 400 | /// To modify move field declaration from designer file to code-behind file. 401 | /// 402 | protected global::System.Web.UI.WebControls.LinkButton btnImport; 403 | 404 | /// 405 | /// lblExamples control. 406 | /// 407 | /// 408 | /// Auto-generated field. 409 | /// To modify move field declaration from designer file to code-behind file. 410 | /// 411 | protected global::System.Web.UI.UserControl lblExamples; 412 | 413 | /// 414 | /// lnkExampleCSV control. 415 | /// 416 | /// 417 | /// Auto-generated field. 418 | /// To modify move field declaration from designer file to code-behind file. 419 | /// 420 | protected global::System.Web.UI.WebControls.HyperLink lnkExampleCSV; 421 | 422 | /// 423 | /// lnkExampleXML control. 424 | /// 425 | /// 426 | /// Auto-generated field. 427 | /// To modify move field declaration from designer file to code-behind file. 428 | /// 429 | protected global::System.Web.UI.WebControls.HyperLink lnkExampleXML; 430 | 431 | /// 432 | /// lblResult control. 433 | /// 434 | /// 435 | /// Auto-generated field. 436 | /// To modify move field declaration from designer file to code-behind file. 437 | /// 438 | protected global::System.Web.UI.WebControls.Label lblResult; 439 | 440 | /// 441 | /// lblIcon control. 442 | /// 443 | /// 444 | /// Auto-generated field. 445 | /// To modify move field declaration from designer file to code-behind file. 446 | /// 447 | protected global::System.Web.UI.WebControls.Label lblIcon; 448 | } 449 | } 450 | -------------------------------------------------------------------------------- /Components/CommonController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Net.Mail; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using System.Web; 10 | using System.Web.Configuration; 11 | using DotNetNuke.Entities.Users; 12 | using DotNetNuke.Security.Roles; 13 | using DotNetNuke.Entities.Portals; 14 | using DotNetNuke.Services.Localization; 15 | using DotNetNuke.Entities.Profile; 16 | using DotNetNuke.Services.Exceptions; 17 | 18 | namespace forDNN.Modules.UsersExportImport 19 | { 20 | public class CommonController 21 | { 22 | #region Export functonality 23 | 24 | public static string ToXML(DataTable dt) 25 | { 26 | System.Xml.XmlDocument objDoc = new System.Xml.XmlDocument(); 27 | System.Xml.XmlElement objRoot = objDoc.CreateElement("users"); 28 | foreach (DataRow dr in dt.Rows) 29 | { 30 | System.Xml.XmlElement objUser = objDoc.CreateElement("user"); 31 | foreach (DataColumn dc in dt.Columns) 32 | { 33 | System.Xml.XmlAttribute objAttr = objDoc.CreateAttribute(dc.ColumnName); 34 | objAttr.Value = string.Format("{0}", dr[dc.ColumnName]); 35 | objUser.Attributes.Append(objAttr); 36 | } 37 | objRoot.AppendChild(objUser); 38 | } 39 | objDoc.AppendChild(objRoot); 40 | return objDoc.InnerXml; 41 | } 42 | 43 | public static string ToCSV(DataTable dt, bool includeHeaderAsFirstRow, string separator) 44 | { 45 | StringBuilder csvRows = new StringBuilder(); 46 | StringBuilder sb = null; 47 | int ColumnsCount = dt.Columns.Count; 48 | 49 | if (includeHeaderAsFirstRow) 50 | { 51 | sb = new StringBuilder(); 52 | for (int index = 0; index < ColumnsCount; index++) 53 | { 54 | if (dt.Columns[index].ColumnName != null) 55 | sb.Append(dt.Columns[index].ColumnName); 56 | 57 | if (index < ColumnsCount - 1) 58 | sb.Append(separator); 59 | } 60 | csvRows.AppendLine(sb.ToString()); 61 | } 62 | 63 | foreach (DataRow dr in dt.Rows) 64 | { 65 | sb = new StringBuilder(); 66 | for (int index = 0; index < ColumnsCount; index++) 67 | { 68 | string value = string.Format("{0}", dr[index]); 69 | if (dt.Columns[index].DataType == typeof(String)) 70 | { 71 | //If double quotes are used in value, ensure each are replaced but 2. 72 | if (value.IndexOf("\"") >= 0) 73 | value = value.Replace("\"", "\"\""); 74 | 75 | //If separtor are is in value, ensure it is put in double quotes. 76 | if (value.IndexOf(separator) >= 0) 77 | value = "\"" + value + "\""; 78 | } 79 | sb.Append(value); 80 | 81 | if (index < ColumnsCount - 1) 82 | sb.Append(separator); 83 | } 84 | 85 | csvRows.AppendLine(sb.ToString()); 86 | } 87 | sb = null; 88 | return csvRows.ToString(); 89 | } 90 | 91 | #endregion 92 | 93 | #region Import functionality 94 | 95 | private static string RemoveWhiteSpaces(string Source) 96 | { 97 | //remove Zero width space and Zero width no-break space 98 | return Source.Trim(new char[] { '\uFEFF', '\u200B', '\r' }); 99 | } 100 | 101 | private static DataTable CSV2Table(byte[] lstBytes) 102 | { 103 | string Separator = ","; 104 | 105 | DataTable dt = new DataTable(); 106 | 107 | string strTable = System.Text.Encoding.UTF8.GetString(lstBytes); 108 | string[] lstRows = strTable.Split(new string[] { "\n" }, StringSplitOptions.None); 109 | //replaced Environment.NewLine with \n, because UNIX formatting does not have \r character 110 | if (lstRows.Length == 0) 111 | { 112 | return dt; 113 | } 114 | 115 | foreach (string Header in lstRows[0].Split(new char[] { ',' })) 116 | { 117 | //lets remove white space chars from the column's name 118 | dt.Columns.Add(RemoveWhiteSpaces(Header)); 119 | } 120 | 121 | for (int i = 1; (i < lstRows.Length - 1); i++) 122 | { 123 | ArrayList lstValues = new ArrayList(); 124 | string Value = lstRows[i]; 125 | 126 | bool WithinQuotes = false; 127 | int k = 0; 128 | StringBuilder SubValue = new StringBuilder(); 129 | while (k < Value.Length) 130 | { 131 | if (Value[k].ToString() == Separator) 132 | { 133 | //check is it new column 134 | if (!WithinQuotes) 135 | { 136 | //yes, its new column 137 | lstValues.Add(SubValue.ToString()); 138 | SubValue = new StringBuilder(); 139 | k++; 140 | continue; 141 | } 142 | } 143 | 144 | if (Value[k].ToString() == "\"") 145 | { 146 | //check is it begin/end of new string column or just quote char 147 | if (k < Value.Length - 1) 148 | { 149 | if ((Value[k + 1].ToString() == "\"")) 150 | { 151 | //this is quote char, replace it with single quote and move cursor next to it 152 | SubValue.Append(Value[k]); 153 | k++; 154 | } 155 | else 156 | { 157 | //this is begin/end of new string column - skip quote char and reverse WithinQuotes flag 158 | WithinQuotes = !WithinQuotes; 159 | } 160 | } 161 | } 162 | else 163 | { 164 | SubValue.Append(Value[k]); 165 | } 166 | 167 | k++; 168 | } 169 | 170 | if (SubValue.ToString() != "") 171 | { 172 | lstValues.Add(SubValue.ToString()); 173 | } 174 | 175 | //add new row to DataTable 176 | DataRow dr = dt.NewRow(); 177 | for (k = 0; k < dt.Columns.Count; k++) 178 | { 179 | try 180 | { 181 | dr[k] = lstValues[k]; 182 | } 183 | catch (Exception Exc) 184 | { 185 | Exceptions.LogException(Exc); 186 | } 187 | } 188 | dt.Rows.Add(dr); 189 | } 190 | 191 | return dt; 192 | } 193 | 194 | private static DataTable XML2Table(byte[] lstBytes) 195 | { 196 | string strXML = System.Text.Encoding.UTF8.GetString(lstBytes); 197 | System.Xml.XmlDocument objDoc = new System.Xml.XmlDocument(); 198 | objDoc.LoadXml(strXML); 199 | 200 | DataTable dt = new DataTable(); 201 | bool RequireColumns = true; 202 | foreach (System.Xml.XmlNode xmlUser in objDoc.DocumentElement.ChildNodes) 203 | { 204 | if (RequireColumns) 205 | { 206 | foreach (System.Xml.XmlAttribute xmlAttr in xmlUser.Attributes) 207 | { 208 | dt.Columns.Add(xmlAttr.Name); 209 | } 210 | RequireColumns = false; 211 | } 212 | 213 | DataRow dr = dt.NewRow(); 214 | foreach (System.Xml.XmlAttribute xmlAttr in xmlUser.Attributes) 215 | { 216 | dr[xmlAttr.Name] = xmlAttr.Value; 217 | } 218 | dt.Rows.Add(dr); 219 | } 220 | 221 | return dt; 222 | } 223 | 224 | private static string ValidatePassword(UserInfo objUser, bool RandomPassword) 225 | { 226 | if (!RandomPassword) 227 | { 228 | objUser.Membership.Password = (objUser.Membership.Password == null) ? "" : objUser.Membership.Password; 229 | if (UserController.ValidatePassword(objUser.Membership.Password)) 230 | { 231 | return objUser.Membership.Password; 232 | } 233 | } 234 | return UserController.GeneratePassword(); 235 | } 236 | 237 | private static object GetDataRowValue(DataTable dt, DataRow dr, string FieldName, object DefaultValue) 238 | { 239 | if (dt.Columns.IndexOf(FieldName) == -1) 240 | { 241 | return DefaultValue; 242 | } 243 | return dr[FieldName]; 244 | } 245 | 246 | private static bool ObjectToBool(object Src) 247 | { 248 | string temp = string.Format("{0}", Src).ToLowerInvariant(); 249 | return (temp == "1") || (temp == "true"); 250 | } 251 | 252 | public static string DoImport(PortalSettings objPortalSettings, string LocalResourceFile, UserInfo currentUserInfo) 253 | { 254 | System.Web.HttpContext objContext = System.Web.HttpContext.Current; 255 | 256 | if (objContext.Request.Files.Count == 0) 257 | { 258 | return Localization.GetString("ImportFileMissed", LocalResourceFile); 259 | } 260 | 261 | bool UpdateExistingUser = Convert.ToBoolean(objContext.Request.Form["cbUpdateExistingUser"]); 262 | 263 | HttpPostedFile objFile = objContext.Request.Files[0]; 264 | 265 | System.IO.FileInfo objFileInfo = new System.IO.FileInfo(objFile.FileName); 266 | byte[] lstBytes = new byte[(int)objFile.InputStream.Length]; 267 | objFile.InputStream.Read(lstBytes, 0, (int)objFile.InputStream.Length); 268 | 269 | DataTable dt = null; 270 | 271 | switch (objFileInfo.Extension.ToLower()) 272 | { 273 | case ".csv": 274 | case ".txt": 275 | dt = CSV2Table(lstBytes); 276 | break; 277 | case ".xml": 278 | dt = XML2Table(lstBytes); 279 | break; 280 | } 281 | 282 | ProfilePropertyDefinition objOldUserID = DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(objPortalSettings.PortalId, "OldUserID"); 283 | if (objOldUserID == null) 284 | { 285 | objOldUserID = new ProfilePropertyDefinition(objPortalSettings.PortalId); 286 | objOldUserID.PropertyName = "OldUserID"; 287 | objOldUserID.PropertyCategory = "Imported"; 288 | objOldUserID.DataType = 349; 289 | DotNetNuke.Entities.Profile.ProfileController.AddPropertyDefinition(objOldUserID); 290 | } 291 | 292 | string NonProfileFields = ",userid,username,firstname,lastname,displayname,issuperuser,email,affiliateid,authorised,isdeleted,roleids,roles,"; 293 | 294 | string SubjectTemplate = Localization.GetString("EmailUserSubject", LocalResourceFile); 295 | string BodyTemplate = Localization.GetString("EmailUserBody", LocalResourceFile); 296 | 297 | int UsersCount = 0; 298 | int SuccessUsersCount = 0; 299 | StringBuilder FailedUsers = new StringBuilder(); 300 | 301 | foreach (DataRow dr in dt.Rows) 302 | { 303 | UsersCount++; 304 | try 305 | { 306 | DotNetNuke.Entities.Users.UserInfo objUser = new DotNetNuke.Entities.Users.UserInfo(); 307 | //use email as username, when username is not provided 308 | objUser.Username = string.Format("{0}", GetDataRowValue(dt, dr, "Username", objUser.Email)); 309 | 310 | bool UserAlreadyExists = false; 311 | if (UpdateExistingUser) 312 | { 313 | objUser = UserController.GetUserByName(objPortalSettings.PortalId, objUser.Username); 314 | if (objUser == null) 315 | { 316 | objUser = new DotNetNuke.Entities.Users.UserInfo(); 317 | objUser.Username = string.Format("{0}", GetDataRowValue(dt, dr, "Username", objUser.Email)); 318 | } 319 | else 320 | { 321 | UserAlreadyExists = true; 322 | } 323 | } 324 | 325 | 326 | objUser.Profile.InitialiseProfile(objPortalSettings.PortalId, true); 327 | objUser.Email = string.Format("{0}", dr["Email"]); 328 | objUser.FirstName = string.Format("{0}", dr["FirstName"]); 329 | objUser.LastName = string.Format("{0}", dr["LastName"]); 330 | objUser.DisplayName = string.Format("{0}", GetDataRowValue(dt, dr, "DisplayName", string.Format("{0} {1}", dr["FirstName"], dr["LastName"]))); 331 | objUser.PortalID = objPortalSettings.PortalId; 332 | 333 | objUser.IsSuperUser = ObjectToBool(GetDataRowValue(dt, dr, "IsSuperUser", "0")); 334 | 335 | //only SuperUsers allowed to import users with SuperUsers rights 336 | if ((!currentUserInfo.IsSuperUser) && objUser.IsSuperUser) 337 | { 338 | FailedUsers.AppendFormat( 339 | string.Format(Localization.GetString("Line", LocalResourceFile), UsersCount) + 340 | Localization.GetString("UserDeniedToImportRole", LocalResourceFile), 341 | currentUserInfo.Username, 342 | "SuperUser"); 343 | continue; 344 | } 345 | 346 | if (dt.Columns.Contains("Password")) 347 | { 348 | objUser.Membership.Password = string.Format("{0}", dr["Password"]); 349 | } 350 | objUser.Membership.Password = ValidatePassword(objUser, Convert.ToBoolean(objContext.Request.Form["cbRandomPassword"])); 351 | 352 | int AffiliateID = -1; 353 | if (Int32.TryParse(string.Format("{0}", GetDataRowValue(dt, dr, "AffiliateId", -1)), out AffiliateID)) 354 | { 355 | objUser.AffiliateID = AffiliateID; 356 | } 357 | 358 | objUser.Membership.Approved = true; 359 | objUser.Membership.PasswordQuestion = objUser.Membership.Password; 360 | objUser.Membership.UpdatePassword = Convert.ToBoolean(objContext.Request.Form["cbForcePasswordChange"]);//update password on next login 361 | 362 | DotNetNuke.Security.Membership.UserCreateStatus objCreateStatus; 363 | if (UserAlreadyExists) 364 | { 365 | objCreateStatus = DotNetNuke.Security.Membership.UserCreateStatus.Success; 366 | } 367 | else 368 | { 369 | objCreateStatus = UserController.CreateUser(ref objUser); 370 | } 371 | 372 | if (objCreateStatus == DotNetNuke.Security.Membership.UserCreateStatus.Success) 373 | { 374 | if (dt.Columns.IndexOf("UserID") != -1) 375 | { 376 | objUser.Profile.SetProfileProperty("OldUserID", string.Format("{0}", dr["UserID"])); 377 | } 378 | SuccessUsersCount++; 379 | 380 | //Update Profile 381 | objUser.Profile.Country = string.Format("{0}", GetDataRowValue(dt, dr, "Country", "")); 382 | objUser.Profile.Street = string.Format("{0}", GetDataRowValue(dt, dr, "Street", "")); 383 | objUser.Profile.City = string.Format("{0}", GetDataRowValue(dt, dr, "City", "")); 384 | objUser.Profile.Region = string.Format("{0}", GetDataRowValue(dt, dr, "Region", "")); 385 | objUser.Profile.PostalCode = string.Format("{0}", GetDataRowValue(dt, dr, "PostalCode", "")); 386 | objUser.Profile.Unit = string.Format("{0}", GetDataRowValue(dt, dr, "Unit", "")); 387 | objUser.Profile.Telephone = string.Format("{0}", GetDataRowValue(dt, dr, "Telephone", "")); 388 | objUser.Profile.FirstName = objUser.FirstName; 389 | objUser.Profile.LastName = objUser.LastName; 390 | 391 | //Profile Properties 392 | if (Convert.ToBoolean(objContext.Request.Form["cbImportProfileProperties"])) 393 | { 394 | foreach (DataColumn dc in dt.Columns) 395 | { 396 | if (NonProfileFields.IndexOf(string.Format(",{0},", dc.ColumnName.ToLower())) != -1) 397 | { 398 | continue; 399 | } 400 | //check if profile property exists 401 | ProfilePropertyDefinition objPPD = DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(objPortalSettings.PortalId, dc.ColumnName); 402 | if ((objPPD == null) && (Convert.ToBoolean(objContext.Request.Form["cbCreateMissedProfileProperties"]))) 403 | { 404 | objPPD = new ProfilePropertyDefinition(objPortalSettings.PortalId); 405 | objPPD.PropertyName = dc.ColumnName; 406 | objPPD.PropertyCategory = "Imported"; 407 | objPPD.DataType = 349; 408 | DotNetNuke.Entities.Profile.ProfileController.AddPropertyDefinition(objPPD); 409 | objUser.Profile.SetProfileProperty(dc.ColumnName, RemoveNewLine(string.Format("{0}", dr[dc.ColumnName]))); 410 | } 411 | else 412 | { 413 | objUser.Profile.SetProfileProperty(dc.ColumnName, RemoveNewLine(string.Format("{0}", dr[dc.ColumnName]))); 414 | } 415 | } 416 | } 417 | ProfileController.UpdateUserProfile(objUser); 418 | UserController.UpdateUser(objPortalSettings.PortalId, objUser); 419 | 420 | //Update Roles 421 | string RolesStatus = UpdateRoles(currentUserInfo, objPortalSettings, objUser, dr, objContext.Request.Form["rblImportRoles"], LocalResourceFile); 422 | if (RolesStatus.Trim() != "") 423 | { 424 | FailedUsers.AppendFormat(Localization.GetString("UpdateRolesError", LocalResourceFile), 425 | UsersCount, 426 | objUser.UserID, 427 | RolesStatus); 428 | } 429 | 430 | if (Convert.ToBoolean(objContext.Request.Form["cbEmailUser"])) 431 | { 432 | string SendEmailResult = CommonController.SendEmail(objUser, SubjectTemplate, BodyTemplate, objPortalSettings); 433 | 434 | switch (SendEmailResult) 435 | { 436 | case "": 437 | //success 438 | break; 439 | case "InvalidEmail": 440 | FailedUsers.AppendFormat(Localization.GetString("SendEmailInvalidEmailException", LocalResourceFile), 441 | UsersCount, 442 | objUser.Username, 443 | objUser.Email); 444 | break; 445 | default: 446 | FailedUsers.AppendFormat(Localization.GetString("SendEmailException", LocalResourceFile), 447 | UsersCount, 448 | objUser.Username, 449 | SendEmailResult); 450 | break; 451 | } 452 | } 453 | } 454 | else 455 | { 456 | FailedUsers.AppendFormat(Localization.GetString("RowMembershipError", LocalResourceFile), 457 | UsersCount, 458 | objUser.Username, 459 | objCreateStatus.ToString()); 460 | } 461 | } 462 | catch (Exception Exc) 463 | { 464 | FailedUsers.AppendFormat(Localization.GetString("RowException", LocalResourceFile), 465 | UsersCount, 466 | Exc.Message); 467 | Exceptions.LogException(Exc); 468 | } 469 | } 470 | return string.Format(Localization.GetString("Result", LocalResourceFile), 471 | UsersCount, 472 | SuccessUsersCount, 473 | FailedUsers.ToString()); 474 | } 475 | 476 | private static string RemoveNewLine(string Source) 477 | { 478 | return Source.Replace("\r", "").Replace("\n", ""); 479 | } 480 | 481 | private static string UpdateRoles(UserInfo objCurrentUser, 482 | PortalSettings objPortalSettings, 483 | UserInfo objUser, 484 | DataRow dr, 485 | string rblImportRoles, 486 | string LocalResourceFile 487 | ) 488 | { 489 | RoleController objRoleController = new RoleController(); 490 | bool ByID = false; 491 | bool AutoCreateRole = false; 492 | string Roles = ""; 493 | 494 | switch (rblImportRoles) 495 | { 496 | case "0": 497 | return ""; 498 | case "1": 499 | ByID = true; 500 | Roles = (string)dr["RoleIDs"]; 501 | break; 502 | case "3": 503 | Roles = (string)dr["Roles"]; 504 | AutoCreateRole = true; 505 | break; 506 | case "2": 507 | Roles = (string)dr["Roles"]; 508 | break; 509 | } 510 | 511 | string AdministratorRoleName = ""; 512 | try 513 | { 514 | AdministratorRoleName = 515 | (objPortalSettings.AdministratorRoleName == DotNetNuke.Common.Utilities.Null.NullString) ? "" : objPortalSettings.AdministratorRoleName; 516 | } 517 | catch(Exception Exc) 518 | { 519 | Exceptions.LogException(Exc); 520 | } 521 | if (AdministratorRoleName == "") 522 | { 523 | //for child portals its empty and we need RoleName only to check security, so can use any uniq string - always will be false 524 | AdministratorRoleName = System.Guid.NewGuid().ToString(); 525 | } 526 | 527 | StringBuilder sb = new StringBuilder(); 528 | foreach (string Role in Roles.Split(new char[] { ',' })) 529 | { 530 | if (Role.Trim() == "") 531 | { 532 | continue; 533 | } 534 | 535 | RoleInfo objRole = null; 536 | if (ByID) 537 | { 538 | int RoleID = -1; 539 | if (Int32.TryParse(Role, out RoleID)) 540 | { 541 | objRole = objRoleController.GetRole(RoleID, objPortalSettings.PortalId); 542 | } 543 | } 544 | else 545 | { 546 | objRole = objRoleController.GetRoleByName(objPortalSettings.PortalId, Role); 547 | if ((objRole == null) && (AutoCreateRole)) 548 | { 549 | objRole = new RoleInfo(); 550 | objRole.RoleGroupID = -1; 551 | objRole.RoleName = Role; 552 | objRole.PortalID = objPortalSettings.PortalId; 553 | objRole.AutoAssignment = false; 554 | objRole.IsPublic = false; 555 | objRole.TrialPeriod = -1; 556 | objRole.BillingPeriod = -1; 557 | objRole.Status = RoleStatus.Approved; 558 | objRole.RoleID = objRoleController.AddRole(objRole); 559 | } 560 | } 561 | 562 | //check current user has permissions to import user with specific role 563 | if (! 564 | (objCurrentUser.IsInRole(objRole.RoleName) || 565 | objCurrentUser.IsInRole(AdministratorRoleName) || 566 | objCurrentUser.IsSuperUser 567 | )) 568 | { 569 | sb.AppendFormat(Localization.GetString("UserDeniedToImportRole", LocalResourceFile), objCurrentUser.Username, 570 | (ByID ? string.Format("RoleID={0}", objRole.RoleID) : string.Format("RoleName={0}", objRole.RoleName)) 571 | ); 572 | continue; 573 | } 574 | 575 | if (objRole != null) 576 | { 577 | objRoleController.AddUserRole(objPortalSettings.PortalId, objUser.UserID, objRole.RoleID, DotNetNuke.Common.Utilities.Null.NullDate); 578 | } 579 | else 580 | { 581 | sb.AppendFormat( 582 | ByID ? Localization.GetString("RoleIDNotFound", LocalResourceFile) : Localization.GetString("RoleNameNotFound", LocalResourceFile), 583 | Role); 584 | } 585 | } 586 | return sb.ToString(); 587 | } 588 | 589 | #endregion 590 | 591 | #region Send Email to Users 592 | 593 | private static Regex objRegExPassword = new Regex( 594 | "\\[User\\:Password\\]", 595 | RegexOptions.IgnoreCase 596 | | RegexOptions.Multiline 597 | | RegexOptions.Singleline 598 | | RegexOptions.CultureInvariant 599 | | RegexOptions.Compiled 600 | ); 601 | 602 | public static string SendEmail(UserInfo objUser, string SubjectTemplate, string BodyTemplate, PortalSettings objPortalSettings) 603 | { 604 | try 605 | { 606 | if (!IsValidEmail(objUser.Email)) 607 | { 608 | return "InvalidEmail"; 609 | } 610 | 611 | //send email 612 | DotNetNuke.Services.Tokens.TokenReplace objTokenReplace = 613 | new DotNetNuke.Services.Tokens.TokenReplace( 614 | DotNetNuke.Services.Tokens.Scope.DefaultSettings, 615 | System.Globalization.CultureInfo.CurrentCulture.Name, 616 | objPortalSettings, 617 | objUser); 618 | 619 | string Subject = objRegExPassword.Replace(SubjectTemplate, objUser.Membership.Password); 620 | string Body = objRegExPassword.Replace(BodyTemplate, objUser.Membership.Password); 621 | 622 | Subject = objTokenReplace.ReplaceEnvironmentTokens(Subject); 623 | Body = objTokenReplace.ReplaceEnvironmentTokens(Body); 624 | 625 | DotNetNuke.Services.Mail.Mail.SendEmail(objPortalSettings.Email, objUser.Email, Subject, Body); 626 | } 627 | catch (Exception Exc) 628 | { 629 | Exceptions.LogException(Exc); 630 | return Exc.Message; 631 | } 632 | return ""; 633 | } 634 | 635 | public static bool IsValidEmail(string Email) 636 | { 637 | //check is empty 638 | if (Email.Trim() == "") 639 | { 640 | return false; 641 | } 642 | 643 | //check is valid at all 644 | try 645 | { 646 | MailAddress m = new MailAddress(Email); 647 | 648 | return true; 649 | } 650 | catch (FormatException) 651 | { 652 | return false; 653 | } 654 | } 655 | 656 | #endregion 657 | 658 | public static void ResponseFile(string ContentType, byte[] lstBytes, string FileName) 659 | { 660 | HttpResponse objResponse = System.Web.HttpContext.Current.Response; 661 | objResponse.ClearHeaders(); 662 | objResponse.ClearContent(); 663 | objResponse.ContentType = ContentType;//"application/vnd.ms-excel" 664 | objResponse.AppendHeader("Content-Length", lstBytes.Length.ToString()); 665 | objResponse.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", FileName)); 666 | objResponse.OutputStream.Write(lstBytes, 0, lstBytes.Length); 667 | objResponse.Flush(); 668 | objResponse.End(); 669 | } 670 | 671 | public static string SaveFile(int PortalId, string ToWrite, string FileName) 672 | { 673 | PortalSettings objPortalSettings = new PortalSettings(PortalId); 674 | string Path = objPortalSettings.HomeDirectoryMapPath + "UsersExportImport\\"; 675 | if (!System.IO.Directory.Exists(Path)) 676 | { 677 | System.IO.Directory.CreateDirectory(Path); 678 | } 679 | //delete all files in directory for security reason 680 | foreach (string tempName in System.IO.Directory.GetFiles(Path)) 681 | { 682 | System.IO.File.Delete(tempName); 683 | } 684 | 685 | System.IO.StreamWriter sw = new System.IO.StreamWriter(Path + FileName, false, Encoding.UTF8); 686 | sw.Write(ToWrite); 687 | sw.Close(); 688 | 689 | return objPortalSettings.HomeDirectory + "UsersExportImport/" + FileName; 690 | } 691 | 692 | public static string GetMaxAllowedFileSize() 693 | { 694 | try 695 | { 696 | System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); 697 | HttpRuntimeSection section = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection; 698 | return string.Format("{0} kB", section.MaxRequestLength); 699 | } 700 | catch (Exception Exc) 701 | { 702 | Exceptions.LogException(Exc); 703 | return "undefined"; 704 | } 705 | } 706 | 707 | public static string ResolveUrl(string FileName, bool VirtualPathOnly) 708 | { 709 | System.Web.HttpRequest objRequest = System.Web.HttpContext.Current.Request; 710 | string Secure = ""; 711 | string Port = ""; 712 | 713 | if (objRequest.IsSecureConnection) 714 | { 715 | Secure = "s"; 716 | } 717 | if (!objRequest.Url.IsDefaultPort) 718 | { 719 | Port = ":" + objRequest.Url.Port.ToString(); 720 | } 721 | 722 | string FullRoot = ""; 723 | if (!VirtualPathOnly) 724 | { 725 | FullRoot = string.Format("http{0}://{1}{2}", 726 | Secure, 727 | objRequest.Url.Host, 728 | Port); 729 | } 730 | 731 | string Result = string.Format("{0}{1}DesktopModules/forDNN.UsersExportImport/{2}", 732 | FullRoot, 733 | (objRequest.ApplicationPath == "") ? "" : string.Format("{0}/", objRequest.ApplicationPath), 734 | FileName); 735 | 736 | return Result; 737 | } 738 | 739 | } 740 | } -------------------------------------------------------------------------------- /.vs/config/applicationhost.config: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 50 | 51 | 52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | 61 | 62 | 63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | 82 |
83 |
84 | 85 |
86 |
87 |
88 |
89 |
90 |
91 | 92 |
93 |
94 |
95 |
96 |
97 | 98 |
99 |
100 |
101 | 102 |
103 |
104 | 105 |
106 |
107 | 108 |
109 |
110 |
111 | 112 | 113 |
114 |
115 |
116 |
117 |
118 |
119 | 120 |
121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | --------------------------------------------------------------------------------