asp.net DiscuzNT登录,退出的代码
程序员文章站
2024-03-11 22:19:49
复制代码 代码如下:using system; using system.collections.generic; using system.text; using dis...
复制代码 代码如下:
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));
}
}
}