Beispiel #1
0
        /// <summary>
        /// Import the User From the Current Table Row
        /// </summary>
        /// <param name="row">
        /// The row with the User Information.
        /// </param>
        /// <param name="importCount">
        /// The import Count.
        /// </param>
        /// <returns>
        /// Returns the Imported User Count.
        /// </returns>
        private int ImportUser(DataRow row, int importCount)
        {
            // Also Check if the Email is unique and exists
            if (this.Get <IAspNetUsersHelper>().GetUserByEmail((string)row["Email"]) != null)
            {
                return(importCount);
            }

            var provider = new YafMembershipProvider();

            var pass           = provider.GeneratePassword();
            var securityAnswer = provider.GeneratePassword();

            // create empty profile just so they have one
            var userProfile = new ProfileInfo();

            // Add Profile Fields to User List Table.
            if (row.Table.Columns.Contains("RealName") && ((string)row["RealName"]).IsSet())
            {
                userProfile.RealName = (string)row["RealName"];
            }

            if (row.Table.Columns.Contains("Blog") && ((string)row["Blog"]).IsSet())
            {
                userProfile.Blog = (string)row["Blog"];
            }

            if (row.Table.Columns.Contains("Gender") && ((string)row["Gender"]).IsSet())
            {
                int.TryParse((string)row["Gender"], out var gender);

                userProfile.Gender = gender;
            }

            if (row.Table.Columns.Contains("Birthday") && ((string)row["Birthday"]).IsSet())
            {
                DateTime.TryParse((string)row["Birthday"], out var userBirthdate);

                if (userBirthdate > DateTimeHelper.SqlDbMinTime())
                {
                    userProfile.Birthday = userBirthdate;
                }
            }

            if (row.Table.Columns.Contains("GoogleId") && ((string)row["GoogleId"]).IsSet())
            {
                userProfile.GoogleId = (string)row["GoogleId"];
            }

            if (row.Table.Columns.Contains("Location") && ((string)row["Location"]).IsSet())
            {
                userProfile.Location = (string)row["Location"];
            }

            if (row.Table.Columns.Contains("Country") && ((string)row["Country"]).IsSet())
            {
                userProfile.Country = (string)row["Country"];
            }

            if (row.Table.Columns.Contains("Region") && ((string)row["Region"]).IsSet())
            {
                userProfile.Region = (string)row["Region"];
            }

            if (row.Table.Columns.Contains("City") && ((string)row["City"]).IsSet())
            {
                userProfile.City = (string)row["City"];
            }

            if (row.Table.Columns.Contains("Interests") && ((string)row["Interests"]).IsSet())
            {
                userProfile.Interests = (string)row["Interests"];
            }

            if (row.Table.Columns.Contains("Homepage") && ((string)row["Homepage"]).IsSet())
            {
                userProfile.Homepage = (string)row["Homepage"];
            }

            if (row.Table.Columns.Contains("Skype") && ((string)row["Skype"]).IsSet())
            {
                userProfile.Skype = (string)row["Skype"];
            }

            if (row.Table.Columns.Contains("ICQe") && ((string)row["ICQ"]).IsSet())
            {
                userProfile.ICQ = (string)row["ICQ"];
            }

            if (row.Table.Columns.Contains("XMPP") && ((string)row["XMPP"]).IsSet())
            {
                userProfile.XMPP = (string)row["XMPP"];
            }

            if (row.Table.Columns.Contains("Occupation") && ((string)row["Occupation"]).IsSet())
            {
                userProfile.Occupation = (string)row["Occupation"];
            }

            if (row.Table.Columns.Contains("Twitter") && ((string)row["Twitter"]).IsSet())
            {
                userProfile.Twitter = (string)row["Twitter"];
            }

            if (row.Table.Columns.Contains("TwitterId") && ((string)row["TwitterId"]).IsSet())
            {
                userProfile.TwitterId = (string)row["TwitterId"];
            }

            if (row.Table.Columns.Contains("Facebook") && ((string)row["Facebook"]).IsSet())
            {
                userProfile.Facebook = (string)row["Facebook"];
            }

            if (row.Table.Columns.Contains("FacebookId") && ((string)row["FacebookId"]).IsSet())
            {
                userProfile.FacebookId = (string)row["FacebookId"];
            }

            var user = new AspNetUsers
            {
                Id              = Guid.NewGuid().ToString(),
                ApplicationId   = this.Get <BoardSettings>().ApplicationId,
                UserName        = (string)row["Name"],
                LoweredUserName = (string)row["Name"],
                Email           = (string)row["Email"],
                IsApproved      = true,

                Profile_Birthday          = userProfile.Birthday,
                Profile_Blog              = userProfile.Blog,
                Profile_Gender            = userProfile.Gender,
                Profile_GoogleId          = userProfile.GoogleId,
                Profile_Homepage          = userProfile.Homepage,
                Profile_ICQ               = userProfile.ICQ,
                Profile_Facebook          = userProfile.Facebook,
                Profile_FacebookId        = userProfile.FacebookId,
                Profile_Twitter           = userProfile.Twitter,
                Profile_TwitterId         = userProfile.TwitterId,
                Profile_Interests         = userProfile.Interests,
                Profile_Location          = userProfile.Location,
                Profile_Country           = userProfile.Country,
                Profile_Region            = userProfile.Region,
                Profile_City              = userProfile.City,
                Profile_Occupation        = userProfile.Occupation,
                Profile_RealName          = userProfile.RealName,
                Profile_Skype             = userProfile.Skype,
                Profile_XMPP              = userProfile.XMPP,
                Profile_LastSyncedWithDNN = userProfile.LastSyncedWithDNN
            };

            this.Get <IAspNetUsersHelper>().Create(user, pass);

            // setup initial roles (if any) for this user
            AspNetRolesHelper.SetupUserRoles(BoardContext.Current.PageBoardID, user);

            // create the user in the YAF DB as well as sync roles...
            var userID = AspNetRolesHelper.CreateForumUser(user, BoardContext.Current.PageBoardID);

            if (userID == null)
            {
                // something is seriously wrong here -- redirect to failure...
                return(importCount);
            }

            // send user register notification to the new users
            this.Get <ISendNotification>().SendRegistrationNotificationToUser(
                user, pass, securityAnswer, "NOTIFICATION_ON_REGISTER");

            // save the time zone...
            var userId = this.Get <IAspNetUsersHelper>().GetUserIDFromProviderUserKey(user.Id);

            var timeZone = 0;

            if (row.Table.Columns.Contains("Timezone") && ((string)row["Timezone"]).IsSet())
            {
                int.TryParse((string)row["Timezone"], out timeZone);
            }

            var autoWatchTopicsEnabled = this.Get <BoardSettings>().DefaultNotificationSetting
                                         == UserNotificationSetting.TopicsIPostToOrSubscribeTo;

            this.GetRepository <User>().Save(
                userId,
                BoardContext.Current.PageBoardID,
                row["Name"],
                row.Table.Columns.Contains("DisplayName") ? row["DisplayName"] : null,
                row["Email"],
                timeZone,
                row.Table.Columns.Contains("LanguageFile") ? row["LanguageFile"] : null,
                row.Table.Columns.Contains("Culture") ? row["Culture"] : null,
                row.Table.Columns.Contains("ThemeFile") ? row["ThemeFile"] : null,
                false);

            // save the settings...
            this.GetRepository <User>().SaveNotification(
                userId,
                true,
                autoWatchTopicsEnabled,
                this.Get <BoardSettings>().DefaultNotificationSetting.ToInt(),
                this.Get <BoardSettings>().DefaultSendDigestEmail);

            importCount++;

            return(importCount);
        }
