-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignUpSignIn.java
133 lines (118 loc) · 6.89 KB
/
SignUpSignIn.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package edu.nctu.wirelab.testsignalv1;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class SignUpSignIn extends AppCompatActivity {
private final String TagName = "SignUpSignIn";
private String configPath;
private EditText EmailEditText, PwdEditText, PwdConfirmationEditText, LocationEditText, SexEditText, CareerEditText, UserNameEditText;
private Button RegisterButton, LoginButton;
private String Email=null, Pwd=null, PwdConfirm=null, Location=null, Sex=null, Career=null, UserName=null;
public void initVar(){
EmailEditText = (EditText)findViewById(R.id.EmailEditText);
PwdEditText = (EditText)findViewById(R.id.PwdEditText);
PwdConfirmationEditText = (EditText)findViewById(R.id.PwdConfirmationEditText);
LocationEditText = (EditText)findViewById(R.id.LocationEditText);
SexEditText = (EditText)findViewById(R.id.SexEditText);
CareerEditText = (EditText)findViewById(R.id.CareerEditText);
UserNameEditText = (EditText)findViewById(R.id.UserNameEditText);
RegisterButton = (Button)findViewById(R.id.RegisterButton);
LoginButton = (Button)findViewById(R.id.LoginButton);
configPath = "/data/data/" + getPackageName() + "/config";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up_sign_in);
initVar();
RegisterButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Email=EmailEditText.getText().toString();
Pwd=PwdEditText.getText().toString();
PwdConfirm=PwdConfirmationEditText.getText().toString();
Location=LocationEditText.getText().toString();
Sex=SexEditText.getText().toString();
Career=CareerEditText.getText().toString();
UserName=UserNameEditText.getText().toString();
if( Email.equals("") || Pwd.equals("") || PwdConfirm.equals("") || UserName.equals("") ){
ShowDialogMsg.showDialog("The fields marked wtih '*' should be filled");
return;
}
else if( Pwd.length()<6 ){
ShowDialogMsg.showDialog("The number of Pwd should be 6-18 digits");
return;
}
else if( Pwd.compareTo(PwdConfirm)!=0 ){
ShowDialogMsg.showDialog("The Pwd is different from Pwd Confirmation. Pwd="+Pwd+" PwdC="+PwdConfirm);
return;
}
String variables = "email="+Email+"&password="+Pwd+"&location="+Location+"&sex="+Sex+"&career="+Career+"&username="+UserName;
// String variables = "email="+Email;
Log.d(TagName, "variables:" + variables);
HttpsConnection httpsconnection = new HttpsConnection(SignUpSignIn.this);
httpsconnection.setMethod("GET", variables);
httpsconnection.execute("/signal/api/signup");//exec with the URLfile such as "index.php" -> https://140.113.216.37/index.php
final View item = LayoutInflater.from(SignUpSignIn.this).inflate(R.layout.register_comfirm_pop, null);
new AlertDialog.Builder(SignUpSignIn.this)
.setTitle("Registration")
.setView(item)
.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText ConfirmationCodeEditText = (EditText) item.findViewById(R.id.ConfirmationCodeEditText);
String ConfirmationCode = ConfirmationCodeEditText.getText().toString();
ShowDialogMsg.showDialog("Confirmation Code:" + ConfirmationCode);
HttpsConnection httpsconnection = new HttpsConnection(SignUpSignIn.this);
httpsconnection.setMethod("GET", "confirmation="+ConfirmationCode);
httpsconnection.execute("/signal/api/signup");//exec with the URLfile such as "index.php" -> https://140.113.216.37/index.php
}
})
.show();
}
});
LoginButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
final View item = LayoutInflater.from(SignUpSignIn.this).inflate(R.layout.login_pop, null);
new AlertDialog.Builder(SignUpSignIn.this)
.setTitle("Login")
.setView(item)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ShowDialogMsg.showDialog("Cancel");
}
})
.setPositiveButton("Login", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText UserNameEditText = (EditText) item.findViewById(R.id.UserNameEditText);
EditText PwdEditText = (EditText) item.findViewById(R.id.PwdEditText);
UserName = UserNameEditText.getText().toString();
Pwd = PwdEditText.getText().toString();
ShowDialogMsg.showDialog("UserName:" + UserNameEditText.getText().toString() + "\nPwd:" + PwdEditText.getText().toString());
String variables = "username="+UserName+"&password="+Pwd;
HttpsConnection httpsconnection = new HttpsConnection(SignUpSignIn.this);
httpsconnection.setMethod("GET", variables);
httpsconnection.execute("/signal/api/login");//exec with the URLfile such as "index.php" -> https://140.113.216.37/index.php
}
})
.show();
}
});
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent intent = new Intent(SignUpSignIn.this, MainActivity.class);
intent.setClass(SignUpSignIn.this, MainActivity.class);
startActivity(intent);
finish();
}
}