Java (JSP) consolidated Discuz Synchronous Login function detailed

Source: Internet
Author: User
Tags auth php file php and win32 root directory

JSP Integration Discuz Synchronous Login features detailed, Uenter is comsenz its products between the direct transmission of a bridge, through Ucenter webmaster can seamlessly integrate Comsenz series of products, center has a complete mechanism of the interface, A third party network application that can be hooked up to any other platform after a simple modification

recently made a project on the resource pool system, the teacher said that 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, the installation of Apache and ph my version for 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 because of the PHP and Apache version of the delay time, the rest of the basic 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 installation of a new installation Ucenter, if not installed, you need to download the installation, the version of ucenter1.5+ the third step, start to configure the Ucenter server (that is, Ucenter installed the program) as shown:             Step three, configure our own program, that is, the client.   1 The jar package https://code.google.com/p/discuz-ucenter-api-for-java/downloads/list   2 in the open source project. Configure a servlet     code for docking with Ucenter 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 under     code as follows: # # ================================== ============== # * discuz! Ucenter API for JAVA # ================================================ # UC comunication Settings #   #  #UC Server URL If it is a completely new installation 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 &N Bsp #key Uc_key = yunstudio   #appid uc_appid = 2   #connect mode:default value is "" Uc_connect =     &N Bsp 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.     Code as follows: <%/**  * ================================================  * discuz! Ucenter API for JAVA  * ================================================  * JSP Call Sample  *   * 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); &nbs P   String $password = Rs.get (2);     String $email = Rs.get (3);     if ($uid > 0) {        Response.AddHeader ("P3P", "cp=" cura ADMa DEVa Psao psdo our BU S 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 Success" + $ucsynlogin);          //Local Login code        //todo ...           Cookie auth = new Cookie ("Auth", Uc.uc_authcode ($password + "T" + $uid, "ENCODE"));     &NBSp   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 not present, or deleted");    } else if ($uid = = 2) {        out.println ("Wrong password");    } else {        OUT.PR Intln ("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.