Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- procedure does not exist
- MySQL(MariaDB)접속 #MariaDB원격 접속 #콘솔에서mysql접속 #원격지에서MySQL #php안드로이드 연동
- 안드로이드 타이머 #타이머 #handler timer #android handler timer #countdowntimer
- 회원가입 구현 #java
- 부트스트랩 #bootstrap install #
- my.ini위치 확인
- mysql #dataloongforcolumn #ER_DATA_TOO_LONG #mariaDB #my.ini찾기 #숨김my.ini찾기 #strict mode 해제 #strict mode
- hedisql limit 1000
- react #react 프로젝트 생성 #초보 #쉽게 #react 세팅 #react frontend #리액트 기본구조
- 안드로이드 아이콘 만들기 #안드로이드 vector asset #android vector asset custom #안드로이드 vector background color change #android pathdata editor #vector drawables edit #vector drawable background color #drawable background color #an
- XAMPP #PHP #mysql #Android #연동
- android #tip #timer #handler #sendmessagedelayed
- Android #bottom navigation View #Bottom tab #FRAGMENT #JAVA #Material Design #안드로이드 프래그먼트 바텀 네비게이션 뷰 커스텀 #안드로이드 메뉴 아이콘 커스텀 #안드로이드 메뉴 #프래그먼트 메뉴 #fragment menu i
- nodejs #express #게시판 기능 구현
- 안드로이드 #앱 아이콘 #앱 아이콘 커스텀하기 #앱 로고 만들기 #앱 아이콘 만들기 #android logo custom #android icon custom #android logo 만들기 #image asset #
- 안드로이드 로그인 회원가입 기능 #안드로이드 php 로그인 #userValidate.php #android php 중복체그 #안드로이드 회원가입 id 중복체크 기능 #android login id check
- 리눅스 #우분투 포트포워딩 #리눅스 포트포워딩 #우분투22.04 php apache db #mariadb #mysql
- MySQL #안드로이드 로그인기능 #안드로이드 php 오류 #안드로이드 db #
- 크롤링 #텍스트 크롤링 #파이썬 #구름IDE
- 부트스트랩 추가시 오류 #
- android hedisql #안드로이드 mariaDB #안드로이드 로그인 권한 #안드로이드 로그인
- 안드로이드 앱 아이콘 변경 #안드로이드 앱 아이콘 사이즈 #안드로이드 앱 아이콘 가이드
- hedisql #mariadb #mysql #마리아db #암호화 복호화 #aes512 #aes_encrypt #aes_decrypt #hedisql 펑션 생성 #hedisql 프로시저 생성 #hedisql 매개변수 #db 펑션 매개변수 #db 프로시저 #db 함수 #db return
- Module not found: Error: Can't resolve '@popperjs/core'
- react #리액트 #프로젝트 초기세팅 #초기구현 #클린코드 #cleancode #node #react-node #vite #react 설치 #react 세팅 #쇼핑몰 #eslint 설정 #vite eslint #TailWindCSS란? #테일윈드적용 #TailWindCSS 적용
- mariadb #mysql
- 터미널 #terminal #aws 인스턴스 접속
- Apache #PHP #마리아DB #아파치
- php #안드로이드 #로그인&회원가입
- db 프로시저 권한 부여 #db procedure 권한 부여 #
Archives
- Today
- Total
맨땅에 코딩
[Android] 로그인&회원가입 기능(2) - 중복체크(php, 프로젝트 소스코드 포함) 본문
목차
반응형
https://haruvely.tistory.com/32 1편입니다
+) 아이디 중복체크 기능 추가
<ValidateRequest.java>
public class ValidateRequest extends StringRequest {
//서버 url 설정(php파일 연동)
final static private String URL="http://ip:port/UserValidate.php";
private Map<String,String> map;
public ValidateRequest(String userID, Response.Listener<String>listener){
super(Method.POST,URL,listener,null);
map=new HashMap<>();
map.put("userID",userID);
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return map;
}
}
ip:port 사용하시는 ip, port 번호로 바꿔주시면 됩니다
<activity_register.xml>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RegisterActivity">
<EditText
android:id="@+id/et_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="200dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ems="10"
android:hint="아이디"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/et_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="비밀번호"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/et_id"
app:layout_constraintStart_toStartOf="@+id/et_id"
app:layout_constraintTop_toBottomOf="@+id/et_id" />
<EditText
android:id="@+id/et_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="이름"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/et_pass"
app:layout_constraintStart_toStartOf="@+id/et_pass"
app:layout_constraintTop_toBottomOf="@+id/et_pass" />
<EditText
android:id="@+id/et_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="나이"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/et_name"
app:layout_constraintStart_toStartOf="@+id/et_name"
app:layout_constraintTop_toBottomOf="@+id/et_name" />
<Button
android:id="@+id/btn_register"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="회원가입"
app:layout_constraintEnd_toEndOf="@+id/et_age"
app:layout_constraintStart_toStartOf="@+id/et_age"
app:layout_constraintTop_toBottomOf="@+id/et_age" />
<Button
android:id="@+id/btn_validateCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="200dp"
android:text="중복체크"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/et_id"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<RegisterActivity.java>
public class RegisterActivity extends AppCompatActivity {
private EditText et_id, et_pass, et_name, et_age;
private Button btn_register, btn_validateCheck;
private AlertDialog dialog;
private boolean validate = false;
@Override
protected void onCreate(Bundle savedInstanceState) { // 액티비티 시작시 처음으로 실행되는 생명주기!
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
// 아이디 값 찾아주기
et_id = findViewById(R.id.et_id);
et_pass = findViewById(R.id.et_pass);
et_name = findViewById(R.id.et_name);
et_age = findViewById(R.id.et_age);
// 아이디 중복 체크
btn_validateCheck = findViewById(R.id.btn_validateCheck);
btn_validateCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String userID = et_id.getText().toString();
if (validate) {
return; // 검증 완료
}
if (userID.equals("")) {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
dialog = builder.setMessage("아이디를 입력하세요.").setPositiveButton("확인", null).create();
dialog.show();
return;
}
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Log.d("response1 : ", response);
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
dialog = builder.setMessage("사용할 수 있는 아이디입니다.").setPositiveButton("확인", null).create();
dialog.show();
et_id.setEnabled(false); //아이디값 고정
validate = true; //검증 완료
btn_validateCheck.setBackgroundColor(getResources().getColor(R.color.colorGray));
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
dialog = builder.setMessage("이미 존재하는 아이디입니다.").setNegativeButton("확인", null).create();
dialog.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
ValidateRequest validateRequest = new ValidateRequest(userID,responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(validateRequest);
}
});
// 회원가입 버튼 클릭 시 수행
btn_register = findViewById(R.id.btn_register);
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// EditText에 현재 입력되어있는 값을 get(가져온다)해온다.
String userID = et_id.getText().toString();
String userPass = et_pass.getText().toString();
String userName = et_name.getText().toString();
int userAge = Integer.parseInt(et_age.getText().toString());
if(validate) {
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Log.d("response2 : ", response);
JSONObject jsonObject = new JSONObject(response);
boolean success = jsonObject.getBoolean("success");
if (success) { // 회원등록에 성공한 경우
Toast.makeText(getApplicationContext(), "회원 등록에 성공하였습니다.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
startActivity(intent);
} else { // 회원등록에 실패한 경우
Toast.makeText(getApplicationContext(), "회원 등록에 실패하였습니다.", Toast.LENGTH_SHORT).show();
return;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
// 서버로 Volley를 이용해서 요청을 함.
RegisterRequest registerRequest = new RegisterRequest(userID, userPass, userName, userAge, responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
dialog = builder.setMessage("아이디 중복체크 해주세요.").setNegativeButton("확인", null).create();
dialog.show();
}
}
});
}
}
<UserValidate.php>
<?php
$con = mysqli_connect("127.0.0.1:3310", "root", "1233", "user");
mysqli_query($con,'SET NAMES utf8');
$userID = isset($_POST["userID"]) ? $_POST["userID"] : "";
$statement = mysqli_prepare($con, "SELECT * FROM user WHERE userID = ?");
mysqli_stmt_bind_param($statement, "s", $userID);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
while(mysqli_stmt_fetch($statement)) {
$response["success"] = false;
$response["userID"] = $userID;
}
echo json_encode($response);
?>
궁금한 점은 댓글 남겨주세요
감사합니다
반응형
'앱 개발 > Java' 카테고리의 다른 글
[Android] 로그인&회원가입 기능 구현 - mysql, php(외부 서버) 활용 (0) | 2022.12.21 |
---|---|
[Android] Vector Asset drawable 크기 조절 및 배경색 그리기 (0) | 2022.11.29 |
[Android] 앱 아이콘(로고) 만들기 + 변경하기 (Image Asset 사용) (0) | 2022.11.24 |
[Android] Timer 구현 - Handler (0) | 2022.09.13 |
[안드로이드] fragment 창 생성 + bottom navigation bar 커스텀 + 메뉴 아이콘 커스텀(저작권 상관X) (0) | 2022.08.10 |