Anonymous social networking 1 -- login, anonymous social networking 1 --

Source: Internet
Author: User

Anonymous social networking 1 -- login, anonymous social networking 1 --

1. Logon

The user logs in using the mobile phone number + SMS verification code. The server does not save the user's mobile phone number.

After successful login, the client can obtain the login identity, and the client can maintain a relatively long period of access to the server through the login identity.

 

2. Interface

Get verification code:

{\"status\":1}

Anonymous Login:

{\"status\":1,\"token\":\"asdasdasdsadasd\"}

  

3. Code

MainActivity

@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);String token = Config.getCachedToken(this);String phone_num = Config.getCachedPhoneNum(this);if (token!=null&&phone_num!=null) {Intent i =new Intent(this, AtyTimeline.class);i.putExtra(Config.KEY_TOKEN, token);i.putExtra(Config.KEY_PHONE_NUM, phone_num);startActivity(i);}else{startActivity(new Intent(this, AtyLogin.class));}finish();}

LoginActivity

findViewById(R.id.btnGetCode).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {if (TextUtils.isEmpty(etPhone.getText())) {Toast.makeText(AtyLogin.this, R.string.phone_num_can_not_be_empty, Toast.LENGTH_LONG).show();return;}final ProgressDialog pd = ProgressDialog.show(AtyLogin.this, getResources().getString(R.string.connecting), getResources().getString(R.string.connecting_to_server));new GetCode(etPhone.getText().toString(), new GetCode.SuccessCallback() {@Overridepublic void onSuccess() {pd.dismiss();Toast.makeText(AtyLogin.this, R.string.suc_to_get_code, Toast.LENGTH_LONG).show();}}, new GetCode.FailCallback() {@Overridepublic void onFail() {pd.dismiss();Toast.makeText(AtyLogin.this, R.string.fail_to_get_code, Toast.LENGTH_LONG).show();}});}});findViewById(R.id.btnLogin).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {if (TextUtils.isEmpty(etPhone.getText())) {Toast.makeText(AtyLogin.this, R.string.phone_num_can_not_be_empty, Toast.LENGTH_LONG).show();return;}if (TextUtils.isEmpty(etCode.getText())) {Toast.makeText(AtyLogin.this, R.string.code_can_not_be_empty, Toast.LENGTH_LONG).show();return;}final ProgressDialog pd = ProgressDialog.show(AtyLogin.this, getResources().getString(R.string.connecting), getResources().getString(R.string.connecting_to_server));new Login(MD5Tool.md5(etPhone.getText().toString()), etCode.getText().toString(), new Login.SuccessCallback() {@Overridepublic void onSuccess(String token) {pd.dismiss();Config.cacheToken(AtyLogin.this, token);Config.cachePhoneNum(AtyLogin.this, etPhone.getText().toString());Intent i = new Intent(AtyLogin.this, AtyTimeline.class);i.putExtra(Config.KEY_TOKEN, token);i.putExtra(Config.KEY_PHONE_NUM, etPhone.getText().toString());startActivity(i);finish();}}, new Login.FailCallback() {@Overridepublic void onFail() {pd.dismiss();Toast.makeText(AtyLogin.this, R.string.fail_to_login, Toast.LENGTH_LONG).show();}});}});

  

 

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.