Develop Paper
  • Program
  • Server
  • Development Tool
  • Blockchain
  • Database
  • Artificial Intelligence
Position: Home > Blogs > Program Language > JSP > Content

Java (JSP) integration discuz synchronous login function

Time:2020-11-21

Recently, I did a project of resource database system. The teacher said that we can build an open source forum instead of developing social modules. I just saw an open source project in open source China that uses the UCenter function of discuz to realize synchronous login( https://code.google.com/p/discuz-ucenter-api-for-java/ )I can’t help but be overjoyed, so I spent a few hours following the tutorial and did it again Very easy to succeed, close up this article to do a memorial..

Uenter is a bridge for the direct transmission of information between Comsenz’s products. Through the UCenter webmaster, Comsenz series products can be integrated seamlessly to realize one-stop registration, login and exit of users. UCenter can make all Comsenz products more closely linked, realize the unified registration and login of users, and make the community really run. UCenter has a well-established interface, which can hook up the third-party network application program of any other platform after simple modification. As a traditional bridge of information, UCenter has a unified mechanism of SMS and friends. End users can easily pass through it in various applications without repeated login, registration and exit. The unified tag mechanism connects all applications in the community closely, so that users can travel freely in the community, quickly find the applications they need and get the best use experience.

First, the first step is to install Apache and pH

My versions are php-5.4.23-win32-vc9-x86 and httpd-2.2.25-win32-x86-openssl-0.9.8y

Basically, I didn’t encounter any special problems, except that the PHP and Apache versions did not match, which delayed some time, the rest were basically smooth.

If PHP has 2_ 4, you need to download a lower version of PHP, otherwise the Apache server will not be able to parse PHP files normally.

The second step is to install discuz. The version I installed is discuz_ X3.1_ SC_ UTF8.zip。 When installing, check new installation to install UCenter by the way. If you don’t install it, you need to download and install it yourself. The version is UCenter 1.5+

Step 3: start to configure the UCenter server (the program installed by UCenter)

As shown in the figure:

 

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

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

2. Configure a servlet for docking with UCenter

Copy codeThe code is 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. Put the configuration file( config.properties )Copy to the SRC directory

Copy codeThe code is as follows:
#
# ================================================
# * Discuz! Ucenter API for JAVA
# ================================================
# UC comunication settings
# 
#
#If the UC server URL is a new installation mode, UCenter can be installed with discuz. The path is
UC_ API = http: / / {discuz root} / 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. Put demo (JSP) in open source project_ demo.jsp )Copy to the root of the application. The original author’s JSP file encoding and file header have a little problem, so I modified it a little bit.

Copy codeThe code is as follows:
<%
/**
 * ================================================
 * Discuz! Ucenter API for JAVA
 * ================================================
* JSP call example
 *
* more information: http://code.google.com/p/discuz-ucenter-api-for-java/
* Author: Liang Ping (No_ [email protected] )
* created on: February 20, 2009
 */
%>
<%@ 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 succeeded”);
        out.println($username);
        out.println($password);
        out.println($email);

        String $ucsynlogin = uc.uc_user_synlogin($uid);
        out.println (“login succeeded” + $ucsylign);

/ / 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 (“the user does not exist or has been deleted”);
    } else if($uid == -2) {
        out.println (“wrong password”);
    } else {
        out.println (the “undefined”);
    }
}else{
    out.println(“Login failed”);
    System.out.println(result);
}
%>

If the example can run, then the registration of what can be directly read on the official website code to understand, very simple.

 

Tags: Discuz synchronous login

Recommended Today

Win10 shield can not be unloaded kb4577586 skills

Microsoft has already announced that it will not support flash at all by the end of this year. Now, Microsoft is on the move.Microsoft has made a new windows 10 patch kb4577586. The only function of this patch is to completely remove flash from the system. Note that once kb4577586 is installed, it cannot be […]

  • Using cookie and saving Chinese and using cookie to realize shopping cart function
  • The specific instance of displaying ArrayList to JSP page in action
  • Seven ways to improve response speed in JSP pages
  • Using JSP page to generate random verification code example
  • Introduction of definition and usage examples in JSP
  • IE9 alert block JSP rendering IE8 no problem
  • Java output the current date of the system
  • JSP page circulation collection operation arrangement
  • Two ways of re encoding data sent by browser by JSP
  • How to calculate the relative path of JSP
Pre: JS code associated with button and enter key
Next: Introduction to the use of pattern modifiers in regular expression tutorial

    Tags

    address algorithm android array assembly attribute Browser c Catalog Character string Client code command configuration file css data Database data base Edition element Example file function golang html html5 ios java javascript linux method mysql node node.js object page parameter php Plug-in unit project python Route source code The server user

    Recent Posts

    • Win10 shield can not be unloaded kb4577586 skills
    • Go version tensorflow installation tutorial
    • MacOS 11 Big Sur developer preview beta 7 officially launched
    • Anti avalanche sharp device: the principle and application of fuse hystrix
    • Using vimdiff instead of SVN diff to view code

    Recent Comments

    • imaxing on Answer for Promise then no dependency effect?
    • Zhang Wenjian on Answer for Promise then no dependency effect?
    • Zhang Wenjian on Answer for Promise then no dependency effect?
    • j_bleach on Answer for Promise then no dependency effect?
    • Zhang Wenjian on Answer for Promise then no dependency effect?

    Categories

    • .NET Core
    • Agile Development
    • Android
    • Apple MAC
    • Architecture Design
    • Artificial Intelligence
    • ASP.NET
    • Blockchain
    • C
    • C#
    • C++
    • Database
    • Development Tool
    • Embedded
    • Erlang
    • Freshman
    • Golang
    • HTML/CSS
    • HTML5
    • Information Security
    • IOS
    • Java
    • JavaScript
    • JSP
    • Linux
    • MongoDB
    • MsSql
    • MySql
    • OOP
    • oracle
    • Other DB
    • Other Technology
    • Perl
    • PHP
    • Program
    • Python
    • Redis
    • Regular Expression
    • Ruby
    • Rust
    • SAP
    • Server
    • VBS
    • VUE
    • WEB Front End
    • Windows
    • XML/XSLT
  • java
  • php
  • python
  • linux
  • windows
  • android
  • ios
  • mysql
  • html
  • .net
  • github
  • node.js

Copyright © 2020 Develop Paper All Rights Reserved   

  Sitemap    About DevelopPaper    Privacy Policy    Contact Us