asp.net discuznt Login, exit code _ Practical Tips

Source: Internet
Author: User
Copy Code code 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 previous error logon information
Loginlogs.deleteloginlog (Dntrequest.getip ());
Refresh user total points according to integral formula
Usercredits.updateusercredits (UID);
Write cookie after user logs in
Forumutils.writeusercookie (UID, Utils.strtoint (dntrequest.getstring ("Expires"),-1), CONFIG. Passwordkey, Dntrequest.getint ("TemplateID", 0), Dntrequest.getint ("LoginMode",-1));
Update user last action, if no need to execute
Onlineusers.updateaction (Olid, UserAction.Login.ActionID, 0, config.) Onlinetimeout);
Update the last access time for this 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; Novice on the road
If the user name conforms to the registration rule, determine if it already exists
if (users.exists (tmpusername))
{
//
This prompts for the error message "The username 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 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 ();
Mailbox Activation Link Validation
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);
}
System administrator for background validation
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 you to join!" (Please do not reply to this information) ";
__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);
Add code here to "register successfully, go back to login page" and return to exit
//...
//
return true;
}
Else
{
SetUrl ("index.aspx");
Setmetarefresh (5);
Setshowbacklink (FALSE);
if (config. regverify = 1)
{
Here to add code hint "Registration is successful, please click on the activation link in your mailbox to activate your account" and return exit
//...
//
}
if (config. Regverify = 2)
{
Add code here that "you registered successfully, but you need the system administrator to audit your account before you can log in" 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)//Determine if the current UID is not the UID generated by 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.