Bmob Cloud enables registration and login functions

Source: Internet
Author: User

I'd like to introduce you to a back-end cloud service that I feel very bmob cloud

With Bmob Cloud We can realize the function of registration and login page, let me show you how to realize these two functions with bmob cloud service.

1. The user is the core of an application. For individual developers, the more users they build into their applications, the more creative power they will bring. Therefore, Bmob provides a dedicated user class--bmobuser to automatically handle the functions required for user account management.

With this class, you can add user account functionality to your application.

Bmobuser is a subclass of Bmobobject that inherits all Bmobobject methods and has the same functionality as Bmobobject. The difference is that Bmobuser adds some specific features related to user account management.

Bmobuser In addition to the attributes inherited from Bmobobject, there are several specific properties:
Username: User's user name (必需)
Password: User's password (必需)
Email: User's e-mail address (可选)
Emailverified: Mailbox Authentication Status (可选)
Mobilephonenumber: Mobile phone number (可选)
Mobilephonenumberverified: Authentication status of mobile phone number (可选)。 These properties are bmobuser, and we can no longer write these attributes in the entity class. Note If you override these properties, the program will receive an error. more code implementation you can download the SDK, find the class in the inside BmobExample MyUser , refer to its usage. The example I introduced here does not write any other attributes, but it is implemented directly from the internal properties of the system. Code for the registration page:
Bmobuser bu =NewBmobuser ();
If the user name and password are entered, then you have to add a sentence to determine whether it is an empty code bu.setusername (name);//name is entered by the user, or it can be written directly inside, such as Bu.setusername ("Xiao Ming")Bu.setpassword (pass);//Note: You cannot register with the Save methodBu.signup ( This,NewSavelistener () {@Override Public voidonsuccess () {//TODO auto-generated Method Stub   Toast.makeText(MainActivity. this , "注册成功" ,Toast.LENGTH_SHORT).show(); } @Override Public voidOnFailure (intcode, String msg) { //TODO auto-generated Method Stub  Toast.makeText(MainActivity.this,"注册失败",Toast.LENGTH_SHORT).show(); }});

Registering the code is simple, first set the user name and password entered by the user into the Users object, and then call the signup method to register. In the Savelistener callback listener processing the registration results returned by the server, the Onsuccess method indicates a successful registration, the OnFailure method indicates that the registration failed, and the parameter s indicates the reason for the failure.

This is the implementation of the registration function in the client, in fact, the user table in the Bmob background will save the users ' registration information, for example, if we register a user, the user name is the Scarecrow, the password is 123456, when the Savelistener callback triggered the Onsuccess method, You can see a user information in the Bmob Background users table, as follows:

Note:Sometimes you may need to send a verification message when the user registers to confirm the authenticity of the user's mailbox. At this point, you only need to login to your own application management background, in the app settings and Mail settings () to the "Mailbox verification" function to open, Bmob Cloud backend will automatically launch a verification to the user at the time of registration.

Login

Once the user has registered successfully, you need to have them later be able to log in to their account using the registered user name to use the app. To do this, you can use the login method of the Bmobuser class.

Bmobuser BU2 =NewBmobuser (); Bu2.setusername ("Lucky"); Bu2.setpassword ("123456"); Bu2.login ( This,NewSavelistener () {@Override Public voidonsuccess () {//TODO auto-generated Method Stub      Toast.makeText(MainActivity.this,"登录成功",Toast.LENGTH_SHORT).show();} @Override Public voidOnFailure (intcode, String msg) {        //TODO auto-generated Method Stub    Toast.makeText(MainActivity.this,"登录失败",Toast.LENGTH_SHORT).show();    }});

You can also use the following method to complete the login of user name + password :

 Bmobuser.loginbyaccount (this , "username", "User password", new  loginlistener<myuser> () {@Override  public  void   done (MyUser user, Bmobexception e) { //  TODO Auto-g enerated method stub  if  (User!=nul L   toast.maketext (mainactivity.
     this    "User logon succeeded"  ,toast.length_short). Show ();    
} } });

In fact, from the above registration, login interface code can be seen, the use of BMOBSDK to achieve user registration, login operation is very simple, we do not need to care about any backend things, as well as the client may need to care about the server interface corresponding to the network request operation and so on.

below to provide you with links:

Official website: http://www.bmob.cn/

Help Document: Http://www.bmob.cn/site/getdocs

Basic operation: Http://docs.bmob.cn/android/faststart/index.html?menukey=fast_start&key=start_android

SDK Download: HTTP://WWW.BMOB.CN/SITE/SDK

Bmob Cloud enables registration and login functions

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.