YAFLogo

erikkl2000
  • erikkl2000
  • 53% (Neutral)
  • YAF Forumling Topic Starter
16 years ago
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");

TextBox password = (TextBox)Login1.FindControl("Password");

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");

// 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 !");

}

}

}

}

---------------------------------------------------------------------------------------

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.");

}

//////////////////////////////////Erik

// username cannot contain semi-colon

if (CreateUserWizard1.UserName.Contains(";"))

{

PageContext.AddLoadMessage(GetText("BAD_USERNAME"));

e.Cancel = true;

return;

}

Control createUserTemplateRef = CreateUserWizard1.CreateUserStep.ContentTemplateContainer;

TextBox tbCaptcha = (TextBox)createUserTemplateRef.FindControl("tbCaptcha");

// verify captcha if enabled

if (PageContext.BoardSettings.EnableCaptchaForRegister && Session["CaptchaImageText"].ToString() != tbCaptcha.Text.Trim())

{

PageContext.AddLoadMessage(GetText("BAD_CAPTCHA"));

e.Cancel = true;

}

}

On web.config

---------------------------------------------------------------------------------------

****Add your provider here ***

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="" />

Sponsor