Java (JSP) consolidated Discuz Synchronous Login features detailed _jsp programming

Source: Internet
Author: User
Tags auth win32

Recently done a resource library system project, the teacher said can build open source forum instead of their own development of social modules, just in open source China saw a use of discuz ucenter function to achieve synchronous login Open Source project (https://code.google.com/p/ discuz-ucenter-api-for-java/), can not help but exultation, so spent a few hours to follow the tutorial operation, incredibly easy success, close-up this article to do a souvenir.

Uenter is a Comsenz of the various products of the direct transmission of information between the bridge, through the Ucenter webmaster can seamlessly integrate Comsenz series of products, to achieve a user's one-stop registration, login, exit. Ucenter can make all the products of Comsenz more closely linked to achieve the user's unified registration login, so that the community really running. Ucenter has a well-established interface that can be easily modified to hook up a third-party network application on any other platform. Ucenter as a traditional bridge of information, with a unified message, friend mechanism, the end users can easily access through the various applications, no need to repeat login, registration, exit. The unified tagging (tag) mechanism, which connects the various applications in the community, allows users to travel freely within the community, quickly find the applications they need, and get the best use experience.

First of all, the first step is to install Apache and ph

My version is php-5.4.23-win32-vc9-x86 and httpd-2.2.25-win32-x86-openssl-0.9.8y.


Basically did not encounter any particular problem, in addition to the PHP and Apache version of the lack of matching delay a little time, the rest basically smooth.

If PHP inside is 2_4, then need to download a low version of PHP, otherwise will cause the Apache server cannot parse php file normally.

The second step, install Discuz, I installed the version is discuz_x3.1_sc_utf8.zip. Install the time to check the new installation will be installed Ucenter, if not installed, you need to download the installation, version of ucenter1.5+

Step three, start configuring the Ucenter server side (the one that ucenter installed)

As shown in figure:


The third step is to configure our own program, which is the client.

1. Copy the jar package https://code.google.com/p/discuz-ucenter-api-for-java/downloads/list in the Open source project

2. Configure a servlet for docking with the Ucenter

Copy Code code as follows:

<servlet>
<servlet-name>connect_discuz</servlet-name>
<servlet-class>com.fivestars.interfaces.bbs.api.UC</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>connect_discuz</servlet-name>
<url-pattern>/api/uc.php</url-pattern>
</servlet-mapping>

3. Copy the configuration file (config.properties) to the SRC directory

Copy Code code as follows:

#
# ================================================
# * discuz! Ucenter API for JAVA
# ================================================
# UC Comunication Settings
#
#
#uc Server URL If it is a newly installed mode, Ucenter can be installed with Discuz, the path is
UC_API = http://{discuz root directory}/uc_server
#uc IP Address
UC_IP = 127.0.0.1

#key
Uc_key = Yunstudio

#appid
Uc_appid = 2

#connect Mode:default value is ""
Uc_connect =

4. Copy the demo (jsp_demo.jsp) in the open source project to the root directory of the application. The original author's jsp file encoding and file headers have a little problem, so I slightly modified a bit.

Copy Code code as follows:

<%
/**
* ================================================
* discuz! Ucenter API for JAVA
* ================================================
* JSP Call Example
*
* More information: http://code.google.com/p/discuz-ucenter-api-for-java/
* Author: liangping (no_ten@163.com)
* Date Created: 2009-2-20
*/
%>
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ page import= "Com.fivestars.interfaces.bbs.util.XMLHelper"%>
<%@ page import= "Com.fivestars.interfaces.bbs.client.Client"%>
<%
Client UC = new Client ();
String result = Uc.uc_user_login ("admin", "Yun");

Linkedlist<string> rs = xmlhelper.uc_unserialize (result);
if (Rs.size () >0) {
int $uid = integer.parseint (rs.get (0));
String $username = rs.get (1);
String $password = Rs.get (2);
String $email = Rs.get (3);
if ($uid > 0) {
Response.AddHeader ("P3P", "cp=\" cura ADMa DEVa Psao psdo our bus UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP cor\ "");

OUT.PRINTLN ("Login Successful");
Out.println ($username);
Out.println ($password);
Out.println ($email);

String $ucsynlogin = Uc.uc_user_synlogin ($uid);
OUT.PRINTLN ("Login Successful" + $ucsynlogin);

Local Login Code
Todo.......

Cookie auth = new Cookie ("Auth", Uc.uc_authcode ($password + "\ T" + $uid, "ENCODE"));
Auth.setmaxage (31536000);
Auth.setdomain ("localhost");
Response.addcookie (auth);

Cookie user = new Cookie ("Uchome_loginuser", $username);
Response.addcookie (user);

else if ($uid = = 1) {
OUT.PRINTLN ("User does not exist, or is deleted");
else if ($uid = = 2) {
OUT.PRINTLN ("Wrong password");
} else {
Out.println ("undefined");
}
}else{
Out.println ("Login failed");
SYSTEM.OUT.PRINTLN (result);
}
%>

If the example can be run up, then the registration log out of what can be directly reader online code to understand, very simple.


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.