asp.net DiscuzNT登录,退出的代码
2024-09-11 09:06:34
供稿:网友
代码如下:
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;