Skip to content

Commit

Permalink
email인증 및 로그인 스크린 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphanoJack committed Jul 24, 2024
1 parent 88e2148 commit 159a703
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 373 deletions.
1 change: 1 addition & 0 deletions lib/model/MBTIModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ part 'generated/MBTIModel.g.dart';

@freezed
class MBTIModel with _$MBTIModel {
const MBTIModel._();
const factory MBTIModel({
required Extroversion extroversion,
required Sensing sensing,
Expand Down
18 changes: 18 additions & 0 deletions lib/providers/SignUpDataProviders.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 이메일 인증 ( 아이디 )
import 'package:flutter_riverpod/flutter_riverpod.dart';

final emailProvider = StateProvider<String>((ref) => '');
final emailVerificationCodeProvider = StateProvider<String>((ref) => '');

// 이름, 닉네임 생성
final nameProvider = StateProvider<String>((ref) => '');
final nicknameProvider = StateProvider<String>((ref) => '');

// 비밀번호 생성
final passwordProvider = StateProvider<String>((ref) => '');
final passwordConfirmProvider = StateProvider<String>((ref) => '');

// 휴대폰 번호 인증 ( 구매할 때 휴대폰 인증 ) ( 따로 만들기 )
final residentRegistrationNumberProvider = StateProvider<String>((ref) => '');
final phoneNumberProvider = StateProvider<String>((ref) => '');
final verificationNumberProvider = StateProvider<String>((ref) => '');
7 changes: 2 additions & 5 deletions lib/screens/mypage/MyPageScreen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';

import 'package:blueberry_flutter_template/screens/mypage/camera/setting_inside_account_manager.dart';
import 'package:blueberry_flutter_template/screens/mypage/camera/setting_inside_camera_media.dart';
import 'package:cloud_functions/cloud_functions.dart';
Expand All @@ -9,7 +8,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_picker/image_picker.dart';

import '../../providers/camera/FirebaseStoreServiceProvider.dart';
import '../../providers/camera/fireStorageServiceProvider.dart';
import '../../providers/user/FirebaseAuthServiceProvider.dart';
Expand Down Expand Up @@ -196,14 +194,13 @@ class MyPageScreen extends ConsumerWidget {
}
}
},
child: const Expanded(
child: ListTile(
child: const ListTile(
leading: Icon(Icons.person_off),
title: Text(
"회원탈퇴",
style: TextStyle(fontSize: 20),
),
)),
),
),
],
),
Expand Down
121 changes: 93 additions & 28 deletions lib/screens/mypage/SignUpScreen.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import 'package:blueberry_flutter_template/screens/mypage/signup/EmailInputScreen.dart';
import 'package:blueberry_flutter_template/screens/mypage/signup/PasswordInputPage.dart';
import 'package:blueberry_flutter_template/screens/mypage/signup/TermsOfServicePage.dart';
import 'package:blueberry_flutter_template/widgets/signup/EmailDuplicateWidget.dart';
import 'package:blueberry_flutter_template/widgets/signup/EmailVerifyWidget.dart';
import 'package:blueberry_flutter_template/widgets/signup/NameInputWidget.dart';
import 'package:blueberry_flutter_template/widgets/signup/NickNameInputWidget.dart';
import 'package:blueberry_flutter_template/widgets/signup/PasswordConfirmWidget.dart';
import 'package:blueberry_flutter_template/widgets/signup/PasswordInputWidget.dart';
import 'package:blueberry_flutter_template/widgets/signup/PrivacyPolicyWidget.dart';
import 'package:blueberry_flutter_template/widgets/signup/TermsOfServiceWidget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'signup/ConfirmationPage.dart';
import 'signup/EmailInputPage.dart';
import 'signup/NameInputPage.dart';
import 'signup/PrivacyPolicyPage.dart';

final PageController _pageController = PageController();

// 이메일 인증 ( 아이디 )
final emailProvider = StateProvider<String>((ref) => '');
final emailVerificationCodeProvider = StateProvider<String>((ref) => '');

// 이름, 닉네임 생성
final nameProvider = StateProvider<String>((ref) => '');
final nicknameProvider = StateProvider<String>((ref) => '');

// 비밀번호 생성
final passwordProvider = StateProvider<String>((ref) => '');
final passwordConfirmProvider = StateProvider<String>((ref) => '');
final PageController _pageController = PageController();

// 휴대폰 번호 인증 ( 구매할 때 휴대폰 인증 ) ( 따로 만들기 )
final residentRegistrationNumberProvider = StateProvider<String>((ref) => '');
final phoneNumberProvider = StateProvider<String>((ref) => '');
final verificationNumberProvider = StateProvider<String>((ref) => '');

