Skip to content

Commit

Permalink
코드 작성 완료(오류가 많음)
Browse files Browse the repository at this point in the history
  • Loading branch information
juyonglee79 committed Nov 10, 2018
1 parent 1b1692d commit b5a1ecc
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 40 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SignUpActivity"/>
<activity android:name=".MainActivity"/>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
import retrofit2.http.POST;

public interface API {
@POST("session")
Call<Void> post_login(@Body JsonObject jsonObject);
@GET("/auth/{gameKey}")
Call<Void> key_certified(@Body JsonObject jsonObject);

@POST("/auth/{gameKey}")
Call<Void> login(@Body JsonObject jsonObject);



}
Original file line number Diff line number Diff line change
@@ -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<Void> call = retrofit.key_certified(jsonObject);
call.enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> 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<Void> call, Throwable t) {

}
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Void> 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<Void> call = retrofit.login(jsonObject);
call.enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Void> call = retrofit.key_certified(jsonObject);
call.enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> 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<Void> call, Throwable t) {

}
});
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/back_btn_signup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFDBA5"/>
<corners android:radius="32dp"/>

</shape>
71 changes: 71 additions & 0 deletions app/src/main/res/layout/acitivty_keycertified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".KeyCertifiedActivity">

<ImageView
android:id="@+id/back_top"
android:layout_width="match_parent"
android:layout_height="223dp"
android:background="@drawable/back_ellipse_default" />

<ImageView
android:id="@+id/logo"
android:layout_width="153dp"
android:layout_height="141dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="135dp"
android:src="@drawable/getterra_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/id_et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="안녕하세요 ID님"
android:textSize="37sp"
android:textColor="#ffdba5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo" />

<EditText
android:id="@+id/keytoken_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="50dp"
android:hint="인증코드를 입력해주세요"
android:textSize="19sp"
android:textColorHint="#ffdba5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_et" />

<Button
android:id="@+id/certificate_btn"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="40dp"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/back_btn_signup"
android:text="Join Game"
android:textColor="#ffb587"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
Loading

0 comments on commit b5a1ecc

Please sign in to comment.