我成功安装了另一个论坛(yaf)代码并成功地将其与博客引擎2.0集成。现在我想要博客引擎2.0和yaf的共同登录,即当我自动登录blogengine2.0时必须是登录。有人建议我解决方案吗?
答案 0 :(得分:1)
将webconfig中的MembershipPorivder更改为以下内容:
//I have changaned the following to be able to genrate a password myself and to be able to retrive it when i want to login the use, you can change this if you want or just leave it as it is.
<membership defaultProvider="YafMembershipProvider" hashAlgorithmType="NONE" >
<providers>
<clear/>
<add connectionStringName="yafnet" applicationName="YetAnotherForum" name="YafMembershipProvider" passwordFormat="Clear" requiresUniqueEmail="true" useSalt="false" enablePasswordRetrieval="true" type="YAF.Providers.Membership.YafMembershipProvider"/>
</providers>
</membership>
此方法将创建一个YAFUser,所有这些方法都是从YAF库中提取的,我刚刚在它们上面工作了很多东西,以提取我想要的一切:
/// <summary>
/// Register YAF User
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <param name="email"></param>
/// <param name="displayName"></param>
public static MembershipUser RegisterYAF_User(string userName, string password, string email, string displayName)
{
//Intilize YAFMembershipProvider
MembershipCreateStatus status;
YafMembershipProvider provider = new YafMembershipProvider();
NameValueCollection valueCollection = new NameValueCollection();
valueCollection.Add("connectionStringName", "yafnet");
valueCollection.Add("applicationName", "YetAnotherForum");
valueCollection.Add("passwordFormat", "Clear");
provider.Initialize("YafMembershipProvider", valueCollection);
//Register YAFMembershipUser
MembershipUser user = provider.CreateUser(userName, password, email, "What is your favorite football team ?", "None", true, new YAF.Providers.Profile.DB().GetProviderUserKey("YetAnotherForum", userName), out status);
//Register YAFUser
if (user != null)
{
//Add user to role
RoleMembershipHelper.AddUserToRole(user.UserName, "Registered");
// setup inital roles (if any) for this user
RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, userName);
// create the user in the YAF DB as well as sync roles...
int? userID = RoleMembershipHelper.CreateForumUser(user, user.UserName, YafContext.Current.PageBoardID);
// create empty profile just so they have one
YafUserProfile userProfile = YafUserProfile.GetProfile(user.UserName);
// setup their inital profile information
userProfile.Location = "USA";
userProfile.Homepage = string.Empty;
userProfile.Save();
LegacyDb.user_save(
UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey),
YafContext.Current.PageBoardID,
null,
null,
null,
YafContext.Current.TimeZoneUser.ToType<int>(),
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null);
}
return user;
}
此功能用于登录YAFUser:
//Login yaf user
/// <summary>
/// Login
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
public static void LoginYAF_User(string userName, string password)
{
MembershipCreateStatus status;
YafMembershipProvider provider = new YafMembershipProvider();
NameValueCollection valueCollection = new NameValueCollection();
valueCollection.Add("connectionStringName", "yafnet");
valueCollection.Add("applicationName", "YetAnotherForum");
valueCollection.Add("passwordFormat", "Clear");
provider.Initialize("YafMembershipProvider", valueCollection);
bool Authenticated = false;
if (provider.ValidateUser(userName, password))
{
Authenticated = true;
FormsAuthentication.SetAuthCookie(userName, true);
}
else if (new YafBoardSettings().EnableDisplayName)
{
var id = new DefaultUserDisplayName(YafContext.Current.ServiceLocator).GetId(userName);
if (id.HasValue)
{
// get the username associated with this id...
userName = UserMembershipHelper.GetUserNameFromID(id.Value);
// validate again...
if (provider.ValidateUser(userName, password))
{
Authenticated = true;
}
}
}
//These 2 lines of code is to redirect to the fourm main page
//YafContext.Current.Get<IRaiseEvent>().Raise(new SuccessfulUserLoginEvent(YafContext.Current.CurrentUserData.UserID));
//YafBuildLink.Redirect(ForumPages.forum);
}
之后转到YAFMembershipProvider.cs并添加如下的重载方法:
public string GetPassword(string username)
{
// Check for null arguments
if ((username == null))
{
ExceptionReporter.ThrowArgument("MEMBERSHIP", "USERNAMEPASSWORDNULL");
}
UserPasswordInfo currentPasswordInfo = UserPasswordInfo.CreateInstanceFromDB(
"YetAnotherForum",
username,
false,
this.UseSalt,
this.HashHex,
this.HashCase,
"",
this.MSCompliant);
return currentPasswordInfo.Password;
}
在这个我已经给出了99%的百分比,其余的只是简单的简单编码,至于博客你应该使用相同的概念。搜索DataLayer并获取所需的所有方法,以便在任意数量的应用程序之间进行同步。