ASP. NET forums, hereinafter referred to as ANF, version 2.0. In this article, the Coefficient Flow account only records the current work and has no technical content.
The existing system already has its own user system and needs to be mounted to ANF. It must be reflected in anf when you register, log on, and change the password of an existing system user. User changes in ANF are not required to affect existing systems, but only one-way synchronization is required.
Find a simple way to integrate without moving any existing code as much as possible. I have read the integration solution of CnForums of Baoyu and existing systems, finally, lazy decides to append the user information and operation type to the url after the above actions of the existing system are completed and pass it to a new page to process related operations in ANF.
This new page is currently called bridge. aspx. Of course, you need to create using in the ANF project. It is responsible for receiving username, password, and other information and then performing corresponding ANF operations.
- Register
Registration is very simple. My Username and Password are self-packaged attributes. To obtain information from the Request, we can add one without Email. Next we need to set AccountStatus to pass and IsAnonymous to turn it off. The bool parameter in Users. Create indicates whether to send the email with the registration success prompt to the user. Of course, I disabled the email.
Note that I catch errors everywhere without returning them. You do not have to do this.
Public void register ()
{
Try
{
User user = new user ();
User. Username = username;
User. Password = password;
User. Email = "Anonymous@Anonymous.com ";
User. AccountStatus = UserAccountStatus. Approved;
User. IsAnonymous = false;
Users. Create (user, false );
}
Catch
{
}
}
- Login
Basically, it is copied and pasted. Note that the last setcookie is the key to synchronous login.
Public void Login ()
{
Try
{
User userToLogin = new User ();
UserToLogin. Username = Username;
UserToLogin. Password = Password;
LoginUserStatus loginStatus = Users. ValidUser (userToLogin );
If (loginStatus = LoginUserStatus. Success)
{
If (! Globals. GetSiteSettings (). AllowLogin)
{
Bool allowed = false;
Int userid = Users. FindUserByUsername (userToLogin. Username). UserID;
ArrayList roles = Roles. GetRoles (userid );
Foreach (Role role in roles)
{
If (role. Name = "site administrators" | role. Name = "Global Administrators ")
{
Allowed = true;
Break;
}
}
If (! Allowed)
{
Return;
}
}
Set_Cookie (userToLogin. Username, "1 ");
}
}
Catch
{
}
}
- Change Password
This assumption is based on the fact that the logon has occurred. If this is not the case, you need to add your own judgment.
Public void ChangePassword ()
{
Try
{
ForumContext forumContext = ForumContext. Current;
User user = forumContext. User;
If (user! = Null)
{
User. ChangePassword (Password, NewPassword );
}
}
Catch
{
}
}
Public void set_Cookie (string Username, string Selet_item)
{
If (Selet_item = "0 ")
{
FormsAuthentication. SetAuthCookie (Username, false );
}
Else
{
Forumcontext = forumcontext. Current;
Formsauthentication. setauthcookie (username, true );
Forumcontext. Context. response. Cookies [formsauthentication. formscookiename]. expires = datetime. Now. adddays (system. Convert. toint32 (selet_item ));
}
}
Finally, register with the existing system, log on, and modify the last Response. Redirect page. If you do not like Redirect, Server. Transfer, and xmlhttp, you can see what you need. Another key point is to encrypt the character string you transmitted, or use plain text ...... ※¥ ※×% ※× If it is not secure, use an ip address to determine who can access this page!