Beispiel #2
0
        /// <summary>
        /// Create user
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void RegisterClick(object sender, EventArgs e)
        {
            if (!this.Page.IsValid)
            {
                return;
            }

            if (!this.ValidateUser())
            {
                return;
            }

            var user = new AspNetUsers
            {
                Id              = Guid.NewGuid().ToString(),
                ApplicationId   = this.Get <BoardSettings>().ApplicationId,
                UserName        = this.UserName.Text,
                LoweredUserName = this.UserName.Text,
                Email           = this.Email.Text,
                IsApproved      = false,
                EmailConfirmed  = false
            };

            var result = this.Get <IAspNetUsersHelper>().Create(user, this.Password.Text.Trim());

            if (!result.Succeeded)
            {
                // error of some kind
                this.PageContext.AddLoadMessage(result.Errors.FirstOrDefault(), MessageTypes.danger);
            }
            else
            {
                // setup initial roles (if any) for this user
                AspNetRolesHelper.SetupUserRoles(this.PageContext.PageBoardID, user);

                var displayName = this.DisplayName.Text;

                // create the user in the YAF DB as well as sync roles...
                var userID = AspNetRolesHelper.CreateForumUser(user, displayName, this.PageContext.PageBoardID);

                if (userID == null)
                {
                    // something is seriously wrong here -- redirect to failure...
                    BuildLink.RedirectInfoPage(InfoMessage.Failure);
                }

                if (this.IsPossibleSpamBot)
                {
                    if (this.Get <BoardSettings>().BotHandlingOnRegister.Equals(1))
                    {
                        this.Get <ISendNotification>().SendSpamBotNotificationToAdmins(user, userID.Value);
                    }
                }
                else
                {
                    // handle e-mail verification
                    var email = this.Email.Text.Trim();

                    this.Get <ISendNotification>().SendVerificationEmail(user, email, userID);

                    if (this.Get <BoardSettings>().NotificationOnUserRegisterEmailList.IsSet())
                    {
                        // send user register notification to the following admin users...
                        this.Get <ISendNotification>().SendRegistrationNotificationEmail(user, userID.Value);
                    }
                }

                this.BodyRegister.Visible = false;
                this.Footer.Visible       = false;

                // success notification localization
                this.Message.Visible     = true;
                this.AccountCreated.Text = this.Get <IBBCode>().MakeHtml(
                    this.GetText("ACCOUNT_CREATED_VERIFICATION"),
                    true,
                    true);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Handles the Click event of the ForumRegister control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void ForumRegisterClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            this.Page.Validate();

            if (!this.Page.IsValid)
            {
                return;
            }

            var newEmail    = this.Email.Text.Trim();
            var newUsername = this.UserName.Text.Trim();

            if (!ValidationHelper.IsValidEmail(newEmail))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_INVALID_MAIL"), MessageTypes.danger);

                return;
            }

            if (this.Get <IAspNetUsersHelper>().UserExists(this.UserName.Text.Trim(), newEmail))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_NAME_EXISTS"), MessageTypes.danger);
                return;
            }

            // setup their initial profile information
            var userProfile = new ProfileInfo
            {
                Location = this.Location.Text.Trim(), Homepage = this.HomePage.Text.Trim()
            };

            var user = new AspNetUsers
            {
                Id              = Guid.NewGuid().ToString(),
                ApplicationId   = this.Get <BoardSettings>().ApplicationId,
                UserName        = newUsername,
                LoweredUserName = newUsername,
                Email           = newEmail,
                IsApproved      = !this.Get <BoardSettings>().EmailVerification,
                EmailConfirmed  = !this.Get <BoardSettings>().EmailVerification,

                Profile_Birthday          = userProfile.Birthday,
                Profile_Blog              = userProfile.Blog,
                Profile_Gender            = userProfile.Gender,
                Profile_GoogleId          = userProfile.GoogleId,
                Profile_Homepage          = userProfile.Homepage,
                Profile_ICQ               = userProfile.ICQ,
                Profile_Facebook          = userProfile.Facebook,
                Profile_FacebookId        = userProfile.FacebookId,
                Profile_Twitter           = userProfile.Twitter,
                Profile_TwitterId         = userProfile.TwitterId,
                Profile_Interests         = userProfile.Interests,
                Profile_Location          = userProfile.Location,
                Profile_Country           = userProfile.Country,
                Profile_Region            = userProfile.Region,
                Profile_City              = userProfile.City,
                Profile_Occupation        = userProfile.Occupation,
                Profile_RealName          = userProfile.RealName,
                Profile_Skype             = userProfile.Skype,
                Profile_XMPP              = userProfile.XMPP,
                Profile_LastSyncedWithDNN = userProfile.LastSyncedWithDNN
            };

            var result = this.Get <IAspNetUsersHelper>().Create(user, this.Password.Text.Trim());

            if (!result.Succeeded)
            {
                // error of some kind
                this.PageContext.AddLoadMessage(result.Errors.FirstOrDefault(), MessageTypes.danger);
                return;
            }

            // setup initial roles (if any) for this user
            AspNetRolesHelper.SetupUserRoles(BoardContext.Current.PageBoardID, user);

            // create the user in the YAF DB as well as sync roles...
            var userId = AspNetRolesHelper.CreateForumUser(user, BoardContext.Current.PageBoardID);

            var autoWatchTopicsEnabled = this.Get <BoardSettings>().DefaultNotificationSetting
                                         .Equals(UserNotificationSetting.TopicsIPostToOrSubscribeTo);

            // save the time zone...
            this.GetRepository <User>().Save(
                this.Get <IAspNetUsersHelper>().GetUserIDFromProviderUserKey(user.Id),
                this.PageContext.PageBoardID,
                null,
                null,
                null,
                this.TimeZones.SelectedValue,
                null,
                null,
                null,
                false);

            if (this.Get <BoardSettings>().EmailVerification)
            {
                this.Get <ISendNotification>().SendVerificationEmail(user, newEmail, userId, newUsername);
            }

            this.GetRepository <User>().SaveNotification(
                this.Get <IAspNetUsersHelper>().GetUserIDFromProviderUserKey(user.Id),
                true,
                autoWatchTopicsEnabled,
                this.Get <BoardSettings>().DefaultNotificationSetting.ToInt(),
                this.Get <BoardSettings>().DefaultSendDigestEmail);

            // success
            this.PageContext.AddLoadMessage(
                this.GetTextFormatted("MSG_CREATED", this.UserName.Text.Trim()),
                MessageTypes.success);

            BuildLink.Redirect(ForumPages.Admin_RegisterUser);
        }
