以下全是代码:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Discuz.Forum;
using Discuz.Plugin;
using Discuz.Data;
using Discuz.Entity;
using Discuz.Config;
using Discuz.Common;
using Discuz.Cache;
namespace zhenghe
{
public class zl
{
public void Login(string username, string password)
{
try
{
Discuz.Config.GeneralConfigInfo config = Discuz.Config.GeneralConfigs.GetConfig();
// int uid =
int uid = Discuz.Forum.Users.GetUserID(username);
if (uid == -1 || !Discuz.Forum.Users.Exists(uid))
{
Regedit(username, password);
uid = Discuz.Forum.Users.GetUserID(username);
}
//删除之前的错误登录信息
Discuz.Forum.LoginLogs.DeleteLoginLog(Discuz.Common.DNTRequest.GetIP());
//根据积分公式刷新用户总积分
Discuz.Forum.UserCredits.UpdateUserCredits(uid);
//写入用户登录后的cookie
Discuz.Forum.ForumUtils.WriteUserCookie(uid, Discuz.Common.Utils.StrToInt(Discuz.Common.DNTRequest.GetString("expires"), -1), config.Passwordkey, Discuz.Common.DNTRequest.GetInt("templateid", 0), Discuz.Common.DNTRequest.GetInt("loginmode", -1));
//更新用户最后动作,如不需要可不执行
//Discuz.Forum.OnlineUsers.UpdateAction(olid, Discuz.Forum.UserAction.Login.ActionID, 0, config.Onlinetimeout);
//更新该用户最后访问时间
Discuz.Forum.Users.UpdateUserLastvisit(uid, Discuz.Common.DNTRequest.GetIP());
}
catch
{
}
}
public void Logout(string username)
{
try
{
int uid = Discuz.Forum.Users.GetUserID(username);
int olid = Discuz.Forum.OnlineUsers.GetOlidByUid(uid);
Discuz.Forum.OnlineUsers.DeleteRows(olid);
Discuz.Forum.ForumUtils.ClearUserCookie();
}
catch
{
}
}
public bool Regedit(string tmpUsername, string password)
{
try
{
//以下为用户注册代码
Discuz.Config.GeneralConfigInfo config = Discuz.Config.GeneralConfigs.GetConfig();
Discuz.Entity.UserGroupInfo usergroupinfo = new Discuz.Entity.UserGroupInfo();
usergroupinfo.Groupid = 10; //新手上路
//如果用户名符合注册规则, 则判断是否已存在
if (Discuz.Forum.Users.Exists(tmpUsername))
{
//
// 这里提示错误信息"用户名已经存在!"
//
return false;
}
Discuz.Entity.UserInfo __userinfo = new Discuz.Entity.UserInfo();
__userinfo.Username = Discuz.Common.Utils.HtmlEncode(tmpUsername);
__userinfo.Nickname = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString(""));
__userinfo.Password = Discuz.Common.Utils.MD5(password);
__userinfo.Secques = "";// Discuz.Forum.ForumUtils.GetUserSecques(Discuz.Common.DNTRequest.GetInt("question", 0), Discuz.Common.DNTRequest.GetString("answer"));
__userinfo.Gender = Discuz.Common.DNTRequest.GetInt("gender", 0);
__userinfo.Adminid = 0;
__userinfo.Groupexpiry = 0;
__userinfo.Extgroupids = "";
__userinfo.Regip = Discuz.Common.DNTRequest.GetIP();
__userinfo.Joindate = Discuz.Common.Utils.GetDateTime();
__userinfo.Lastip = Discuz.Common.DNTRequest.GetIP();
__userinfo.Lastvisit = Discuz.Common.Utils.GetDateTime();
__userinfo.Lastactivity = Discuz.Common.Utils.GetDateTime();
__userinfo.Lastpost = Discuz.Common.Utils.GetDateTime();
__userinfo.Lastpostid = 0;
__userinfo.Lastposttitle = "";
__userinfo.Posts = 0;
__userinfo.Digestposts = 0;
__userinfo.Oltime = 0;
__userinfo.Pageviews = 0;
__userinfo.Credits = 0;
__userinfo.Extcredits1 = Discuz.Forum.Scoresets.GetScoreSet(1).Init;
__userinfo.Extcredits2 = Discuz.Forum.Scoresets.GetScoreSet(2).Init;
__userinfo.Extcredits3 = Discuz.Forum.Scoresets.GetScoreSet(3).Init;
__userinfo.Extcredits4 = Discuz.Forum.Scoresets.GetScoreSet(4).Init;
__userinfo.Extcredits5 = Discuz.Forum.Scoresets.GetScoreSet(5).Init;
__userinfo.Extcredits6 = Discuz.Forum.Scoresets.GetScoreSet(6).Init;
__userinfo.Extcredits7 = Discuz.Forum.Scoresets.GetScoreSet(7).Init;
__userinfo.Extcredits8 = Discuz.Forum.Scoresets.GetScoreSet(8).Init;
__userinfo.Avatarshowid = 0;
__userinfo.Email = "";
__userinfo.Bday = "";
__userinfo.Sigstatus = Discuz.Common.DNTRequest.GetInt("sigstatus", 0);
if (__userinfo.Sigstatus != 0)
{
__userinfo.Sigstatus = 1;
}
__userinfo.Tpp = Discuz.Common.DNTRequest.GetInt("tpp", 0);
__userinfo.Ppp = Discuz.Common.DNTRequest.GetInt("ppp", 0);
__userinfo.Templateid = Discuz.Common.DNTRequest.GetInt("templateid", 1);
__userinfo.Pmsound = Discuz.Common.DNTRequest.GetInt("pmsound", 0);
__userinfo.Showemail = Discuz.Common.DNTRequest.GetInt("showemail", 0);
int receivepmsetting = 1;
foreach (string rpms in Discuz.Common.DNTRequest.GetString("receivesetting").Split(','))
{
if (rpms != string.Empty)
{
int tmp = int.Parse(rpms);
receivepmsetting = receivepmsetting | tmp;
}
}
if (config.Regadvance == 0)
{
receivepmsetting = 7;
}
__userinfo.Newsletter = (Discuz.Entity.ReceivePMSettingType)receivepmsetting;
__userinfo.Invisible = Discuz.Common.DNTRequest.GetInt("invisible", 0);
__userinfo.Newpm = 0;
__userinfo.Medals = "";
if (config.Welcomemsg == 1)
{
__userinfo.Newpm = 1;
}
__userinfo.Accessmasks = Discuz.Common.DNTRequest.GetInt("accessmasks", 0);
//
__userinfo.Website = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("website"));
__userinfo.Icq = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("icq"));
__userinfo.Qq = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("qq"));
__userinfo.Yahoo = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("yahoo"));
__userinfo.Msn = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("msn"));
__userinfo.Skype = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("skype"));
__userinfo.Location = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("location"));
if (usergroupinfo.Allowcstatus == 1)
{
__userinfo.Customstatus = Discuz.Common.Utils.HtmlEncode(Discuz.Common.DNTRequest.GetString("customstatus"));
}
else
{
__userinfo.Customstatus = "";
}
__userinfo.Avatar = @"avatars\\common\\0.gif";
__userinfo.Avatarwidth = 0;
__userinfo.Avatarheight = 0;
__userinfo.Bio = Discuz.Common.DNTRequest.GetString("bio");
__userinfo.Signature = Discuz.Common.Utils.HtmlEncode(Discuz.Forum.ForumUtils.BanWordFilter(Discuz.Common.DNTRequest.GetString("signature")));
Discuz.Entity.PostpramsInfo _postpramsinfo = new Discuz.Entity.PostpramsInfo();
_postpramsinfo.Usergroupid = usergroupinfo.Groupid;
_postpramsinfo.Attachimgpost = config.Attachimgpost;
_postpramsinfo.Showattachmentpath = config.Showattachmentpath;
_postpramsinfo.Hide = 0;
_postpramsinfo.Price = 0;
_postpramsinfo.Sdetail = __userinfo.Signature;
_postpramsinfo.Smileyoff = 1;
_postpramsinfo.Bbcodeoff = 1 - usergroupinfo.Allowsigbbcode;
_postpramsinfo.Parseurloff = 1;
_postpramsinfo.Showimages = usergroupinfo.Allowsigimgcode;
_postpramsinfo.Allowhtml = 0;
_postpramsinfo.Smiliesinfo = Discuz.Forum.Smilies.GetSmiliesListWithInfo();
_postpramsinfo.Customeditorbuttoninfo = Discuz.Forum.Editors.GetCustomEditButtonListWithInfo();
_postpramsinfo.Smiliesmax = config.Smiliesmax;
__userinfo.Sightml = Discuz.Forum.UBB.UBBToHTML(_postpramsinfo);
//
__userinfo.Authtime = Discuz.Common.Utils.GetDateTime();
//邮箱激活链接验证
if (config.Regverify == 1)
{
__userinfo.Authstr = Discuz.Forum.ForumUtils.CreateAuthStr(20);
__userinfo.Authflag = 1;
__userinfo.Groupid = 8;
//SendEmail(tmpUsername, Discuz.Common.DNTRequest.GetString("password").Trim(), Discuz.Common.DNTRequest.GetString("email").Trim(), __userinfo.Authstr);
}
//系统管理员进行后台验证
else if (config.Regverify == 2)
{
__userinfo.Authstr = Discuz.Common.DNTRequest.GetString("website");
__userinfo.Groupid = 8;
__userinfo.Authflag = 1;
}
else
{
__userinfo.Authstr = "";
__userinfo.Authflag = 0;
__userinfo.Groupid = Discuz.Forum.UserCredits.GetCreditsUserGroupID(0).Groupid;
}
__userinfo.Realname = Discuz.Common.DNTRequest.GetString("realname");
__userinfo.Idcard = Discuz.Common.DNTRequest.GetString("idcard");
__userinfo.Mobile = Discuz.Common.DNTRequest.GetString("mobile");
__userinfo.Phone = Discuz.Common.DNTRequest.GetString("phone");
int uid = Discuz.Forum.Users.CreateUser(__userinfo);
if (config.Welcomemsg == 1)
{
Discuz.Entity.PrivateMessageInfo __privatemessageinfo = new Discuz.Entity.PrivateMessageInfo();
string curdatetime = Discuz.Common.Utils.GetDateTime();
// 收件箱
__privatemessageinfo.Message = config.Welcomemsgtxt;
__privatemessageinfo.Subject = "欢迎您的加入! (请勿回复本信息)";
__privatemessageinfo.Msgto = __userinfo.Username;
__privatemessageinfo.Msgtoid = uid;
__privatemessageinfo.Msgfrom = Discuz.Forum.PrivateMessages.SystemUserName;
__privatemessageinfo.Msgfromid = 0;
__privatemessageinfo.New = 1;
__privatemessageinfo.Postdatetime = curdatetime;
__privatemessageinfo.Folder = 0;
Discuz.Forum.PrivateMessages.CreatePrivateMessage(__privatemessageinfo, 0);
}
if (config.Regverify == 0)
{
Discuz.Forum.UserCredits.UpdateUserCredits(uid);
//Discuz.Forum.ForumUtils.WriteUserCookie(uid, -1, config.Passwordkey);
Discuz.Forum.OnlineUsers.UpdateAction(0, Discuz.Forum.UserAction.Register.ActionID, 0, config.Onlinetimeout);
Discuz.Forum.Statistics.ReSetStatisticsCache();
//SetUrl("index.aspx");
//SetMetaRefresh();
//SetShowBackLink(false);
//这里添加代码提示“注册成功, 返回登录页"并return退出
//...
//
return true;
}
else
{
//SetUrl("index.aspx");
//SetMetaRefresh(5);
//SetShowBackLink(false);
if (config.Regverify == 1)
{
//这里添加代码提示“注册成功, 请您到您的邮箱中点击激活链接来激活您的帐号"并return退出
//...
//
}
if (config.Regverify == 2)
{
//这里添加代码提示“您注册成功, 但需要系统管理员审核您的帐户后才可登陆使用"并return退出
//...
//
}
return true;
}
}
catch
{
return false;
}
}
public bool Delete(string userName)
{
int uid = Discuz.Forum.Users.GetUserID(userName);
if (Convert.ToInt32(uid) > 1) //判断是不是当前UID是不是系统初始化时生成的UID
{
int deluserid = Convert.ToInt32(uid);
Discuz.Forum.AdminUsers.DelUserAllInf(deluserid, true, true);
return true;
}
return false;
}
public bool ChangePassword(string userName, string password)
{
try
{
int uid = Discuz.Forum.Users.GetUserID(userName);
return Discuz.Forum.Users.UpdateUserPassword(uid, password);
}
catch
{
return false;
}
//UserFactory.UpdateUserPassword(uid, newpassword);
//Discuz.Forum.ForumUtils.WriteCookie("password", Discuz.Forum.ForumUtils.SetCookiePassword(Discuz.Common.Utils.MD5(newpassword), config.Passwordkey));
//OnlineUserFactory.UpdatePassword(olid, Discuz.Common.Utils.MD5(newpassword));
}
}
}