/
CreateAccount.java
102 lines (95 loc) · 2.74 KB
/
CreateAccount.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.example.campusfeed;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class CreateAccount extends Activity
{
EditText userName, passWord, email;
TextView error;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_account);
userName = (EditText) this.findViewById(R.id.userName);
passWord = (EditText) this.findViewById(R.id.passWord);
email = (EditText) this.findViewById(R.id.email);
error = (TextView) this.findViewById(R.id.error);
((Button) this.findViewById(R.id.submit))
.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (email.getText().toString().contains(" ")
|| !email.getText().toString().contains("@")
|| userName.getText().toString()
.replace(" ", "").contains(" ")
|| passWord.getText().toString()
.replace(" ", "").contains(" "))
{
error.setVisibility(View.VISIBLE);
} else
{
new createAcc().execute(email.getText().toString(),
userName.getText().toString(), passWord
.getText().toString());
error.setVisibility(View.GONE);
}
}
});
}
class createAcc extends AsyncTask<String, Void, String>
{
protected String doInBackground(String... params)
{
String url = "http://ezevents.6te.net/createaccount.php"
+ "?email=" + params[0] + "&username=" + params[1]
+ "&password=" + params[2];
HttpGet httpGet = new HttpGet(url);
HttpClient h = new DefaultHttpClient();
HttpResponse r = null;
try
{
// execute request
r = h.execute(httpGet);
} catch (ClientProtocolException e1)
{
Log.d("APP", e1.getMessage());
} catch (IOException e1)
{
Log.d("APP", e1.getMessage());
}
try
{
return EntityUtils.toString(r.getEntity());
} catch (ParseException e)
{
Log.d("ERROR", e.getMessage());
} catch (IOException e)
{
Log.d("ERROR", e.getMessage());
}
return null;
}
protected void onPostExecute(String response)
{
if (response.equals("fail") || response == null)
error.setVisibility(View.VISIBLE);
else
CreateAccount.this.finish();
}
}
}