From b5a1ecc973af3b4322892bc5fd44b8cc5959ec21 Mon Sep 17 00:00:00 2001 From: juyonglee79 Date: Sat, 10 Nov 2018 23:28:32 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C(=EC=98=A4=EB=A5=98=EA=B0=80=20=EB=A7=8E?= =?UTF-8?q?=EC=9D=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 + .../get_terra_android_v2/Connector/API.java | 10 ++- .../KeyCertifiedActivity.java | 73 ++++++++++++++++ .../get_terra_android_v2/LoginActivity.java | 66 +++++++------- .../get_terra_android_v2/SignUpActivity.java | 86 +++++++++++++++++++ app/src/main/res/drawable/back_btn_signup.xml | 6 ++ .../main/res/layout/acitivty_keycertified.xml | 71 +++++++++++++++ app/src/main/res/layout/activity_login.xml | 31 +++++-- app/src/main/res/layout/activity_signup.xml | 84 ++++++++++++++++++ app/src/main/res/values/colors.xml | 2 +- 10 files changed, 390 insertions(+), 40 deletions(-) create mode 100644 app/src/main/java/com/dsm2018/get_terra_android_v2/KeyCertifiedActivity.java create mode 100644 app/src/main/java/com/dsm2018/get_terra_android_v2/SignUpActivity.java create mode 100644 app/src/main/res/drawable/back_btn_signup.xml create mode 100644 app/src/main/res/layout/acitivty_keycertified.xml create mode 100644 app/src/main/res/layout/activity_signup.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e253fad..9cb1bd5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,7 @@ + diff --git a/app/src/main/java/com/dsm2018/get_terra_android_v2/Connector/API.java b/app/src/main/java/com/dsm2018/get_terra_android_v2/Connector/API.java index b6c4e70..6e01140 100644 --- a/app/src/main/java/com/dsm2018/get_terra_android_v2/Connector/API.java +++ b/app/src/main/java/com/dsm2018/get_terra_android_v2/Connector/API.java @@ -8,6 +8,12 @@ import retrofit2.http.POST; public interface API { - @POST("session") - Call post_login(@Body JsonObject jsonObject); + @GET("/auth/{gameKey}") + Call key_certified(@Body JsonObject jsonObject); + + @POST("/auth/{gameKey}") + Call login(@Body JsonObject jsonObject); + + + } diff --git a/app/src/main/java/com/dsm2018/get_terra_android_v2/KeyCertifiedActivity.java b/app/src/main/java/com/dsm2018/get_terra_android_v2/KeyCertifiedActivity.java new file mode 100644 index 0000000..3b2b121 --- /dev/null +++ b/app/src/main/java/com/dsm2018/get_terra_android_v2/KeyCertifiedActivity.java @@ -0,0 +1,73 @@ +package com.dsm2018.get_terra_android_v2; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.dsm2018.get_terra_android_v2.Connector.API; +import com.dsm2018.get_terra_android_v2.Connector.ServiceGenerator; +import com.google.gson.JsonObject; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class KeyCertifiedActivity extends AppCompatActivity { + TextView ID; + EditText keytoken; + Button joingame; + String getKeytoken; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.acitivty_keycertified); + + keytoken = (EditText) findViewById(R.id.keytoken_et); + joingame = (Button) findViewById(R.id.certificate_btn); + joingame.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getKeytoken = keytoken.getText().toString(); + getKeytoken = getKeytoken.trim(); + if (getKeytoken.getBytes().length <= 0) { + Toast.makeText(getApplicationContext(), "이메일 혹은 인증번호가 입력되지 않았습니다", Toast.LENGTH_SHORT).show(); + } else { + post(); + } + + } + }); + } + + public void post() { + API retrofit = ServiceGenerator.getClient().create(API.class); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("gameKey", getKeytoken); + Call call = retrofit.key_certified(jsonObject); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Void repo = response.body(); + if (response.code()==201) { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + } + else if(response.code()==204) { + Toast.makeText(getApplicationContext(), "인증번호를 잘못 입력하셨습니다.", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } +} + diff --git a/app/src/main/java/com/dsm2018/get_terra_android_v2/LoginActivity.java b/app/src/main/java/com/dsm2018/get_terra_android_v2/LoginActivity.java index 7a75b02..46e3fe3 100644 --- a/app/src/main/java/com/dsm2018/get_terra_android_v2/LoginActivity.java +++ b/app/src/main/java/com/dsm2018/get_terra_android_v2/LoginActivity.java @@ -3,6 +3,7 @@ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; @@ -18,55 +19,62 @@ public class LoginActivity extends AppCompatActivity { Button login; - EditText email; - EditText certificationNum; - String getEmail; - String getCertificationNum; + Button signup; + EditText ID; + EditText password; + String getID; + String getPassword; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - final String mail = "^[_a-zA-Z0-9-\\.]+@[\\.a-zA-Z0-9-]+\\.[a-zA-Z]+$"; setContentView(R.layout.activity_login); - login=(Button)findViewById(R.id.login_btn); - email=(EditText)findViewById(R.id.email_et); - certificationNum=(EditText)findViewById(R.id.certificationNum_et); + + signup = (Button) findViewById(R.id.signup_btn); + signup.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(LoginActivity.this, SignUpActivity.class); + startActivity(intent); + } + }); + login = (Button) findViewById(R.id.login_btn); + ID = (EditText) findViewById(R.id.id_et); + password = (EditText) findViewById(R.id.password_et); login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - getEmail=email.getText().toString(); - getCertificationNum=certificationNum.getText().toString(); - getEmail=getEmail.trim(); - getCertificationNum=getCertificationNum.trim(); - if(getEmail.getBytes().length<=0|getCertificationNum.getBytes().length<=0){ - Toast.makeText(getApplicationContext(),"이메일 혹은 인증번호가 입력되지 않았습니다",Toast.LENGTH_SHORT).show(); - } - else if(getEmail.matches(mail)){ - Toast.makeText(getApplicationContext(),"이메일 형식이 잘못되었습니다.",Toast.LENGTH_SHORT).show(); + getID = ID.getText().toString(); + getPassword = password.getText().toString(); + getID = getID.trim(); + getPassword = getPassword.trim(); + if (getID.getBytes().length <= 0 | getPassword.getBytes().length <= 0) { + Toast.makeText(getApplicationContext(), "이메일 혹은 인증번호가 입력되지 않았습니다", Toast.LENGTH_SHORT).show(); } - else{ + else { post(); } } }); } - public void post(){ - API retrofit= ServiceGenerator.getClient().create(API.class); - JsonObject jsonObject=new JsonObject(); - jsonObject.addProperty("serial_number",getCertificationNum); - Call call= retrofit.post_login(jsonObject); + + public void post() { + API retrofit = ServiceGenerator.getClient().create(API.class); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", getID); + jsonObject.addProperty("password", getPassword); + Call call = retrofit.login(jsonObject); call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { Void repo = response.body(); - if(response.code()==200) { - Intent intent = new Intent(getApplicationContext(), MainActivity.class); + if (response.code() == 401) { + Toast.makeText(getApplicationContext(), "아이디 혹은 비밀번호가 맞지 않습니다.", Toast.LENGTH_SHORT).show(); + } else { + Intent intent = new Intent(getApplicationContext(), KeyCertifiedActivity.class); startActivity(intent); finish(); } - else if(response.code()==401){ - Toast.makeText(getApplicationContext(),"인증번호가 맞지 않습니다.",Toast.LENGTH_SHORT).show(); - } } @Override diff --git a/app/src/main/java/com/dsm2018/get_terra_android_v2/SignUpActivity.java b/app/src/main/java/com/dsm2018/get_terra_android_v2/SignUpActivity.java new file mode 100644 index 0000000..ec47664 --- /dev/null +++ b/app/src/main/java/com/dsm2018/get_terra_android_v2/SignUpActivity.java @@ -0,0 +1,86 @@ +package com.dsm2018.get_terra_android_v2; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.dsm2018.get_terra_android_v2.Connector.API; +import com.dsm2018.get_terra_android_v2.Connector.ServiceGenerator; +import com.google.gson.JsonObject; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class SignUpActivity extends AppCompatActivity { + EditText email; + EditText ID; + EditText password; + String getEmail; + String getID; + String getPassword; + Button signup_btn; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_signup); + + final String mail = "^[_a-zA-Z0-9-\\.]+@[\\.a-zA-Z0-9-]+\\.[a-zA-Z]+$"; + signup_btn = (Button) findViewById(R.id.signup_btn); + email = findViewById(R.id.email_et); + ID = findViewById(R.id.id_et); + password = findViewById(R.id.password_et); + signup_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getEmail = email.getText().toString(); + getID = ID.getText().toString(); + getPassword = password.getText().toString(); + if (getEmail.getBytes().length <= 0 | getID.getBytes().length <= 0 | getPassword.getBytes().length <= 0) { + Toast.makeText(getApplicationContext(), "입력이 완료되지 않았습니다", Toast.LENGTH_SHORT).show(); + } + else if (getID.matches(mail)) { + Toast.makeText(getApplicationContext(), "이메일 형식이 잘못되었습니다.", Toast.LENGTH_SHORT).show(); + } + else { + post(); + } + } + }); + + } + + public void post() { + API retrofit = ServiceGenerator.getClient().create(API.class); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("email", getEmail); + jsonObject.addProperty("id",getID); + jsonObject.addProperty("password", getPassword); + Call call = retrofit.key_certified(jsonObject); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Void repo = response.body(); + if (response.code() == 205) { + Toast.makeText(getApplicationContext(), "중복된 아이디입니다.", Toast.LENGTH_SHORT).show(); + } + else{ + Toast.makeText(getApplicationContext(), "회원가입이 완료되었습니다.", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(getApplicationContext(), LoginActivity.class); + startActivity(intent); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } +} diff --git a/app/src/main/res/drawable/back_btn_signup.xml b/app/src/main/res/drawable/back_btn_signup.xml new file mode 100644 index 0000000..8824afe --- /dev/null +++ b/app/src/main/res/drawable/back_btn_signup.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/acitivty_keycertified.xml b/app/src/main/res/layout/acitivty_keycertified.xml new file mode 100644 index 0000000..1eab979 --- /dev/null +++ b/app/src/main/res/layout/acitivty_keycertified.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + +