Albert Casas
  • Posts: 3
  • Joined: 30/09/2016
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


 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

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
Albert Casas
  • Posts: 3
  • Joined: 30/09/2016
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

    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?
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.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved