/// <summary> /// Get YAF User Id from the Current DNN User /// </summary> /// <returns> /// The YAF User ID /// </returns> private int GetYafUserId() { // Check for user if (!HttpContext.Current.User.Identity.IsAuthenticated) { return(UserMembershipHelper.GuestUserId); } // get the user from the membership provider var dnnUser = Membership.GetUser(this.UserInfo.Username, true); // Check if the user exists in yaf var yafUserId = LegacyDb.user_get(this.boardId, dnnUser.ProviderUserKey); if (!yafUserId.Equals(0)) { return(yafUserId); } // Get current DNN user var dnnUserInfo = UserController.GetCurrentUserInfo(); return(UserImporter.CreateYafUser( dnnUserInfo, dnnUser, this.boardId, this.PortalSettings.PortalId, YafContext.Current.Get <YafBoardSettings>())); }
/// <summary> /// The create board. /// </summary> /// <param name="importUsers">if set to <c>true</c> [import users].</param> /// <param name="BoardName">Name of the board.</param> /// <returns> /// Returns the Board ID of the new Board. /// </returns> private int CreateBoard(bool importUsers, string boardName) { // new admin var newAdmin = UserMembershipHelper.GetUser(); // Create Board var newBoardId = this.CreateBoardDatabase( boardName, YafContext.Current.Get <MembershipProvider>().ApplicationName, YafContext.Current.Get <RoleProvider>().ApplicationName, "english.xml", newAdmin); if (newBoardId > 0 && global::YAF.Classes.Config.MultiBoardFolders) { // Successfully created the new board var boardFolder = this.Server.MapPath( Path.Combine(global::YAF.Classes.Config.BoardRoot, "{0}/".FormatWith(newBoardId))); // Create New Folders. if (!Directory.Exists(Path.Combine(boardFolder, "Images"))) { // Create the Images Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images")); // Create Sub Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Emoticons")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Ranks")); } if (!Directory.Exists(Path.Combine(boardFolder, "Themes"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Themes")); // Need to copy default theme to the Themes Folder } if (!Directory.Exists(Path.Combine(boardFolder, "Uploads"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads")); } } // Import Users & Roles if (importUsers) { string message; UserImporter.ImportUsers( newBoardId, this.PortalSettings.PortalId, this.PortalSettings.GUID, out message); } return(newBoardId); }
/// <summary> /// Save the Settings /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void UpdateClick([NotNull] object sender, [NotNull] EventArgs e) { var moduleController = new ModuleController(); moduleController.UpdateModuleSetting(this.ModuleId, "forumboardid", this.BoardID.SelectedValue); moduleController.UpdateModuleSetting(this.ModuleId, "RemoveTabName", this.RemoveTabName.SelectedValue); moduleController.UpdateModuleSetting( this.ModuleId, "InheritDnnLanguage", this.InheritDnnLanguage.Checked.ToString()); var boardSettings = new LoadBoardSettings(this.BoardID.SelectedValue.ToType <int>()) { DNNPageTab = this.TabId, DNNPortalId = this.PortalId, BaseUrlMask = $"http://{HttpContext.Current.Request.ServerVariables["SERVER_NAME"]}/" }; // save the settings to the database boardSettings.SaveRegistry(); // Import Users & Roles UserImporter.ImportUsers( this.BoardID.SelectedValue.ToType <int>(), this.PortalSettings.PortalId, out _); Config.Touch(); this.Response.Redirect(this.navigationManager.NavigateURL(this.TabId), true); }
/// <summary> /// Save the Settings /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void UpdateClick(object sender, EventArgs e) { var moduleController = new ModuleController(); moduleController.UpdateModuleSetting(this.ModuleId, "forumboardid", this.BoardID.SelectedValue); moduleController.UpdateModuleSetting(this.ModuleId, "RemoveTabName", this.RemoveTabName.SelectedValue); moduleController.UpdateModuleSetting( this.ModuleId, "InheritDnnLanguage", this.InheritDnnLanguage.Checked.ToString()); var boardSettings = new LoadBoardSettings(this.BoardID.SelectedValue.ToType <int>()) { DNNPageTab = this.TabId, DNNPortalId = this.PortalId, BaseUrlMask = $"http://{HttpContext.Current.Request.ServerVariables["SERVER_NAME"]}/" }; // save the settings to the database boardSettings.SaveRegistry(); // Import Users & Roles UserImporter.ImportUsers( this.BoardID.SelectedValue.ToType <int>(), this.PortalSettings.PortalId, out _); // Reload forum settings BoardContext.Current.BoardSettings = null; BuildLink.Redirect(ForumPages.Board); }
/// <summary> /// Import/Update Users and Sync Roles /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void ImportClick(object sender, EventArgs e) { string info; UserImporter.ImportUsers(this.boardId, this.PortalSettings.PortalId, this.PortalSettings.GUID, out info); this.lInfo.Text = info; }
/// <summary> /// Check if the DNN User exists in YAF, and if the Profile is up to date. /// </summary> private void CreateOrUpdateUser() { // Get current DNN user var dnnUserInfo = UserController.GetCurrentUserInfo(); // get the user from the membership provider MembershipUser dnnMembershipUser = Membership.GetUser(dnnUserInfo.Username, true); if (dnnMembershipUser == null) { return; } // Check if the user exists in yaf var yafUserId = LegacyDb.user_get(this.forum1.BoardID, dnnMembershipUser.ProviderUserKey); var boardSettings = YafContext.Current == null ? new YafLoadBoardSettings(this.forum1.BoardID) : YafContext.Current.Get <YafBoardSettings>(); if (yafUserId.Equals(0)) { yafUserId = UserImporter.CreateYafUser( dnnUserInfo, dnnMembershipUser, this.forum1.BoardID, this.CurrentPortalSettings.PortalId, boardSettings); // super admin check... if (dnnUserInfo.IsSuperUser) { UserImporter.CreateYafHostUser(yafUserId, this.forum1.BoardID); } } else { this.CheckForRoles(dnnUserInfo, yafUserId); ProfileSyncronizer.UpdateUserProfile( yafUserId, YafContext.Current.Profile, YafContext.Current.CurrentUserData, dnnUserInfo, dnnMembershipUser, this.CurrentPortalSettings.PortalId, this.CurrentPortalSettings.GUID, boardSettings); } }
/// <summary> /// The create board. /// </summary> /// <param name="importUsers">if set to <c>true</c> [import users].</param> /// <param name="boardName">Name of the board.</param> /// <returns> /// Returns the Board ID of the new Board. /// </returns> private int CreateBoard([NotNull] bool importUsers, [NotNull] string boardName) { CodeContracts.VerifyNotNull(boardName); // new admin var newAdmin = UserController.Instance.GetCurrentUserInfo().ToAspNetUsers(); // Create Board var newBoardId = this.CreateBoardDatabase( boardName, "english.xml", newAdmin); if (newBoardId > 0 && Configuration.Config.MultiBoardFolders) { // Successfully created the new board var boardFolder = this.Server.MapPath( Path.Combine(Configuration.Config.BoardRoot, $"{newBoardId}/")); // Create New Folders. if (!Directory.Exists(Path.Combine(boardFolder, "Images"))) { // Create the Images Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images")); // Create Sub Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images", "Avatars")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images", "Categories")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images", "Forums")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images", "Medals")); } if (!Directory.Exists(Path.Combine(boardFolder, "Uploads"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads")); } } // Import Users & Roles if (importUsers) { UserImporter.ImportUsers( newBoardId, this.PortalSettings.PortalId, out _); } return(newBoardId); }
/// <summary> /// Check if the DNN User exists in YAF, and if the Profile is up to date. /// </summary> private void CreateOrUpdateUser() { // Get current DNN user var dnnUserInfo = UserController.Instance.GetCurrentUserInfo(); // Check if the user exists in yaf var yafUser = this.GetRepository <User>().GetUserByProviderKey(this.forum1.BoardID, dnnUserInfo.UserID.ToString()); if (yafUser == null) { // Migrate from Yaf < 3 yafUser = this.GetRepository <User>() .GetSingle(u => u.Name == dnnUserInfo.Username && u.Email == dnnUserInfo.Email); if (yafUser != null) { // update provider Key this.GetRepository <User>().UpdateOnly( () => new User { ProviderUserKey = dnnUserInfo.UserID.ToString() }, u => u.ID == yafUser.ID); } } var boardSettings = BoardContext.Current == null ? new LoadBoardSettings(this.forum1.BoardID) : this.Get <BoardSettings>(); if (yafUser == null) { var yafUserId = UserImporter.CreateYafUser( dnnUserInfo, this.forum1.BoardID, this.CurrentPortalSettings.PortalId, boardSettings); // super admin check... if (dnnUserInfo.IsSuperUser) { UserImporter.SetYafHostUser(yafUserId, this.forum1.BoardID); } } else { this.CheckForRoles(dnnUserInfo, yafUser.ID); } }
/// <summary> /// Check if the DNN User exists in YAF, and if the Profile is up to date. /// </summary> private void CreateOrUpdateUser() { // Get current DNN user var dnnUserInfo = UserController.Instance.GetCurrentUserInfo(); // get the user from the membership provider var dnnMembershipUser = Membership.GetUser(dnnUserInfo.Username, true); if (dnnMembershipUser == null) { return; } // Check if the user exists in yaf var yafUserId = BoardContext.Current.GetRepository <User>().GetUserId(this.forum1.BoardID, dnnMembershipUser.ProviderUserKey.ToString()); var boardSettings = BoardContext.Current == null ? new LoadBoardSettings(this.forum1.BoardID) : BoardContext.Current.Get <BoardSettings>(); if (yafUserId.Equals(0)) { yafUserId = UserImporter.CreateYafUser( dnnUserInfo, dnnMembershipUser, this.forum1.BoardID, this.CurrentPortalSettings.PortalId, boardSettings); // super admin check... if (dnnUserInfo.IsSuperUser) { UserImporter.SetYafHostUser(yafUserId, this.forum1.BoardID); } } else { this.CheckForRoles(dnnUserInfo, yafUserId); ProfileSyncronizer.UpdateUserProfile( yafUserId, BoardContext.Current.Profile, BoardContext.Current.CurrentUserData, dnnUserInfo, boardSettings); } }
/// <summary> /// Gets the settings. /// </summary> private void GetSettings() { var settings = new DataSet(); var filePath = $"{HttpRuntime.AppDomainAppPath}App_Data/YafImports.xml"; try { settings.ReadXml(filePath); } catch (Exception) { var file = new FileStream(filePath, FileMode.Create); var sw = new StreamWriter(file); sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sw.WriteLine("<YafImports>"); sw.WriteLine("<Import PortalId=\"0\" BoardId=\"1\"/>"); sw.WriteLine("</YafImports>"); sw.Close(); file.Close(); settings.ReadXml(filePath); } var boards = BoardContext.Current != null ? BoardContext.Current.GetRepository <Board>().GetAll() : BoardContext.Current.GetRepository <Board>().GetAll().Select(b => new Board { ID = b.ID }).ToList(); settings.Tables[0].Rows.Cast <DataRow>().ForEach(dataRow => { var boardId = dataRow["BoardId"].ToType <int>(); var portalId = dataRow["PortalId"].ToType <int>(); // check if board exist if (boards.Any(b => b.ID.Equals(boardId))) { UserImporter.ImportUsers(boardId, portalId, out this.info); } }); }
/// <summary> /// Gets the settings. /// </summary> private void GetSettings() { var settings = new DataSet(); var filePath = "{0}App_Data/YafImports.xml".FormatWith(HttpRuntime.AppDomainAppPath); try { settings.ReadXml(filePath); } catch (Exception) { var file = new FileStream(filePath, FileMode.Create); var sw = new StreamWriter(file); sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sw.WriteLine("<YafImports>"); sw.WriteLine("<Import PortalId=\"0\" BoardId=\"1\"/>"); sw.WriteLine("</YafImports>"); sw.Close(); file.Close(); settings.ReadXml(filePath); } var boards = YafContext.Current != null ? YafContext.Current.GetRepository <Board>().ListTyped() : Data.ListBoards(); foreach (DataRow dataRow in settings.Tables[0].Rows) { var boardId = dataRow["BoardId"].ToType <int>(); var portalId = dataRow["PortalId"].ToType <int>(); // check if board exist if (boards.Any(b => b.ID.Equals(boardId))) { UserImporter.ImportUsers(boardId, portalId, out this.info); } } }
/// <summary> /// Get YAF User Id from the Current DNN User /// </summary> /// <returns> /// The YAF User ID /// </returns> private int GetYafUserId() { // Check for user if (!HttpContext.Current.User.Identity.IsAuthenticated) { return(BoardContext.Current.Get <IAspNetUsersHelper>().GuestUserId); } // Check if the user exists in yaf var yafUser = BoardContext.Current.GetRepository <User>().GetUserByProviderKey(this.boardId, this.UserInfo.UserID.ToString()); if (yafUser != null) { return(yafUser.ID); } yafUser = BoardContext.Current.GetRepository <User>() .GetSingle(u => u.Name == this.UserInfo.Username && u.Email == this.UserInfo.Email); if (yafUser == null) { return(UserImporter.CreateYafUser( this.UserInfo, this.boardId, this.PortalSettings.PortalId, BoardContext.Current.Get <BoardSettings>())); } { // update provider Key BoardContext.Current.GetRepository <User>().UpdateOnly( () => new User { ProviderUserKey = this.UserInfo.UserID.ToString() }, u => u.ID == yafUser.ID); return(yafUser.ID); } }
public QuestionImporter(NpgsqlConnection conn, UserImporter import, TextWriter tw) { this.conn = conn; userimport = import; textwriter = tw; }
public QuestionImporter(NpgsqlConnection conn) { this.conn = conn; userimport = new UserImporter(); textwriter = System.Console.Out; }
public async Task ImportUsers([FromService] UserImporter importer) { await importer.ImportUsers(); }
private static void ConfigureUserImport() { UserImporter importer = new UserImporter(new DomanUserLoginProvider(DomainConstants.DomainName)); Timer dispatcherTimer = new System.Threading.Timer(new TimerCallback(importer.DispatcherTimerTick), null, 86400000, 86400000); }