YAFLogo

datafake
  • datafake
  • 54.2% (Neutral)
  • YAF Forumling Topic Starter
16 years ago
Hi all,

Im new to YAF.

I am about to write a fairly simple web site that will allow users to sign up, answer some survey questions and add some text ( their tip to other users )

We need to add a forum section to the site (YAF) that we will open once we have collected some users. I want users to sign up via my simple web app and be able to use the same credentials to login to YAF later.

I have intalled the latest version of YAF 1.9.3 as it should allow me to use the ASP.NET membership provider to share users with my simple site.

Everything seems to be working with the forum installed. To see how my membership adding code might work I tried adding a user using the ASP.NET configuration tool but got an error. Should I be able to do this or does YAF need extra fields.

I also notice that although I have users in my forum the membership tables are still empty. Is this what I should expect.

Can anyone show me some example code for adding a user to YAF from outside the forum.

Thanks for any help or clarification

Graeme

YAF 1.9.3 .NET 3.5

Sponsor
Mek
  • Mek
  • 100% (Exalted)
  • YAF Developer
16 years ago
Have you changed the web.config Providers section to your asp.net default membership ones, it doesn't automatically guess which provider to use.

Providers follow the same pattern as they based on the same underlying classes, so YAF does not require additional fields for Membership or Roles. Sounds like your problem lies elsewhere.

Google:

System.Web.Security.Membership.CreateUser for examples of how to create a user using Membership.


UserPostedImage

"It's a case of RTFM.. the only problem being we don't have a manual!"

When I post FP:Mek in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Ederon 🙂 )

datafake
  • datafake
  • 54.2% (Neutral)
  • YAF Forumling Topic Starter
16 years ago

Ill look into this. Make sure I actually have my membership set up correctly!

Thanks for your help.

Graeme

datafake
  • datafake
  • 54.2% (Neutral)
  • YAF Forumling Topic Starter
16 years ago
Hi i am wrestling with my web.config

If I go into the forum and register a new user then entries appear in both the yaf_User table and the asp_net_Users table.

However

If I create a new user using the ASP.NET configuration tool the user appears in the asp_net_Users table but not in the yaf_User table.

Can anyone help me out?

The connection string myConnectionString points to the SQL database that has the Membership tables, the YAF tables and tables I created. I am using 1.9.3, .NET 3.5 and working locally with VS2008 Express.

Part of web.config:

type="System.Web.Security.SqlMembershipProvider"

connectionStringName="myConnectionString"

applicationName="/"

minRequiredNonalphanumericCharacters="0"

minRequiredPasswordLength="6"

maxInvalidPasswordAttempts="20"

passwordAttemptWindow="10"

enablePasswordReset="true"

requiresQuestionAndAnswer="false"

requiresUniqueEmail="False" />

type="System.Web.Security.SqlRoleProvider"

connectionStringName="myConnectionString"

applicationName="/"/>

applicationName="/"

name="YafProfileProvider"

type="YAF.Providers.Profile.YafProfileProvider"/>

Also im using and have YAF in a folder called forum

This is the only combination I can get to work but I dont understand what BaseUrl does as none of the tutorials suggest that it needs to be changed.

Thanks

Graeme

CoreyRi1
  • CoreyRi1
  • 52.4% (Neutral)
  • YAF Forumling
16 years ago
@datafake: Try to sign in to your forum using the user you just created. I know that sounds weird, but this is the way mine is setup and how it works: 1.User registers using a registration form which is outside of yaf. 2. User is added to the outside database but not the yaf database. 3. User signs in to YAF and if they have a matching account on the outside database, their user info is automatically copied to the yaf database and they are signed in. So it might be working afterall...

The problem I'm having is that those users are not added to the _UserGroup table so they have no permissions by default...so you might need to find some work-around for that...I'm still trying to find the best method to fix the problem but I'm really not sure how to fix it at this point.

datafake
  • datafake
  • 54.2% (Neutral)
  • YAF Forumling Topic Starter
16 years ago

Thanks for your help @CoreyRi1 ill give that a try!

Graeme

datafake
  • datafake
  • 54.2% (Neutral)
  • YAF Forumling Topic Starter
16 years ago
Hi,

Whoo hoo

Yes, I tried that and it works as you said.

The permissions problem is because Role is not set in the code. When I use ASP.NET configuration tool I get to select a role, either "administrator" or "registered" and it works. I did this in code like this.


try
{
    MembershipUser mu = Membership.CreateUser(username.Text, password.Text, email.Text);
    Roles.AddUserToRole(mu.UserName.ToString(), "registered");           

    // Display a status message           
    validationmessage.Text += string.Format("User {0} was added to role {1}.", 
    mu.UserName.ToString(),"registered"); 
}
catch (MembershipCreateUserException ex)
{
    validationmessage.Text += GetErrorMessage(ex.StatusCode);
}


