/// <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 = 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.SetYafHostUser(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);
            }
        }
Beispiel #2
0
        /// <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);
            }
        }