Advertisement
Guest User

Untitled

a guest
Jan 17th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. package com.thebutts.slappybutt;
  2.  
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.support.v7.app.ActionBarActivity;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12.  
  13. import org.apache.http.HttpEntity;
  14. import org.apache.http.HttpResponse;
  15. import org.apache.http.HttpStatus;
  16. import org.apache.http.NameValuePair;
  17. import org.apache.http.client.HttpClient;
  18. import org.apache.http.client.entity.UrlEncodedFormEntity;
  19. import org.apache.http.client.methods.HttpPost;
  20. import org.apache.http.impl.client.DefaultHttpClient;
  21. import org.apache.http.message.BasicNameValuePair;
  22. import org.apache.http.util.EntityUtils;
  23.  
  24. import java.io.IOException;
  25. import java.io.InputStream;
  26. import java.io.UnsupportedEncodingException;
  27. import java.util.ArrayList;
  28. import java.util.List;
  29.  
  30.  
  31. public class RegisterActivity extends ActionBarActivity {
  32.  
  33. @Override
  34. protected void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_register);
  37.  
  38. setupUiEvents();
  39. }
  40.  
  41. void setupUiEvents() {
  42. Button firstButton = (Button) findViewById(R.id.btn_register);
  43. firstButton.setOnClickListener(new View.OnClickListener() {
  44. @Override
  45. public void onClick(View v) {
  46. RegisterActivity.this.onClickStartRegister((Button) v);
  47. }
  48. });
  49. }
  50.  
  51. private void onClickStartRegister(Button b) {
  52. String username = ((EditText) findViewById(R.id.editText4)).getText().toString();
  53. String email = ((EditText) findViewById(R.id.editText)).getText().toString();
  54. String password = ((EditText) findViewById(R.id.editText2)).getText().toString();
  55. String confirmedPass = ((EditText) findViewById(R.id.editText3)).getText().toString();
  56.  
  57. HttpClient httpClient = new DefaultHttpClient();
  58. HttpPost httpPost = new HttpPost("http://slappybutt.azurewebsites.net/api/Account/Register");
  59.  
  60. if (username.length() >= 1 && email.length() >= 1 && password.length() >= 1 && confirmedPass.length() >= 1
  61. && password.equals(confirmedPass)) {
  62.  
  63. List<NameValuePair> nameValuePairs = new ArrayList<>(4);
  64. nameValuePairs.add(new BasicNameValuePair("UserName", username));
  65. nameValuePairs.add(new BasicNameValuePair("Email", email));
  66. nameValuePairs.add(new BasicNameValuePair("Password", password));
  67. nameValuePairs.add(new BasicNameValuePair("ConfirmPassword", confirmedPass));
  68. try {
  69. httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  70. } catch (UnsupportedEncodingException e) {
  71. e.printStackTrace();
  72. }
  73. try {
  74. HttpResponse response = httpClient.execute(httpPost);
  75.  
  76.  
  77. final int statusCode = response.getStatusLine().getStatusCode();
  78.  
  79. Log.d(getClass().getSimpleName(), "Status code " + statusCode + " for URL " + httpPost.getURI());
  80.  
  81.  
  82. HttpEntity entity = response.getEntity();
  83.  
  84. String responseStr = EntityUtils.toString(entity);
  85.  
  86.  
  87. Log.d(getClass().getSimpleName(), "Response " + responseStr);
  88.  
  89.  
  90. } catch (Exception e) {
  91.  
  92. Log.d(getClass().getSimpleName(), "exeption " + e.getMessage());
  93. e.printStackTrace();
  94. }
  95.  
  96.  
  97. // Intent intent = new Intent(this, MainActivity.class);
  98. // startActivity(intent);
  99.  
  100. } else if (username.length() < 1 && email.length() < 1 && password.length() < 1 && confirmedPass.length() < 1) {
  101. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  102. builder.setMessage("All fields must be filled!")
  103. .setCancelable(false)
  104. .setPositiveButton("OK", new DialogInterface.OnClickListener() {
  105. public void onClick(DialogInterface dialog, int id) {
  106. //do things
  107. }
  108. });
  109. AlertDialog alert = builder.create();
  110. alert.show();
  111. } else if (!password.endsWith(confirmedPass)) {
  112. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  113. builder.setMessage("Passwords does not match!")
  114. .setCancelable(false)
  115. .setPositiveButton("OK", new DialogInterface.OnClickListener() {
  116. public void onClick(DialogInterface dialog, int id) {
  117. //do things
  118. }
  119. });
  120. AlertDialog alert = builder.create();
  121. alert.show();
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement