Skip to content

Commit

Permalink
can send sign up and log in data
Browse files Browse the repository at this point in the history
  • Loading branch information
yuichi10 committed Oct 2, 2015
1 parent 001f424 commit 9873d24
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,31 @@
*/
public class DataManage {
//when connect to server
//static String server = "115.65.57.253:8080";
static String server = "192.168.11.3:9898";
//static String server = "115.65.57.253:8989";
//static String server = "192.168.11.5";
final static String server = "192.168.11.3";
//static String server = "172.17.194.69";
final static String port = ":8989";
//use these ward when connect to server
static String httpDemand = "Demand";
static String httpSignUp = "SignUp";
static String httpID = "Id";
static String httpPassword = "Password";
static String httpName = "Name";
static String httpGender = "Gender";
public void DataManege(){};
final static String httpDemand = "Demand";
//use at sign up
final static String httpSignUp = "SignUp";
final static String httpID = "Id";
final static String httpPassword = "Password";
final static String httpPassword2 = "Password2";
final static String httpName = "Name";
final static String httpGender = "Gender";
final static String httpAge = "Age";
final static String errCheck = "isErr";
final static String errId = "id_err";
final static String errPass1 = "pass1_err";
final static String errPass2 = "pass2_err";
final static String errName = "name_err";
final static String errGender = "gender_err";
final static String errAge = "age+err";




public void DataManege(){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

/**
* Created by yuichi on 8/25/15.
Expand All @@ -29,24 +30,35 @@ public class HttpCommunication {
//Post parameters
List<NameValuePair> postParams = new ArrayList<NameValuePair>();

public interface HttpCommunicationCallBack {
public void getResponse(String str);
}

private HttpCommunicationCallBack _httpCommunicationCallBack;

public void setCallbacks(HttpCommunicationCallBack myClassCallbacks){
_httpCommunicationCallBack = myClassCallbacks;
}


public HttpCommunication(String serverName, String path){
//Uri for get
mBuilder = new Uri.Builder();
setServerName(serverName);

if(path != "") {
mBuilder.path("/" + path);
}
//Uri for post
mUri = "http://" + serverName + "/" + path;
mUri = "http://" + serverName + DataManage.port + "/" + path;
}

public HttpCommunication(String serverName){
//Uri for get
mBuilder = new Uri.Builder();
setServerName(serverName);
//Uri for post
mUri = "http://" + serverName;
mUri = "http://" + serverName + DataManage.port;
}

private void setServerName(String str){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public Post(String url, List<NameValuePair> params){
public void run() {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(mUrl);
Log.v("POST", mUrl);
try {
post.setEntity(new UrlEncodedFormEntity(mParams, "UTF-8"));// 文字コード変換
// リクエスト送信
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,4 @@ public void analyseJson(String jStr){
}

}


//MD5
public String encodePassdigiest(String password){
byte[] enclyptedHash=null;
// MD5で暗号化したByte型配列を取得する
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(password.getBytes());
enclyptedHash = md5.digest();

// 暗号化されたByte型配列を、16進数表記文字列に変換する
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bytesToHexString(enclyptedHash);
}

private String bytesToHexString(byte[] fromByte) {

StringBuilder hexStrBuilder = new StringBuilder();
for (int i = 0; i < fromByte.length; i++) {

// 16進数表記で1桁数値だった場合、2桁目を0で埋める
if ((fromByte[i] & 0xff) < 0x10) {
hexStrBuilder.append("0");
}
hexStrBuilder.append(Integer.toHexString(0xff & fromByte[i]));
}
return hexStrBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;

/**
* Created by yuichi on 8/20/15.
Expand All @@ -27,7 +32,9 @@ public class SignUP extends Activity implements View.OnClickListener{
EditText password1;
EditText password2;
EditText name;
EditText age;
RadioGroup gender;
TextView idErrText, pass1ErrText, pass2ErrText, nameErrText, genderErrText,ageErrText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -54,6 +61,7 @@ public void onCreate(Bundle savedInstanceState) {
name = (EditText)findViewById(R.id.signUpName_e);
name.setWidth(name.getWidth());
gender = (RadioGroup)findViewById(R.id.signUpGender);
age = (EditText)findViewById(R.id.signUpAge);
}

public void onActivityResult( int requestCode, int resultCode, Intent intent ){
Expand Down Expand Up @@ -85,6 +93,44 @@ public void onActivityResult( int requestCode, int resultCode, Intent intent ){
}
}

public boolean showErr(String jsonStr){
try {
JSONObject json = new JSONObject(jsonStr);
if(json.getBoolean(DataManage.errCheck)){
if(json.getString(DataManage.errId) != ""){
idErrText = (TextView)findViewById(R.id.signUpEmail_t_err);
idErrText.setText(json.getString(DataManage.errId));
}
if(json.getString(DataManage.errPass1) != ""){
pass1ErrText = (TextView)findViewById(R.id.signUpPassword_t_err);
pass1ErrText.setText(json.getString(DataManage.errPass1));
}
if(json.getString(DataManage.errPass2) != ""){
pass2ErrText = (TextView)findViewById(R.id.signUpPassword2_t_err);
pass2ErrText.setText(json.getString(DataManage.errPass2));
}
if(json.getString(DataManage.errName) != ""){
nameErrText = (TextView)findViewById(R.id.signUpName_t_err);
nameErrText.setText(json.getString(DataManage.errName));
}
if(json.getString(DataManage.errGender) != ""){
genderErrText = (TextView)findViewById(R.id.signUpGender_t_err);
genderErrText.setText(json.getString(DataManage.errGender));
}
if(json.getString(DataManage.errAge) != ""){
ageErrText = (TextView)findViewById(R.id.signUpAge_t_err);
ageErrText.setText(json.getString(DataManage.errAge));
}
return true;
}else{
return false;
}
} catch (JSONException e) {
e.printStackTrace();
}
return true;
}

@Override
public void onClick(View v) {
switch (v.getId()){
Expand All @@ -98,23 +144,37 @@ public void onClick(View v) {
case R.id.doSignUp:
//get server info
String server = DataManage.server;
String path = "/";
String path = "signup";
//get editor info
String sEmail = email.getText().toString();
String sPassword = password1.getText().toString();
String sPassword2 = password2.getText().toString();
String sName = name.getText().toString();
int iGender = gender.getCheckedRadioButtonId();
String sGender = "NOT";
if(iGender != -1){
sGender = ((RadioButton)findViewById(iGender)).getText().toString();
switch (iGender){
case R.id.signUpMan:
iGender = 0;
break;
case R.id.signUpFemale:
iGender = 1;
break;
}
}
String sAge = age.getText().toString();
HttpCommunication hc = new HttpCommunication(server,path);
hc.setGetParameter(DataManage.httpDemand, DataManage.httpSignUp);
hc.setGetParameter(DataManage.httpID, sEmail);
hc.setGetParameter(DataManage.httpPassword, sPassword);
hc.setGetParameter(DataManage.httpName, sName);
hc.setGetParameter(DataManage.httpGender, sGender);
hc.Get();
hc.setPostParameter(DataManage.httpID, sEmail);
hc.setPostParameter(DataManage.httpPassword, sPassword);
hc.setPostParameter(DataManage.httpPassword2, sPassword2);
hc.setPostParameter(DataManage.httpName, sName);
hc.setPostParameter(DataManage.httpGender, iGender + "");
hc.setPostParameter(DataManage.httpAge, sAge);
String res = hc.Post();
boolean iserr = showErr(res);

Log.d("POST", res);
break;
}
}
Expand Down
52 changes: 51 additions & 1 deletion app/src/main/res/layout/sign_up.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -22,6 +26,10 @@
android:layout_height="wrap_content"
android:layout_weight="2"/>
</LinearLayout>
<TextView
android:id="@+id/signUpEmail_t_err"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -42,6 +50,10 @@
android:inputType="textPassword"
android:layout_weight="2"/>
</LinearLayout>
<TextView
android:id="@+id/signUpPassword_t_err"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -62,6 +74,10 @@
android:inputType="textPassword"
android:layout_weight="2"/>
</LinearLayout>
<TextView
android:id="@+id/signUpPassword2_t_err"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -80,6 +96,10 @@
android:layout_height="wrap_content"
android:layout_weight="2"/>
</LinearLayout>
<TextView
android:id="@+id/signUpName_t_err"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<RadioGroup
android:id="@+id/signUpGender"
Expand All @@ -94,12 +114,42 @@
android:text="@string/signUpGenderMan"/>

<RadioButton
android:id="@+id/feMail"
android:id="@+id/signUpFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signUpGenderWoman"/>
</RadioGroup>

<TextView
android:id="@+id/signUpGender_t_err"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/signUpAge_t"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"/>
<EditText
android:id="@+id/signUpAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:width="100dp"/>

</LinearLayout>
<TextView
android:id="@+id/signUpAge_t_err"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>



<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 9873d24

Please sign in to comment.