Asp.net DiscuzNT logon and exit code

Source: Internet
Author: User

Copy codeThe Code is as follows:
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 );
}
// Delete the previous error logon information
LoginLogs. DeleteLoginLog (DNTRequest. GetIP ());
// Refresh the total user points based on the Integral Formula
UserCredits. UpdateUserCredits (uid );
// Write the cookie after User Login
ForumUtils. writeUserCookie (uid, Utils. strToInt (DNTRequest. getString ("expires"),-1), config. passwordkey, DNTRequest. getInt ("templateid", 0), DNTRequest. getInt ("loginmode",-1 ));
// Update the last user action. Do not execute this action unless necessary.
// OnlineUsers. UpdateAction (olid, UserAction. Login. ActionID, 0, config. Onlinetimeout );
// Update the last access time of the user
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
{
// The following is the user registration code
Discuz. Config. GeneralConfigInfo config = Discuz. Config. GeneralConfigs. GetConfig ();
UserGroupInfo usergroupinfo = new UserGroupInfo ();
Usergroupinfo. Groupid = 10; // get started
// If the user name meets the registration rules, determine whether the user name already exists
If (Users. Exists (tmpUsername ))
{
//
// The error message "the user name already exists! "
//
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 required epmsetting = 1;
Foreach (string rpms in DNTRequest. GetString ("receivesetting"). Split (','))
{
If (rpms! = String. Empty)
{
Int tmp = int. Parse (rpms );
Paiepmsetting = paiepmsetting | tmp;
}
}
If (config. Regadvance = 0)
{
Paiepmsetting = 7;
}
_ Userinfo. Newsletter = (paiepmsettingtype) paiepmsetting;
_ 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 ();
// Email activation link verification
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 );
}
// The system administrator performs background verification.
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 ();
// Inbox
_ Privatemessageinfo. Message = config. Welcomemsgtxt;
_ Privatemessageinfo. Subject = "welcome to join us! (Do not reply to this message )";
_ 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 );
// When the code is added, the system prompts "registration successful. return to the logon page" and return to exit.
//...
//
Return true;
}
Else
{
// SetUrl ("index. aspx ");
// SetMetaRefresh (5 );
// SetShowBackLink (false );
If (config. Regverify = 1)
{
// The code is added to indicate "registration successful. Please click the activation link in your email address to activate your account" and return to exit
//...
//
}
If (config. Regverify = 2)
{
// The code is added to indicate that "You have registered successfully, but the system administrator must review your account before you can log on to use" and return to exit.
//...
//
}
Return true;
}
}
Catch
{
Return false;
}
}
Public static bool Delete (string userName)
{
Int uid = Users. GetUserID (userName );
If (Convert. ToInt32 (uid)> 1) // determines whether the current UID is the UID generated during system initialization.
{
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 ));
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.