復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
using Discuz.Common;
using Discuz.Forum;
using Discuz.Config;
using Discuz.Entity;
namespace DiscuzIntegration
{
public class Integration
{
public static void Login(string username, string password)
{
try
{
Discuz.Config.GeneralConfigInfo config = Discuz.Config.GeneralConfigs.GetConfig();
int uid = Users.GetUserID(username);
if (uid == -1 || !Users.Exists(uid))
{
Regedit(username, password);
uid = Users.GetUserID(username);
}
//刪除之前的錯誤登錄信息
LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
//根據積分公式刷新用戶總積分
UserCredits.UpdateUserCredits(uid);
//寫入用戶登錄後的cookie
ForumUtils.WriteUserCookie(uid, Utils.StrToInt(DNTRequest.GetString("expires"), -1), config.Passwordkey, DNTRequest.GetInt("templateid", 0), DNTRequest.GetInt("loginmode", -1));
//更新用戶最後動作,如不需要可不執行
//OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0, config.Onlinetimeout);
//更新該用戶最後訪問時間
Users.UpdateUserLastvisit(uid, DNTRequest.GetIP());
}
catch
{
}
}
public static void Logout(string username)
{
try
{
int uid = Users.GetUserID(username);
int olid = OnlineUsers.GetOlidByUid(uid);
OnlineUsers.DeleteRows(olid);
ForumUtils.ClearUserCookie();
}
catch
{
}
}
public static bool Regedit(string tmpUsername, string password)
{
try
{
//以下為用戶注冊代碼
Discuz.Config.GeneralConfigInfo config = Discuz.Config.GeneralConfigs.GetConfig();
UserGroupInfo usergroupinfo = new UserGroupInfo();
usergroupinfo.Groupid = 10; //新手上路
//如果用戶名符合注冊規則, 則判斷是否已存在
if (Users.Exists(tmpUsername))
{
//
// 這裡提示錯誤信息"用戶名已經存在!"
//
return false;
}
UserInfo __userinfo = new UserInfo();
__userinfo.Username = Utils.HtmlEncode(tmpUsername);
__userinfo.Nickname = Utils.HtmlEncode(DNTRequest.GetString(""));
__userinfo.Password = Utils.MD5(password);
__userinfo.Secques = "";// ForumUtils.GetUserSecques(DNTRequest.GetInt("question", 0), DNTRequest.GetString("answer"));
__userinfo.Gender = DNTRequest.GetInt("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.Email = "";
__userinfo.Bday = "";
__userinfo.Sigstatus = DNTRequest.GetInt("sigstatus", 0);
if (__userinfo.Sigstatus != 0)
{
__userinfo.Sigstatus = 1;
}
__userinfo.Tpp = DNTRequest.GetInt("tpp", 0);
__userinfo.Ppp = DNTRequest.GetInt("ppp", 0);
__userinfo.Templateid = DNTRequest.GetInt("templateid", 1);
__userinfo.Pmsound = DNTRequest.GetInt("pmsound", 0);
__userinfo.Showemail = DNTRequest.GetInt("showemail", 0);
int receivepmsetting = 1;
foreach (string rpms in DNTRequest.GetString("receivesetting").Split(','))
{
if (rpms != string.Empty)
{
int tmp = int.Parse(rpms);
receivepmsetting = receivepmsetting | tmp;
}
}
if (config.Regadvance == 0)
{
receivepmsetting = 7;
}
__userinfo.Newsletter = (ReceivePMSettingType)receivepmsetting;
__userinfo.Invisible = DNTRequest.GetInt("invisible", 0);
__userinfo.Newpm = 0;
__userinfo.Medals = "";
if (config.Welcomemsg == 1)
{
__userinfo.Newpm = 1;
}
__userinfo.Accessmasks = DNTRequest.GetInt("accessmasks", 0);
//
__userinfo.Website = Utils.HtmlEncode(DNTRequest.GetString("website"));
__userinfo.Icq = Utils.HtmlEncode(DNTRequest.GetString("icq"));
__userinfo.Qq = Utils.HtmlEncode(DNTRequest.GetString("qq"));
__userinfo.Yahoo = Utils.HtmlEncode(DNTRequest.GetString("yahoo"));
__userinfo.Msn = Utils.HtmlEncode(DNTRequest.GetString("msn"));
__userinfo.Skype = Utils.HtmlEncode(DNTRequest.GetString("skype"));
__userinfo.Location = Utils.HtmlEncode(DNTRequest.GetString("location"));
if (usergroupinfo.Allowcstatus == 1)
{
__userinfo.Customstatus = Utils.HtmlEncode(DNTRequest.GetString("customstatus"));
}
else
{
__userinfo.Customstatus = "";
}
__userinfo.Avatar = @"avatars\common\0.gif";
__userinfo.Avatarwidth = 0;
__userinfo.Avatarheight = 0;
__userinfo.Bio = DNTRequest.GetString("bio");
__userinfo.Signature = Utils.HtmlEncode(ForumUtils.BanWordFilter(DNTRequest.GetString("signature")));
PostpramsInfo _postpramsinfo = new 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 = Smilies.GetSmiliesListWithInfo();
_postpramsinfo.Customeditorbuttoninfo = Editors.GetCustomEditButtonListWithInfo();
_postpramsinfo.Smiliesmax = config.Smiliesmax;
__userinfo.Sightml = UBB.UBBToHTML(_postpramsinfo);
//
__userinfo.Authtime = Utils.GetDateTime();
//郵箱激活鏈接驗證
if (config.Regverify == 1)
{
__userinfo.Authstr = ForumUtils.CreateAuthStr(20);
__userinfo.Authflag = 1;
__userinfo.Groupid = 8;
//SendEmail(tmpUsername, DNTRequest.GetString("password").Trim(), DNTRequest.GetString("email").Trim(), __userinfo.Authstr);
}
//系統管理員進行後台驗證
else if (config.Regverify == 2)
{
__userinfo.Authstr = DNTRequest.GetString("website");
__userinfo.Groupid = 8;
__userinfo.Authflag = 1;
}
else
{
__userinfo.Authstr = "";
__userinfo.Authflag = 0;
__userinfo.Groupid = UserCredits.GetCreditsUserGroupID(0).Groupid;
}
__userinfo.Realname = DNTRequest.GetString("realname");
__userinfo.Idcard = DNTRequest.GetString("idcard");
__userinfo.Mobile = DNTRequest.GetString("mobile");
__userinfo.Phone = DNTRequest.GetString("phone");
int uid = Users.CreateUser(__userinfo);
if (config.Welcomemsg == 1)
{
PrivateMessageInfo __privatemessageinfo = new PrivateMessageInfo();
string curdatetime = Utils.GetDateTime();
// 收件箱
__privatemessageinfo.Message = config.Welcomemsgtxt;
__privatemessageinfo.Subject = "歡迎您的加入! (請勿回復本信息)";
__privatemessageinfo.Msgto = __userinfo.Username;
__privatemessageinfo.Msgtoid = uid;
__privatemessageinfo.Msgfrom = PrivateMessages.SystemUserName;
__privatemessageinfo.Msgfromid = 0;
__privatemessageinfo.New = 1;
__privatemessageinfo.Postdatetime = curdatetime;
__privatemessageinfo.Folder = 0;
PrivateMessages.CreatePrivateMessage(__privatemessageinfo, 0);
}
if (config.Regverify == 0)
{
UserCredits.UpdateUserCredits(uid);
//ForumUtils.WriteUserCookie(uid, -1, config.Passwordkey);
OnlineUsers.UpdateAction(0, UserAction.Register.ActionID, 0, config.Onlinetimeout);
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 static bool Delete(string userName)
{
int uid = Users.GetUserID(userName);
if (Convert.ToInt32(uid) > 1) //判斷是不是當前UID是不是系統初始化時生成的UID
{
int deluserid = Convert.ToInt32(uid);
AdminUsers.DelUserAllInf(deluserid, true, true);
return true;
}
return false;
}
public static bool ChangePassword(string userName, string password)
{
try
{
int uid = Users.GetUserID(userName);
return Users.UpdateUserPassword(uid, password);
}
catch
{
return false;
}
//UserFactory.UpdateUserPassword(uid, newpassword);
//ForumUtils.WriteCookie("password", ForumUtils.SetCookiePassword(Utils.MD5(newpassword), config.Passwordkey));
//OnlineUserFactory.UpdatePassword(olid, Utils.MD5(newpassword));
}
}
}