Welcome Guest! To enable all features please Login or Register.
Options
View
Go to last post Go to first unread
Offline Albert Casas  
#1 Posted : Wednesday, April 12, 2017 2:56:03 AM(UTC)
Albert Casas


Rank: YAF Forumling

Reputation:

Joined: 9/30/2016(UTC)
Posts: 3
Man

Hello, I'm trying to create a new user via code in a new Board but if I create a user in Board 1 this is create without problems, but if I create in another Board the application show me this message

You can not insert the NULL value in the 'Flags' column, table 'Forum.dbo.yaf_User'. The column does not support NULL values. INSERT error.
You can not insert the NULL value in the 'UserID' column, table 'Forum.dbo.yaf_UserGroup'. The column does not support NULL values. INSERT error.

I call this procedure for create de new board


Code:
 Querystring += "  Declare @data as datetime  set @data = getdate() "
        Querystring += "  Declare @BoardName nvarchar(150) "
        Querystring += "  Declare @Boardid int "
		
        'Creació del forum
        '-----------------------------------
        
        Querystring += " EXEC  [forum].[dbo].[yaf_board_create]  "
        Querystring += "                 @BoardName = 'Board Name', "
        Querystring += " @Culture = N'es-Es', "
        Querystring += " @LanguageFile = N'spanish.xml',"
        Querystring += " @MembershipAppName = N'', "
        Querystring += " @RolesAppName = N'',"
        Querystring += " @UserName = N'admin', "
        Querystring += " @UserEmail = N'mail@domanin.com',"
        Querystring += " @UserKey = N'*****',"
        Querystring += " @IsHostAdmin = 0, "
        Querystring += " @RolePrefix = N'',"
        Querystring += " @UTCTIMESTAMP = @data"
        Querystring += " set @Boardid=     IDENT_CURRENT( 'forum.dbo.yaf_Board' ) "



And use this funcition for create new users

Code:
MembershipCreateStatus status;
        var pass = Membership.GeneratePassword(32, 16);
        var securityQuestion = "Security Question";
        var securityAnswer = "Security Answer";
        var userName = "UserName24";
        var email = "user@domanin.com";
        var boardId = 2;

        MembershipUser user = YafContext.Current.Get<MembershipProvider>().CreateUser(
                                    userName, pass, email, securityQuestion, securityAnswer, true, null, out status);

        // setup inital roles (if any) for this user
        RoleMembershipHelper.SetupUserRoles(boardId, userName);

        // create the user in the YAF DB as well as sync roles...
        int? userID = RoleMembershipHelper.CreateForumUser(user, boardId);

        // create empty profile just so they have one
        YafUserProfile userProfile = YafUserProfile.GetProfile(userName);

        // Set profile properties?!
        userProfile.Homepage = "http://www.test.com";

        // setup their inital profile information
        userProfile.Save();

        if (YafContext.Current.Get<YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet())
        {
            // send user register notification to the following admin users...
            YafContext.Current.Get<ISendNotification>().SendRegistrationNotificationEmail(user, userID.Value);
        }
        int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey);
        LegacyDb.user_save(
                                   userId,
                                boardId,
                                  userName,
                                  "Albert",
                                   email,
                                   0,
                                   null,
                                   null,
                                   null,
                                   true,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null);

        bool autoWatchTopicsEnabled = YafContext.Current.Get<YafBoardSettings>().DefaultNotificationSetting ==
                                                              UserNotificationSetting.TopicsIPostToOrSubscribeTo;

        // save the settings...
        LegacyDb.user_savenotification(
                                    userId,
                                    true,
                                    autoWatchTopicsEnabled,
                                    YafContext.Current.Get<YafBoardSettings>().DefaultNotificationSetting,
                                    YafContext.Current.Get<YafBoardSettings>().DefaultSendDigestEmail);




I have looked in the database and the new user have been created, it have a group (yaf_UserGroup) and this group have a flag(yaf_Group)

Any idea, how to do it?

Thanks
Sponsor
Offline Albert Casas  
#2 Posted : Wednesday, April 19, 2017 6:38:04 AM(UTC)
Albert Casas


Rank: YAF Forumling

Reputation:

Joined: 9/30/2016(UTC)
Posts: 3
Man

hello

I belived I have a problem with my code. But now I try to create a new YAF forum and in the administrator server section >> desktop >> new broad I have created a new broad (Broad 2)

I have modified my default page to tell it to work with the board 2

Code:
    protected void Page_Load(object sender, EventArgs e)
    {
 
            this.forum.BoardID = 2; 
 
   
    }


But the forum section is empty and I can't create categories in the admnistrative section

Is there any way to do dinamic boardID?

Edited by user Wednesday, April 19, 2017 7:11:21 AM(UTC)  | Reason: Not specified

Rss Feed  Atom Feed
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error