class SignUpScreen extends StatefulWidget {
const SignUpScreen({super.key});
Expand All @@ -44,31 +30,31 @@ class _SignUpScreenState extends State<SignUpScreen> {
controller: _pageController,
physics: const NeverScrollableScrollPhysics(),
children: [
EmailInputScreen(
EmailInputPage(
onNext: () => _pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
),
),
EmailVerificationPage(
PasswordInputPage(
onNext: () => _pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
),
),
NameInputPage(
PasswordConfirmPage(
onNext: () => _pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
),
),
PasswordInputPage(
NameNickNameInputPage(
onNext: () => _pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
),
),
PasswordConfirmPage(
EmailVerifyPage(
onNext: () => _pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
Expand All @@ -94,3 +80,82 @@ class _SignUpScreenState extends State<SignUpScreen> {
);
}
}


class EmailInputPage extends StatelessWidget {
final VoidCallback onNext;
const EmailInputPage({super.key, required this.onNext});

@override
Widget build(BuildContext context) {
return EmailDuplicateWidget(onNext: onNext);
}
}

class PasswordInputPage extends StatelessWidget {
final VoidCallback onNext;
const PasswordInputPage({super.key, required this.onNext});

@override
Widget build(BuildContext context) {
return PasswordInputWidget(onNext: onNext);
}
}

class PasswordConfirmPage extends StatelessWidget {
final VoidCallback onNext;
const PasswordConfirmPage({super.key, required this.onNext});

@override
Widget build(BuildContext context) {
return PasswordConfirmWidget(onNext: onNext);
}
}

class NameNickNameInputPage extends StatelessWidget {
final VoidCallback onNext;
const NameNickNameInputPage({super.key, required this.onNext});

@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
NameInputWidget(),
NickNameInputWidget(onNext: onNext),
],
),
);
}
}

class EmailVerifyPage extends StatelessWidget {
final VoidCallback onNext;
const EmailVerifyPage({super.key, required this.onNext});

@override
Widget build(BuildContext context) {
return EmailVerifyWidget(onNext: onNext);
}
}

class TermsOfServicePage extends StatelessWidget {
final VoidCallback onNext;
const TermsOfServicePage({super.key, required this.onNext});

@override
Widget build(BuildContext context) {
return TermsOfServiceWidget(onNext: onNext);
}
}

class PrivacyPolicyPage extends StatelessWidget {
final VoidCallback onNext;
const PrivacyPolicyPage({super.key, required this.onNext});

@override
Widget build(BuildContext context) {
return PrivacyPolicyWidget(onNext: onNext);
}
}
34 changes: 13 additions & 21 deletions lib/screens/mypage/signup/ConfirmationPage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:async';

import 'package:blueberry_flutter_template/providers/SignUpDataProviders.dart';
import 'package:blueberry_flutter_template/providers/user/FirebaseAuthServiceProvider.dart';
import 'package:blueberry_flutter_template/screens/mypage/MyPageScreen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand All @@ -19,8 +22,6 @@ class ConfirmationPage extends ConsumerWidget {

const ConfirmationPage({super.key, required this.onNext});

get firebaseAuthServiceProvider => null;

@override
Widget build(BuildContext context, WidgetRef ref) {
final email = ref.read(emailProvider.notifier);
Expand Down Expand Up @@ -57,8 +58,9 @@ class ConfirmationPage extends ConsumerWidget {
const SizedBox(height: 20),
isLoading.when(
data: (value) => ElevatedButton(
onPressed:
signUp(email.state, password.state, name.state, context, ref),
onPressed: () async {
await upDateUserDB(email.state, name.state, context, ref);
},
child: const Text('가입하기'),
),
loading: () => const CircularProgressIndicator(),
Expand All @@ -69,35 +71,25 @@ class ConfirmationPage extends ConsumerWidget {
);
}

signUp(email, password, name, context, ref) async {
Future<void> upDateUserDB(email, name, BuildContext context, WidgetRef ref) async {
try {
// 사용자 계정 생성
var userCredential = await ref
.read(firebaseAuthServiceProvider)
.signUpWithEmailPassword(email, password);
var currentUser = await ref.read(firebaseAuthServiceProvider).getCurrentUser()!;

// 새로운 UserDTO 인스턴스 생성
UserModel newUser = UserModel(
userId: userCredential!.uid,
email: email,
userId: currentUser.uid,
name: name,
// 초기 이름 값, 필요에 따라 수정
age: 0,
// 초기 나이 값, 필요에 따라 수정
email: email,
age: 1,
profileImageUrl: '',
// 초기 프로필 사진 URL, 필요에 따라 수정
createdAt: DateTime.now() // 계정 생성 날짜
);
createdAt: DateTime.now());

// Firestore에 사용자 정보 저장
await ref.read(firebaseStoreServiceProvider).createUser(newUser);

Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text(AppStrings.signUpSuccessMessage)),
);
Navigator.push(context, MaterialPageRoute(builder: (context) => MyPageScreen()));
} catch (e) {
// 회원가입 실패 시, 에러 메시지 출력
print('회원가입 실패: $e');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('회원가입 실패: $e'),
Expand Down
Loading

0 comments on commit 159a703

Please sign in to comment.