---
title: Android 사용자 등록 및 이메일 인증 구현 방법
slug: docs-kr/android/working-with-users/user-registration-email-verification
description: Android에서 이메일 인증을 포함한 사용자 등록 구현 가이드. Parse Server로 앱 제작.
image: https://www.back4app.com/images/logo-social.png
createdAt: 2024-03-14T15:39:53.618Z
---

# 이메일 인증을 통한 사용자 등록 구현 방법

## 소개

이 가이드에서는 사용자 등록 기능(가입)에 사용자 이메일 인증 프로세스를 설정하는 방법을 배웁니다. [Parse Server 핵심 기능](https://www.back4app.com/product/parse-server)을 사용하여 이메일 인증이 포함된 앱을 생성합니다.

이 튜토리얼은 <font color="#2166ae">`buildToolsVersion=30.0.3`</font> , <font color="#2166ae">`Compile SDK Version = 30`</font> 및 <font color="#2166ae">`targetSdkVersion 30`</font>

:::hint{type="success"}
**언제든지 GitHub 리포지토리를 통해 전체 프로젝트에 접근할 수 있습니다.**

- [코틀린 예제 리포지토리](https://github.com/templates-back4app/android_email_verification_kt)
- [자바 예제 리포지토리](https://github.com/templates-back4app/android_email_verification_java)
:::

## 목표

사용자 가입 기능에서 Back4App에 사용자 인증 이메일 프로세스를 설정합니다.

## 전제 조건

:::hint{type="info"}
**이 튜토리얼을 완료하려면 다음이 필요합니다:**

- [안드로이드 스튜디오](https://developer.android.com/studio/index.html)
- Back4App에 생성 및 연결된 [안드로이드 앱.](https://www.back4app.com/docs/android/parse-android-sdk)
- 안드로이드 4.1 (젤리빈) 이상에서 실행되는 [가상 장치](https://developer.android.com/studio/run/managing-avds.html))
:::

## 1 - 라이브러리 가져오기

이 단계에서는 프로젝트에서 사용할 라이브러리를 가져옵니다:

1. 다음 Parse 클래스를 우리의 활동에 추가합니다.

:::BlockQuote
&#x20;1   import com.parse.Parse;
&#x20;2   import com.parse.ParseException;
&#x20;3   import com.parse.ParseUser;
:::

&#x20;    2\. 다음을 추가해야 합니다 <font color="#2166ae">`Java 1.8`</font> 프로젝트에 <font color="#2166ae">`build.gradle(Module:App)`</font> 왜냐하면 이 프로젝트에서 람다 함수를 자주 사용할 것이기 때문입니다.

```java
1   compileOptions {
2       sourceCompatibility JavaVersion.VERSION_1_8
3       targetCompatibility JavaVersion.VERSION_1_8
4   }
```

## 2 - 이메일 인증 활성화

이제 Back4App 대시보드에서 이메일 인증을 활성화합시다. 이메일 인증 페이지에는 두 가지 속성이 있습니다: 사용자 이메일 인증 및 이메일이 인증되지 않은 경우 로그인 방지.
사용자 이메일 인증 옵션만 활성화하면 사용자는 인증 이메일을 받지만 정상적으로 로그인하고 애플리케이션을 사용할 수 있습니다. “이메일이 인증되지 않은 경우 로그인 방지” 옵션도 활성화하면 사용자는 이메일 인증 프로세스를 완료한 후에만 로그인할 수 있습니다.

&#x20;    1\. [Back4App 웹사이트](https://www.back4app.com/)로 이동하여 <font color="#2166ae">`서버 설정`</font>을 클릭합니다.

&#x20;    2\. “검증 이메일” 카드를 찾아 <font color="#2166ae">`설정`</font>을 클릭합니다.

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/bydSzO_8krq6jisNsHd_G_image.png)



&#x20;    3\. <font color="#2166ae">`사용자 이메일 검증`</font>을 클릭하고 <font color="#2166ae">`이메일이 검증되지 않은 경우 로그인 방지`</font>을 클릭합니다.

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/z3rwo9fC1_-Hd3kGf6zP7_image.png)

&#x20;    4\. 선택 사항: 빈 필드를 채우고 이미 채워진 필드를 선호에 따라 수정합니다.

&#x20;    5\. <font color="#2166ae">`저장`</font> 버튼을 클릭합니다.

## 3 - 가입하기

두 가지 기본 속성은 <font color="#2166ae">`ParseUser` </font>클래스는 사용자 이름과 비밀번호입니다. 또한 설정해야 할 세 번째 특별 속성이 있습니다. 즉, 이메일입니다.

이메일 확인을 통한 회원가입을 구현하기 위해, 사용자 등록을 구현할 때 사용했던 것과 동일한 방법을 사용할 것입니다. 그러나 이번에는 사용자를 로그인 화면으로 리디렉션하는 대신, 사용자가 로그인하기 위해 이메일을 확인하도록 요청할 것입니다.

회원가입 프로세스를 완료한 후, 사용자는 데이터베이스에 저장됩니다. 사용자 데이터는<font color="#2166ae"> `Parse Dashboard`</font>에서 mailVerified Boolean 속성이 false로 설정된 상태로 사용 가능합니다. 확인 이메일 프로세스는 사용자의 이메일을 확인하고 이 속성을 true로 설정하여 사용자가 앱의 모든 리소스에 완전히 접근할 수 있도록 하는 것입니다.

회원가입 화면은 다음과 같이 보일 것입니다:

::Image[]{src="https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/ilBeWCB-6fdQ9nvjJ-Bar_image.png" size="50" width="278" height="600" position="center" showCaption="false"}

다음 단계를 따라 <font color="#2166ae">`SignUpActivity` </font>작업을 생성하십시오:

&#x20;    1\. <font color="#2166ae">`SignUpActivity`</font>,에 추가하여 **1단계**:의 종속성을 가져옵니다.

:::BlockQuote
1   import com.parse.ParseExceptio&#x6E;**;**
2   import com.parse.SignUpCallbac&#x6B;**;**
:::

&#x20;    2\. 다음 코드를 사용하여 사용자 등록을 구현합니다:

:::CodeblockTabs
```java
1   private void signUp(String username, String password, String email) {
2        progressDialog.show();
3        ParseUser user = new ParseUser();
4        user.setUsername(username);
5        user.setPassword(password);
6        user.setEmail(email);
7        user.signUpInBackground(e -> {
8            progressDialog.dismiss();
9            if (e == null) {
10               ParseUser.logOut();
11               showAlert("Account Created Successfully!", "Please verify your email before Login", false);
12           } else {
13               ParseUser.logOut();
14               showAlert("Error Account Creation failed", "Account could not be created" + " :" + e.getMessage(), true);
15           }
16       });
17   }
```

```kotlin
1   private fun signUp(username: String, password: String, email: String) {
2        progressDialog?.show()
3        val user = ParseUser()
4        user.username = username
5        user.setPassword(password)
6        user.email = email
7        user.signUpInBackground(SignUpCallback {
8            progressDialog?.dismiss()
9            if (it == null) {
10               ParseUser.logOut();
11               showAlert("Account Created Successfully!","Please verify your email before Login", false)
12           } else {
13              ParseUser.logOut();
14              showAlert("Error Account Creation failed","Account could not be created" + " :" + it.message,true)
15           }
16       })
17   }
```
:::

:::hint{type="info"}
예제 프로젝트에서 이 코드는 <font color="#2166ae">`회원가입`</font> 버튼 콜백 안에 있습니다.
또한, 사용자 이름, 비밀번호 및 이메일은 Edit Texts를 사용하여 입력됩니다.
:::

:::hint{type="info"}
이메일 주소가 유효한지 확인하는 코드를 추가한 후 프론트 엔드에 설정할 수 있습니다. 마지막으로, 피드백을 제공하는 코드를 추가할 수 있습니다.
:::

가입을 마친 후 다음 메시지를 볼 수 있습니다… :

::Image[]{src="https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/wIMP0PQxS_564oj6QW4Tm_image.png" size="50" width="276" height="600" position="center" showCaption="false"}

&#x20;    3\. 경고 대화 상자를 표시하는 추가 방법을 추가하는 것이 흥미롭습니다. 프로세스를 더 전문적으로 보이게 만들 수 있습니다. 다음은 이를 수행하는 방법입니다:

:::CodeblockTabs
```java
1    private void showAlert(String title, String message, boolean error) {
2         AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this)
3                 .setTitle(title)
4                 .setMessage(message)
5                 .setPositiveButton("OK", (dialog, which) -> {
6                     dialog.cancel();
7                     // don't forget to change the line below with the names of your Activities
8                     if (!error) {
9                         Intent intent = new Intent(SignUpActivity.this, LoginActivity.class);
10                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
11                        startActivity(intent);
12                    }
13                });
14        AlertDialog ok = builder.create();
15        ok.show();
16    }
```

```kotlin
1    private fun showAlert(title: String, message: String, error: Boolean) {
2         val builder = AlertDialog.Builder(this)
3             .setTitle(title)
4             .setMessage(message)
5             .setPositiveButton("OK") { dialog, which ->
6                 dialog.cancel()
7                 // don't forget to change the line below with the names of your Activities
8                 if (!error) {
9                     val intent = Intent(this@SignUpActivity, LoginActivity::class.java)
10                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
11                    startActivity(intent)
12                }
13            }
14        val ok = builder.create()
15        ok.show()
16    }
```
:::

가입 후 우리는 다음과 같은 이메일을 받을 것입니다:

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/NXLL2hhr5j7GhVGftSUOK_image.png)

이메일을 확인한 후 속성이 true로 설정됩니다:

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/vhgw-H2rGUgvnKoW3vvQe_image.png)

이메일을 확인한 후 속성이 true로 설정됩니다:

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/QRt0_FrBwp7BmuLjZHaUG_image.png)

## 4 - 로그인

이메일 인증으로 로그인을 구현하려면, 기본 [사용자 등록](https://www.back4app.com/docs/android/login-android-tutorial). 하지만 이번에는 Parse가 사용자가 추가 접근을 허용하기 전에 **emailVerified** 불리언을 확인합니다.

:::hint{type="info"}
**참고**: 사용자가 실제로 로그인하는 것은 *ParseUser.logInInBackground()* 함수가 호출될 때입니다. 하지만 이메일 인증이 완료될 때까지는 앱에 완전히 접근할 수 없습니다. 데이터베이스에 생성된 세션 객체 때문입니다. 따라서 이메일을 인증하지 않은 사용자가 애플리케이션에 접근하려고 할 때마다 *ParseUser.logout()&#x20;*&#xC744; 사용하는 것이 중요합니다. 그렇지 않으면 <font color="#2166ae">`세션` </font>이 열려 있게 됩니다.

:::

2단계에서 ‘이메일이 인증되지 않은 경우 로그인 방지’ 옵션을 활성화한 경우, 이메일을 인증하지 않고 로그인하려고 하면 다음과 같은 오류가 발생합니다.

::Image[]{src="https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/ngrxWmCOlDPGthFmDGrVB_image.png" size="50" width="281" height="601" position="center" showCaption="false"}

&#x20;<font color="#2166ae">`LoginActivity`</font> 가 작동하도록 하려면, 다음 단계를 따르세요:

&#x20;    1\. <font color="#2166ae">`LoginActivity`</font>, 1단계에서 가져온 종속성과 함께 가져옵니다.

:::BlockQuote
1   import com.parse.LogInCallbac&#x6B;**;**
2   import com.parse.ParseExceptio&#x6E;**;**
:::

&#x20;    2\. 사용자 로그인 기능을 구현하려면 다음 코드를 사용하세요:

:::CodeblockTabs
```java
1   private void login(String username, String password) {
2        progressDialog.show();
3        ParseUser.logInInBackground(username, password, (parseUser, e) -> {
4            progressDialog.dismiss();
5            if (parseUser != null) {
6                showAlert("Login Successful", "Welcome, " + username + "!", false);
7            } else {
8                ParseUser.logOut();
9                showAlert("Login Fail", e.getMessage() + " Please try again", true);
10           }
11       });
12   }
```

```kotlin
1   private fun login(username: String, password: String) {
2        progressDialog?.show()
3        ParseUser.logInInBackground(username,password) { parseUser: ParseUser?, e: ParseException? ->
4            progressDialog?.dismiss()
5            if (parseUser != null) {
6                showAlert("Login Successful", "Welcome, $username!", false)
7            } else {
8                ParseUser.logOut()
9                showAlert("Login Fail", e?.message + " Please try again", true)
10           }
11       }
12   }
```
:::

:::hint{type="info"}
예제 프로젝트에서 이 코드는 <font color="#2166ae">`로그인`</font> 버튼 콜백에 배치되어 있습니다.
또한, 사용자 이름과 비밀번호는 Edit Text를 사용하여 입력받습니다.
:::

:::hint{type="info"}
메서드 <font color="#2166ae">`alertDisplayer` </font>는 <font color="#2166ae">`SignUpActivity`</font>에 추가한 것과 동일합니다. <font color="#2166ae">`Intent` </font> 인수도 변경하는 것을 잊지 마세요.
:::

## 5 - 로그 아웃

사용자 로그 아웃을 구현하려면 아래 코드를 사용하세요, <font color="#2166ae">`LogoutActivity`</font>:

:::CodeblockTabs
```java
1   progressDialog.show();
2        ParseUser.logOutInBackground(e -> {
3            progressDialog.dismiss();
4            if (e == null)
5                showAlert("So, you're going...", "Ok...Bye-bye then");
6        });
```

```kotlin
1   progressDialog!!.show()
2        ParseUser.logOutInBackground { e: ParseException? ->
3            progressDialog!!.dismiss()
4            if (e == null)
5                showAlert("So, you're going...", "Ok...Bye-bye then")
6        }
```
:::

:::hint{type="info"}
예제 프로젝트에서 이 코드는 <font color="#2166ae">`로그 아웃`</font> 버튼 콜백 안에 있습니다.
:::

:::hint{type="info"}
메서드 <font color="#2166ae">`alertDisplayer` </font>는 당신이 <font color="#2166ae">`LoginActivity` </font>와 <font color="#2166ae">`SignUpActivity`</font>, 그 <font color="#2166ae">`Intent` </font> 인수들을 변경하는 것을 잊지 마세요.
:::

## 6 - 앱 테스트하기

앱을 실행하고, 몇 명의 사용자를 생성한 후, 등록 후 이메일을 확인하지 않고 로그인해 보세요.

&#x20;    1\. 앱을 실행하고, 몇 명의 사용자를 생성한 후, 이메일을 확인하지 않고 등록 후 로그인해 보세요.

&#x20;    2\. [Back4App 웹사이트.](https://www.back4app.com/)

&#x20;    3\. 앱을 찾아서 <font color="#2166ae">`대시보드` </font>> <font color="#2166ae">`코어` </font>> <font color="#2166ae">`브라우저` </font>> <font color="#2166ae">`사용자` </font>를 클릭하여 생성한 사용자를 확인하세요!

## 완료되었습니다!

이 단계에서, Parse Server의 핵심 기능을 통해 Back4App을 사용하여 이메일 인증으로 앱에 로그인, 가입 또는 로그아웃할 수 있습니다!
