公司最近开发的项目,有论坛,要求采用Discuz!NT,做用户整合,因dnt采用自己的用户管理,无法与membership用户整合,多次试验,通过修改ForumUtils.cs文件,将GetCookie方法修改,则可直接使用form验证,同时将注册,退出,登陆页面重新跳转到项目的相关页面即可.还需要删除修改口令,找回密码页面
当然,还需要在注册用户的同时,注册dnt用户
Dnt用户相关代码,包括注册,登陆,登出
public class UserManager
{
/**//// <summary>
/// 注册dnt用户
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="email"></param>
/// <param name="nickname"></param>
/// <returns></returns>
public static bool Register(string username, string password, string email, string nickname)
{
GeneralConfigInfo config = GeneralConfigs.GetConfig();
OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
UserGroupInfo usergroupinfo = UserGroups.GetUserGroupInfo(oluserinfo.Groupid);
UserInfo userinfo = new UserInfo();
userinfo.Username = username;
userinfo.Nickname = nickname;
userinfo.Password = Utils.MD5(password);
userinfo.Email = email;
userinfo.Secques = "";
userinfo.Gender = 0;
userinfo.Adminid = 0;
userinfo.Groupexpiry = 0;
userinfo.Extgroupids = "";
userinfo.Regip = DNTRequest.GetIP();
userinfo.Joindate = Utils.GetDateTime();
userinfo.Lastip = DNTRequest.GetIP();
userinfo.Lastvisit = Utils.GetDateTime();
userinfo.Lastactivity = Utils.GetDateTime();
userinfo.Lastpost = Utils.GetDateTime();
userinfo.Lastpostid = 0;
userinfo.Lastposttitle = "";
userinfo.Posts = 0;
userinfo.Digestposts = 0;
userinfo.Oltime = 0;
userinfo.Pageviews = 0;
userinfo.Credits = 0;
userinfo.Extcredits1 = Scoresets.GetScoreSet(1).Init;
userinfo.Extcredits2 = Scoresets.GetScoreSet(2).Init;
userinfo.Extcredits3 = Scoresets.GetScoreSet(3).Init;
userinfo.Extcredits4 = Scoresets.GetScoreSet(4).Init;
userinfo.Extcredits5 = Scoresets.GetScoreSet(5).Init;
userinfo.Extcredits6 = Scoresets.GetScoreSet(6).Init;
userinfo.Extcredits7 = Scoresets.GetScoreSet(7).Init;
userinfo.Extcredits8 = Scoresets.GetScoreSet(8).Init;
userinfo.Avatarshowid = 0;
userinfo.Bday = "";
userinfo.Sigstatus = 1;
userinfo.Tpp = 0;
userinfo.Ppp = 0;
userinfo.Templateid = 0;
userinfo.Pmsound = 1;
userinfo.Showemail = 0;
userinfo.Newsletter = ReceivePMSettingType.ReceiveAllPMWithHint;
userinfo.Invisible = 0;
userinfo.Newpm = 0;
userinfo.Medals = "";
if (config.Welcomemsg == 1)
{
userinfo.Newpm = 1;
}
userinfo.Accessmasks = 0;
userinfo.Website = "";
userinfo.Icq = "";
userinfo.Qq = "";
userinfo.Yahoo = "";
userinfo.Msn = "";
userinfo.Skype = "";
userinfo.Location = "";
userinfo.Customstatus = "";
userinfo.Avatar = @"avatars\common\0.gif";
userinfo.Avatarwidth = 0;
userinfo.Avatarheight = 0;
userinfo.Bio = "";
userinfo.Signature = "";
PostpramsInfo postpramsinfo = new PostpramsInfo();
postpramsinfo.Usergroupid = oluserinfo.Groupid;//7
postpramsinfo.Attachimgpost = config.Attachimgpost;//1
postpramsinfo.Showattachmentpath = config.Showattachmentpath;//0
postpramsinfo.Hide = 0;
postpramsinfo.Price = 0;
postpramsinfo.Sdetail = userinfo.Signature;
postpramsinfo.Smileyoff = 1;
postpramsinfo.Bbcodeoff = 1 - usergroupinfo.Allowsigbbcode;//1
postpramsinfo.Parseurloff = 1;
postpramsinfo.Showimages = usergroupinfo.Allowsigimgcode;//0
postpramsinfo.Allowhtml = 0;
postpramsinfo.Smiliesinfo = Smilies.GetSmiliesListWithInfo();
postpramsinfo.Customeditorbuttoninfo = Editors.GetCustomEditButtonListWithInfo();
postpramsinfo.Smiliesmax = config.Smiliesmax;//5
userinfo.Sightml = "";
//
userinfo.Authtime = Utils.GetDateTime();
userinfo.Authstr = "";
userinfo.Authflag = 0;
userinfo.Groupid = UserCredits.GetCreditsUserGroupID(0).Groupid;//10
userinfo.Realname = "";
userinfo.Idcard = "";
userinfo.Mobile = "";
userinfo.Phone = "";
int uid = Users.CreateUser(userinfo);
//根据积分公式刷新用户总积分
UserCredits.UpdateUserCredits(uid);
//写入用户登录后的cookie
ForumUtils.WriteUserCookie(uid, -1, config.Passwordkey);
//更新用户最后动作,如不需要可不执行
OnlineUsers.UpdateAction(oluserinfo.Olid, UserAction.Register.ActionID, 0, config.Onlinetimeout);
Statistics.ReSetStatisticsCache();
return true;
}
/**//// <summary>
/// 登陆论坛
/// </summary>
/// <param name="username"></param>
public static void Login(string username)
{
GeneralConfigInfo config = GeneralConfigs.GetConfig();
OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
int uid = Users.GetUserID(username);
//删除之前的错误登录信息
LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
//根据积分公式刷新用户总积分
UserCredits.UpdateUserCredits(uid);
//写入用户登录后的cookie
ForumUtils.WriteUserCookie(uid, -1, config.Passwordkey);
//更新用户最后动作,如不需要可不执行
OnlineUsers.UpdateAction(oluserinfo.Olid, UserAction.Login.ActionID, 0, config.Onlinetimeout);
//更新该用户最后访问时间
Users.UpdateUserLastvisit(uid, DNTRequest.GetIP());
}
/**//// <summary>
/// 论坛退出
/// </summary>
public static void Logout()
{
GeneralConfigInfo config = GeneralConfigs.GetConfig();
OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
if (oluserinfo.Userid > 0)
{
Users.UpdateOnlineTime(oluserinfo.Userid);
OnlineUsers.DeleteRows(oluserinfo.Olid);
ForumUtils.ClearUserCookie();
}
}
/**//// <summary>
/// 账号是否存在
/// 账号导入时使用[临时]
/// </summary>
/// <param name="username"></param>
/// <returns></returns>
public static bool Exists(string username)
{
return Users.Exists(username);
}
ForumUtils.cs的修改
/**//// <summary>
/// 获得论坛cookie值
/// </summary>
/// <param name="strName">项</param>
/// <returns>值</returns> public static string GetCookie(string strName)
{
//
// [add by wuhp] 2008-4-14
//
// 取Cookie中的用户id,
// 判断membership是否登陆,若登陆,获取membership当前账号的userid
if ("userid".Equals(strName))
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.Items["dnt_userid"] == null)
{
HttpContext.Current.Items["dnt_userid"] = Users.GetUserID(HttpContext.Current.User.Identity.Name);
}
return HttpContext.Current.Items["dnt_userid"].ToString();
}
return "";
}
//
// [add by wuhp] 2008-4-14
//
// 取Cookie中的口令
// 判断membership是否登陆,若登陆,获取membership当前账号的口令
if ("password".Equals(strName))
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.Items["dnt_password"] == null)
{
GeneralConfigInfo config = GeneralConfigs.GetConfig();
ShortUserInfo userinfo = Users.GetShortUserInfo(Users.GetUserID(HttpContext.Current.User.Identity.Name));
HttpContext.Current.Items["dnt_password"] = SetCookiePassword(userinfo.Password, config.Passwordkey);
}
return HttpContext.Current.Items["dnt_password"].ToString();
}
return "";
}
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies["dnt"] != null && HttpContext.Current.Request.Cookies["dnt"][strName] != null)
{
return Utils.UrlDecode(HttpContext.Current.Request.Cookies["dnt"][strName].ToString());
}
return "";
}