Im development [5]-use email as the user name to log on to openfire

Source: Internet
Author: User
Home> instant messaging»
Im development using email as user name login openfireim development using email as user name login openfire Date: Author: firefish classification: instant messaging read: 3,242 comments: 5

Now there are many websites, especially websites labeled with "Web2.0", using email addresses as user names. The reason is not discussed in this article. This article describes how to build an IM (instant messaging) system based on the XMPP protocol when your website uses email as the user name, you want to log on to im directly with the user account of the website (another log in this blog, "log on to openfire with Django User Account", describes the basic construction of the system in detail, for more information, see.

What is it? Er, the problem lies in the "@" symbol in the email. In XMPP, @ is defined as a symbol with special purpose. The XMPP user name is called jid. jid consists of three parts, such:Test@abc.com/Resource. As you can see, the jid contains a @, followed by the username, followed by the domain, and the resource after the slash represents the name of the currently used client.

So obviously, the @ in the email conflicts with the @ In the jid! Of course XMPP, as a niux im protocol, has taken this into account and it is defined in the extended protocol XEP-0106.

The solution is to escape special characters in the user name. That is, the client performs a conversion after obtaining the user's login name. This ensures that the jid sent to the server is a valid string without conflict. XMPP defines the special character processing @ in addition to a few other, interested students Please slam here onlookers XEP-0106: jid escaping.

Openfire currently supports XEP-0106, which is defined in org. XMPP. packet. jid, escapenode and unescapenode. Client I am using gloox API, in Version 1.0, gloox also added support for XEP-0106, which can be found in jid. cpp. If you are using another client development kit that does not support XEP-0106, it's easy to write two functions as defined by the Protocol.

With these two functions, you can easily get the user input email on the client, call the escapenode function to escape the string, and use the escaped string as the user name to send a login request. For example, if the user name is a test@gmail.com, it becomes test \ 40@gmail.com after escaping.

After receiving the request, openfire calls the verification function (refer to another log in this blog, "log on to openfire with Django User Account" for custom verification) authenticate, this function uses the username and password provided by the client to query users in the User table. What we need to do is to convert the escaped @ symbol back before querying the database, as shown below:

Username = jid. unescapenode (username );

Another class that processes user information is the class pointed to by provider. User. classname of table ofproperty. The loaduser function of this class also needs to process username.

Now you can use email as the username to log on to the openfire-based IM system.

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.