Posted by: pbwbart - Monday, 15 June 2009 07:10:27 |
---|
Hi, I'm trying to create a forum user with my own source. If I add a user into my own database It should automaticly be insterted into the yaf databaste. For this I referene all dll files of the yaf forum and I import the following[quote]imports System.Drawing imports System.Web.Security imports System.Web.UI.HtmlControls imports YAF.Classes.Utils imports YAF.Classes.Base[/quote] I created my sourcecode which looks like this: [code]Public ReadOnly Property PageContext() As YafContext Get End Get End Property Protected Sub ForumRegister(Byval newEmail as string,Byval newUsername as string,Byval Password as string,Byval Question as string, Byval Answer as string,Byval Location as string, Byval Homepage as string) 'Dim newEmail As String = Email.Text.Trim() 'Dim newUsername As String = UserName.Text.Trim() Dim TimeZones as string = "60" Dim hashinput As String = DateTime.Now.ToString() + newEmail + Security.CreatePassword(20) Dim hash As String = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5") Dim status As MembershipCreateStatus Dim user As MembershipUser = Membership.CreateUser(newUsername, Password, newEmail, Question, Answer, Not Pagecontext.BoardSettings.EmailVerification, status) ' setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, newUsername) ' create the user in the YAF DB as well as sync roles... Dim userID As System.Nullable(Of Integer) = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID) ' create profile Dim userProfile As YafUserProfile = Pagecontext.GetProfile(newUsername) ' setup their inital profile information userProfile.Location = Location userProfile.Homepage = HomePage userProfile.Save() ' save the time zone... YAF.Classes.Data.DB.user_save(UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey), Pagecontext.PageBoardID, Nothing, Nothing, Convert.ToInt32(TimeZones), Nothing, _ Nothing, Nothing, Nothing, Nothing) 'If Pagecontext.BoardSettings.EmailVerification Then ' send template email 'Dim verifyEmail As New YafTemplateEmail("VERIFYEMAIL") 'verifyEmail.TemplateParams("{link}") = [String].Format("{1}{0}", YAF.Classes.Utils.YafBuildLink.GetLink(YAF.Classes.Utils.ForumPages.approve, "k={0}", hash), YAF.Classes.Utils.YafForumInfo.ServerURL) 'verifyEmail.TemplateParams("{key}") = hash 'verifyEmail.TemplateParams("{forumname}") = Pagecontext.BoardSettings.Name 'verifyEmail.TemplateParams("{forumlink}") = [String].Format("{0}", ForumPage.ForumURL) 'Dim subject As String = [String].Format(Pagecontext.Localization.GetText("COMMON", "EMAILVERIFICATION_SUBJECT"), Pagecontext.BoardSettings.Name) 'verifyEmail.SendEmail(New System.Net.Mail.MailAddress(newEmail, newUsername), subject, True) 'End If End Sub [/code] It is almost the same as the code in /admin/reguser but a little different. When I'm debugging the source I don'n get any errors But there is a problme with the "PageContext" I can't figure out what it is doing and I actually have no idea how I can use this to make everyting work the right way. Can someone please help me? Thanks |
Posted by: Mek - Monday, 15 June 2009 07:19:32 |
---|
Your PageContent property should return PageContext.Current i.e. looks like this in C# [code] public YafContext ForumContext { get { return YafContext.Current; } } [/code] |
Posted by: pbwbart - Tuesday, 16 June 2009 23:56:51 |
---|
Thanks for your Replay, in vb.net the code looks like this [code]Public ReadOnly Property PageContext() As YafContext Get Return YafContext.Current End Get End Property[/code] So I missed the return statement. But I think I'm missing something else because no user will be added. I think I'm missing some sessions in my application like the one of the loged in user which creates the new user(admin). I think somehow I need to simulate I'm logged in But I actually don't know which session I need exactly |
Posted by: Mek - Wednesday, 17 June 2009 00:02:13 |
---|
When you saying a user is not added, is it a new user to the membership, or is the user being created in membership and not yaf. Its not to do with your user session. |
Posted by: pbwbart - Wednesday, 17 June 2009 00:48:48 |
---|
Then I'm missing something else But I don't know what it is. Now I'm getting a nullreference on YafContest.get_Current() So I'm sure I have to set it somewhere [quote] System.NullReferenceException: Object reference not set to an instance of an object. Server stack trace: at YAF.Classes.Utils.YafContext.get_Current() at dValuate.EvalRunTime.ForumRegister(String newEmail, String newUsername, String Password, String Question, String Answer, String Location, String Homepage)[/quote] |
Posted by: pbwbart - Thursday, 18 June 2009 02:07:34 |
---|
I found this manual on your wiki site http://wiki.yetanotherforum.net/AspNetMembershipIntegration.ashx but when I add this source to my login script no user will by add. [code] Dim YafPassword As String = FormsAuthentication.HashPasswordForStoringInConfigFile(paswoord, "md5") Dim YafUserID As Object = yaf.Classes.Data.DB.user_login(1, login, YafPassword) If YafUserID Is DBNull.Value Then Dim AdminPage As New YAF.Classes.Base.AdminPage 'YafUserID = yaf.Classes.Data.DB.user_register(AdminPage, 1, Login, YafPassword, Membership.GetUser(Login).Email, "", "", "-300", False) YafUserID = yaf.Classes.Data.DB.user_register(AdminPage, 1, Login, YafPassword, email, "", "", "-300", False) End If Dim idName As String = String.Format("{0};{1};{2}", YafUserID, 1, Login) Httpcontext.Current.Session.Add("YAFUserId", idName) [/code] paswoord, login and email are clear tekst strings, the password si not encrypted. I added db.config and all app.config settings to my portal web.config. But I don't get the feeling anything changes when someone logs in. edit: there is a session which will be set after login [quote]YAFUserId:False;1;username[/quote] "username" is de loginname of the user |
Posted by: pbwbart - Thursday, 18 June 2009 04:18:20 |
---|
I finnaly get somewhere, users now will be added in de user table, but still not in "prov_membership" I sql I had to alter the storedprocudure User_save [code] USE [RIBW] GO /****** Object: StoredProcedure [dbo].[RIBWU_yaf_user_save] Script Date: 06/18/2009 14:06:35 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[RIBWU_yaf_user_save]( @UserID int, @BoardID int, @UserName nvarchar(50) = null, @Password nvarchar(50) = null, @Email nvarchar(50) = null, @TimeZone int, @LanguageFile nvarchar(50) = null, @ThemeFile nvarchar(50) = null, @OverrideDefaultTheme bit = null, @Approved bit = null, @PMNotification bit = null, @ProviderUserKey nvarchar(64) = null, @Hash nvarchar(64) = null, @Location nvarchar(64) = null, @HomePage nvarchar(64) = null ) AS begin declare @RankID int declare @Flags int set @Flags = 0 if @Approved<>0 set @Flags = @Flags | 2 if @PMNotification is null SET @PMNotification = 1 if @OverrideDefaultTheme is null SET @OverrideDefaultTheme=0 if @UserID is null or @UserID<1 begin if @Email = '' set @Email = null select @RankID = RankID from [dbo].[RIBWU_yaf_Rank] where (Flags & 1)<>0 and BoardID=@BoardID insert into [dbo].[RIBWU_yaf_User](BoardID,RankID,Name,Password,Email,Joined,LastVisit,NumPosts,TimeZone,Flags,PMNotification,ProviderUserKey) values(@BoardID,@RankID,@UserName,'-',@Email,getdate(),getdate(),0,@TimeZone,@Flags,@PMNotification,@ProviderUserKey) set @UserID = SCOPE_IDENTITY() insert into [dbo].[RIBWU_yaf_UserGroup](UserID,GroupID) select @UserID,GroupID from [dbo].[RIBWU_yaf_Group] where BoardID=@BoardID and (Flags & 4)<>0 end else begin update [dbo].[RIBWU_yaf_User] set TimeZone = @TimeZone, LanguageFile = @LanguageFile, ThemeFile = @ThemeFile, OverrideDefaultThemes = @OverrideDefaultTheme, PMNotification = @PMNotification where UserID = @UserID if @Email is not null update [dbo].[RIBWU_yaf_User] set Email = @Email where UserID = @UserID end end[/code] and in my login source I chaged user_registration because the order of the parameters is changed a little [code] Dim YafPassword As String = FormsAuthentication.HashPasswordForStoringInConfigFile(paswoord, "md5") Dim YafUserID As Object = yaf.Classes.Data.DB.user_login(1, login, YafPassword) If YafUserID Is DBNull.Value Then Dim AdminPage As New YAF.Classes.Base.AdminPage 'YafUserID = yaf.Classes.Data.DB.user_register(AdminPage, 1, Login, YafPassword, Membership.GetUser(Login).Email, "", "", "-300", False) 'YafUserID = yaf.Classes.Data.DB.user_register(AdminPage, 1, Login, YafPassword, email, "", "", "-300", False) YafUserID = yaf.Classes.Data.DB.user_register(1, Login, paswoord, "", email, "", "", "60", True) End If Dim idName As String = String.Format("{0};{1};{2}", YafUserID, 1, Login) Httpcontext.Current.Session.Add("YAFUserId", idName) [/code] I will work on this, If I have some result I will tell Edit : "RIBWU_yaf_" in my sp is my prefix, you should replace this |