Beispiel #4
0
        /// <summary>
        /// Creates the facebook user
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="email">
        /// The email.
        /// </param>
        /// <param name="facebookUserId">
        /// The facebook User Id.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// Returns if the login was successfully or not
        /// </returns>
        private bool CreateFacebookUser(string name, string email, string facebookUserId, out string message)
        {
            if (this.Get <BoardSettings>().DisableRegistrations)
            {
                message = this.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED");
                return(false);
            }

            // Check if user name is null
            var userName    = name;
            var displayName = userName;

            userName = displayName.Replace(" ", ".");

            var pass = PasswordGenerator.GeneratePassword(true, true, true, true, false, 16);

            var user = new AspNetUsers
            {
                Id                 = Guid.NewGuid().ToString(),
                ApplicationId      = this.Get <BoardSettings>().ApplicationId,
                UserName           = userName,
                LoweredUserName    = userName.ToLower(),
                Email              = email,
                IsApproved         = true,
                EmailConfirmed     = true,
                Profile_RealName   = name,
                Profile_FacebookId = facebookUserId,
                Profile_Facebook   = $"https://www.facebook.com/profile.php?id={facebookUserId}"
            };

            var result = this.Get <IAspNetUsersHelper>().Create(user, pass);

            if (!result.Succeeded)
            {
                // error of some kind
                message = result.Errors.FirstOrDefault();
                return(false);
            }

            // setup initial roles (if any) for this user
            AspNetRolesHelper.SetupUserRoles(BoardContext.Current.PageBoardID, user);

            // create the user in the YAF DB as well as sync roles...
            var userID = AspNetRolesHelper.CreateForumUser(user, displayName, BoardContext.Current.PageBoardID);

            if (userID == null)
            {
                // something is seriously wrong here -- redirect to failure...
                message = this.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED");
                return(false);
            }

            // send user register notification to the user...
            this.Get <ISendNotification>().SendRegistrationNotificationToUser(
                user,
                pass,
                "NOTIFICATION_ON_FACEBOOK_REGISTER");

            if (this.Get <BoardSettings>().NotificationOnUserRegisterEmailList.IsSet())
            {
                // send user register notification to the following admin users...
                this.Get <ISendNotification>().SendRegistrationNotificationEmail(user, userID.Value);
            }

            var autoWatchTopicsEnabled = this.Get <BoardSettings>().DefaultNotificationSetting
                                         == UserNotificationSetting.TopicsIPostToOrSubscribeTo;

            this.GetRepository <User>().Save(
                userID.Value,
                BoardContext.Current.PageBoardID,
                user.UserName,
                user.UserName,
                user.Email,
                TimeZoneInfo.Local.Id,
                null,
                null,
                null,
                false);

            // save the settings...
            this.GetRepository <User>().SaveNotification(
                userID.Value,
                true,
                autoWatchTopicsEnabled,
                this.Get <BoardSettings>().DefaultNotificationSetting.ToInt(),
                this.Get <BoardSettings>().DefaultSendDigestEmail);

            // save avatar
            this.GetRepository <User>().SaveAvatar(
                userID.Value,
                $"https://graph.facebook.com/{facebookUserId}/picture",
                null,
                null);

            this.Get <IRaiseEvent>().Raise(new NewUserRegisteredEvent(user, userID.Value));

            message = string.Empty;

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Handles the Click event of the ForumRegister control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void ForumRegisterClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            this.Page.Validate();

            if (!this.Page.IsValid)
            {
                return;
            }

            var newEmail    = this.Email.Text.Trim();
            var newUsername = this.UserName.Text.Trim();

            if (!ValidationHelper.IsValidEmail(newEmail))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_INVALID_MAIL"), MessageTypes.danger);

                return;
            }

            if (this.Get <IAspNetUsersHelper>().UserExists(this.UserName.Text.Trim(), newEmail))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_NAME_EXISTS"), MessageTypes.danger);
                return;
            }

            var user = new AspNetUsers
            {
                Id              = Guid.NewGuid().ToString(),
                ApplicationId   = this.Get <BoardSettings>().ApplicationId,
                UserName        = newUsername,
                LoweredUserName = newUsername,
                Email           = newEmail,
                IsApproved      = false,
                EmailConfirmed  = false
            };

            var result = this.Get <IAspNetUsersHelper>().Create(user, this.Password.Text.Trim());

            if (!result.Succeeded)
            {
                // error of some kind
                this.PageContext.AddLoadMessage(result.Errors.FirstOrDefault(), MessageTypes.danger);
                return;
            }

            // setup initial roles (if any) for this user
            AspNetRolesHelper.SetupUserRoles(this.PageContext.PageBoardID, user);

            // create the user in the YAF DB as well as sync roles...
            var userId = AspNetRolesHelper.CreateForumUser(user, this.PageContext.PageBoardID);

            var autoWatchTopicsEnabled = this.Get <BoardSettings>().DefaultNotificationSetting
                                         .Equals(UserNotificationSetting.TopicsIPostToOrSubscribeTo);

            this.Get <ISendNotification>().SendVerificationEmail(user, newEmail, userId, newUsername);

            this.GetRepository <User>().SaveNotification(
                this.Get <IAspNetUsersHelper>().GetUserIDFromProviderUserKey(user.Id),
                true,
                autoWatchTopicsEnabled,
                this.Get <BoardSettings>().DefaultNotificationSetting.ToInt(),
                this.Get <BoardSettings>().DefaultSendDigestEmail);

            // success
            this.PageContext.LoadMessage.AddSession(
                this.GetTextFormatted("MSG_CREATED", this.UserName.Text.Trim()),
                MessageTypes.success);

            BuildLink.Redirect(ForumPages.Admin_Users);
        }