string GetErrorMessage(MembershipCreateStatus status)
{
    switch (status)
    {
       case MembershipCreateStatus.DuplicateUserName:
           return "Sorry that user name already exists. Please enter a different user name.";

       case MembershipCreateStatus.DuplicateEmail:
           return "A user name for that e-mail address already exists. Please enter a different e-mail address.";

       case MembershipCreateStatus.InvalidPassword:
           return "The password provided is invalid. Please enter a valid password value.";

       case MembershipCreateStatus.InvalidEmail:
           return "The e-mail address provided is invalid. Please check the value and try again.";

       case MembershipCreateStatus.InvalidAnswer:
           return "The password retrieval answer provided is invalid. Please check the value and try again.";

       case MembershipCreateStatus.InvalidQuestion:
           return "The password retrieval question provided is invalid. Please check the value and try again.";

       case MembershipCreateStatus.InvalidUserName:
           return "The user name provided is invalid. Please check the value and try again.";

       case MembershipCreateStatus.ProviderError:
           return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";

       case MembershipCreateStatus.UserRejected:
           return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";

       default:
           return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
    }
}

Thanks again for your help

Graeme

CoreyRi1
  • CoreyRi1
  • 52.4% (Neutral)
  • YAF Forumling
16 years ago
Great, glad to hear your forum is now working!:)

Thanks for the tip about the permissions problem, but I'm not really sure what to do with that code. Do I need to insert that somewhere? Do I need to modify some code, if so, which file? Is that even YAF code, or is that from your other application?

Heh, sorry...really haven't worked with asp much myself.

datafake
  • datafake
  • 54.2% (Neutral)
  • YAF Forumling Topic Starter
16 years ago
Hi

That code is outside the forum. Users to my site can sign up outside of the forum then use those details to log into the forum

I have a page with a sign up form, when the user submits the form the code behind for the page captures the data they input and puts the extra details I need into my DB tables. After that the code uses the built in membership classes to add a new user to the asp_net membership system.

These two lines add new users that my app and YAF will share

MembershipUser mu = Membership.CreateUser(username.Text, password.Text, email.Text);

Roles.AddUserToRole(mu.UserName.ToString(), "registered");

The second line adds users to the registered role. Without it i would get the problem of the new user having no permissions. Equivalent to not checking a role checkbox when using the asp.net configuration tool.

Your permissions problem may be because you are not selecting a role when ading users with the asp.net configuration tool. Also if your web.config is wrong the asp.net configuration tool will not show any roles to select

Graeme

evil wiggins
15 years ago
Hi I am also having problem with this

This is the web.config section, if anybody can show me what I am doing wrong please?

<roleManager enabled="true" cacheRolesInCookie="true" createPersistentCookie="true" >
	<providers>
		<add applicationName="/" connectionStringName="LocalSqlServer" name="DefaultRoleProvider" type="System.Web.Security.SqlRoleProvider" />
	</providers>
</roleManager>
<authentication mode="Forms"/>
<membership>
	<providers>
		<add connectionStringName="LocalSqlServer" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="true" passwordFormat="Clear" minRequiredPasswordLength="3" minRequiredNonalphanumericCharacters="0" passwordStrengthRegularExpression="" name="DefaultMembershipProvider" type="YAF.Providers.Membership.YafMembershipProvider" />
	</providers>
</membership>
		
<profile enabled="true" defaultProvider="YafProfileProvider" inherits="YAF.Classes.Utils.YafUserProfile">
	<providers>
		<clear/>
		<add connectionStringName="yafnet" applicationName="/" name="YafProfileProvider" type="YAF.Providers.Profile.YafProfileProvider"/>
	</providers>
</profile>
Mek
  • Mek
  • 100% (Exalted)
  • YAF Developer
15 years ago

Hi I am also having problem with this

evil wiggins wrote:

Your web.config seems to be a mash; why are you using Standard Role Providers with our Membership and Profile??? Makes no sense. Look at the web.configs bundled with 1.93 RC2 in the web.configs folder to see how these should be set up. And if I'm entirely honest I'd say use our web.config then alter them to suit whatever your trying to do, rather than start with another web.config and try to get YAF to work with it. Much easier imo.


UserPostedImage

"It's a case of RTFM.. the only problem being we don't have a manual!"

When I post FP:Mek in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Ederon 🙂 )

evil wiggins
15 years ago
the problem is I already have 300+ users in the membership table, if i try to uise the yaf stuff i can't log in. Has anybody successfully integrated into an existing membership table I followed all the instructions but it just would not work.

with the above "mash" (nice word) I can login and i am logged in to the forum, but i think that is only because i am the admin user, i can't see any other members listed for the forum

Mek
  • Mek
  • 100% (Exalted)
  • YAF Developer
15 years ago
Which membership table? Cos your "mash" is pointing the membership at our membership provider, yet your roles is pointing at the standard asp.net roles. When you want both to be probably point at the standard providers (probably the profiles as well, but I believe you have to inherit the profile provider. There has been a discussion about it on the forums).


UserPostedImage

"It's a case of RTFM.. the only problem being we don't have a manual!"

When I post FP:Mek in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Ederon 🙂 )

evil wiggins
15 years ago
Ok, managed to get it working.

Though now the images are broken links and the theme is not displaying, yet it works fine on localhost, but as soon as i put it on my site, nothing.

benwhyte83
15 years ago
Hey, I am getting this error

Could not load type 'YAF.Providers.Profile.ProfileProvider'

This is what I have set up for the providers in the web.config file


    <profile enabled="true" defaultProvider="YafProfileProvider" inherits="YAF.Classes.Utils.YafUserProfile">
      <providers>
        <clear/>
        <add name="YafProfileProvider" type="YAF.Providers.Profile.ProfileProvider" connectionStringName="yafnet" applicationName="" />
      </providers>
    </profile>

I am pretty sure I have copied across all the correct bin files, app_code and other web.config keys. Is there anything I could have missed?