Welcome Guest Search | Active Topics | Log In | Register

Multiple Membership Providers - Contribution Options · View
erikkl2000
#1 Posted : Monday, July 21, 2008 7:45:12 PM

Rank: YAF Forumling


Joined: 7/15/2008
Posts: 5
Location: dallas texas
Shows how to compare users from different data stores and if a match occures then we add them to YET

On Login Page




protected void Page_Load(object sender, System.EventArgs e)
{
// Ederon : guess we don't need this if anymore
//if ( !CanLogin )
// YAF.Classes.Utils.YafBuildLink.Redirect( YAF.Classes.Utils.ForumPages.forum );

////Erik
if (Request.QueryString["msg"] != null)
{
lblMsg.Text = Request.QueryString["msg"];
lblMsg.ForeColor = System.Drawing.Color.Red;
}

if (!IsPostBack)
{





protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
MembershipProvider afcc;
MembershipProvider yet;
MembershipUser yetUser = null;
MembershipUser afccUser = null;

TextBox userName = (TextBox)Login1.FindControl("UserName"Wink;
TextBox password = (TextBox)Login1.FindControl("Password"Wink;

yet = Membership.Providers["YafMembershipProvider"];
afcc = Membership.Providers["AspNetSqlMembershipProvider"];


afccUser = afcc.GetUser(userName.Text, false);
yetUser = yet.GetUser(userName.Text, false);
if (afccUser != null && yetUser == null)
{
MembershipCreateStatus status;
bool userNameExist = yet.GetUserNameByEmail(afccUser.Email) != null;
if (!userNameExist)
{
yet.CreateUser(afccUser.UserName, password.Text, afccUser.Email, afccUser.PasswordQuestion,
"moved", true, afccUser.ProviderUserKey, out status);

if (status == MembershipCreateStatus.Success)
{
// setup inital roles (if any) for this user
RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, afccUser.UserName);

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

// create empty profile just so they have one
YafUserProfile userProfile = PageContext.GetProfile(afccUser.UserName);
// setup their inital profile information

userProfile.Save();

string hashinput = DateTime.Now.ToString() + afccUser.Email + Security.CreatePassword(20);
string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5"Wink;

// save verification record...
YAF.Classes.Data.DB.checkemail_save(userID, hash, afccUser.Email);

string link = String.Format("{1}{0}", YafBuildLink.GetLinkNotEscaped(ForumPages.approve, "k={0}&showemsg=1&msg=Information Migrated ! Please Login Once More&autologin=1", hash), YafForumInfo.ServerURL);
Response.Redirect(link);
}
else
{
PageContext.AddLoadMessage("Error While Migrating Your AFCC Inc Nework Data ! Please Report This To Support immeditally !"Wink;
}
}
}


}


On Register Page


protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
// trim username on postback
CreateUserWizard1.UserName = CreateUserWizard1.UserName.Trim();

/////////////////////////////////Erik
MembershipProvider afcc;
MembershipUser afccUser;
afcc = Membership.Providers["AspNetSqlMembershipProvider"];
afccUser = afcc.GetUser(CreateUserWizard1.UserName, false);
if (afccUser.Email.Trim() == CreateUserWizard1.Email.Trim())
{
Response.Redirect("~/default.aspx?g=login&msg=That Email Already Exists On The AFCC Inc. Network. Login and we will move this email for you automatically."Wink;
}
//////////////////////////////////Erik

// username cannot contain semi-colon
if (CreateUserWizard1.UserName.Contains(";"Wink)
{
PageContext.AddLoadMessage(GetText("BAD_USERNAME"Wink);
e.Cancel = true;
return;

}

Control createUserTemplateRef = CreateUserWizard1.CreateUserStep.ContentTemplateContainer;
TextBox tbCaptcha = (TextBox)createUserTemplateRef.FindControl("tbCaptcha"Wink;

// verify captcha if enabled
if (PageContext.BoardSettings.EnableCaptchaForRegister && Session["CaptchaImageText"].ToString() != tbCaptcha.Text.Trim())
{
PageContext.AddLoadMessage(GetText("BAD_CAPTCHA"Wink);
e.Cancel = true;
}
}

On web.config


<membership defaultProvider="YafMembershipProvider" hashAlgorithmType="SHA1" >
<providers>
<clear/>
<add connectionStringName="yafnet" applicationName="YetAnotherForum" name="YafMembershipProvider" requiresUniqueEmail="true" useSalt="true" type="YAF.Providers.Membership.YafMembershipProvider"/>



****Add your provider here ***
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider,System.Web,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="xxxxxx"
requiresUniqueEmail="true"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />


</providers>
</membership>
Users browsing this topic
Guest
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.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 RC2 | YAF © 2003-2008, Yet Another Forum.NET
This page was generated in 0.197 seconds.

SourceForge.net Logo Powered by ASP.NET v2.0 411ASP.NET