Skip to content

Commit

Permalink
email인증 및 로그인 스크린 수정 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphanoJack authored Jul 25, 2024
2 parents 9baa489 + a64b81d commit 90f0a2b
Show file tree
Hide file tree
Showing 17 changed files with 438 additions and 392 deletions.
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 @@ -10,7 +9,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.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 @@ -193,14 +191,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 {
static const String name = 'SignUpScreen';
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);
}
}
48 changes: 8 additions & 40 deletions lib/screens/mypage/signup/ConfirmationPage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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:blueberry_flutter_template/services/FirebaseService.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand All @@ -19,15 +23,14 @@ 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);
final name = ref.read(nameProvider.notifier);
final nickname = ref.read(nicknameProvider.notifier);
final password = ref.read(passwordProvider.notifier);
final isLoading = ref.watch(signUpProvider);
final firebaseService = FirebaseService();

return Padding(
padding: const EdgeInsets.all(16.0),
Expand Down Expand Up @@ -57,8 +60,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 firebaseService.upDateUserDB(email.state, name.state);
},
child: const Text('가입하기'),
),
loading: () => const CircularProgressIndicator(),
Expand All @@ -68,40 +72,4 @@ class ConfirmationPage extends ConsumerWidget {
),
);
}

signUp(email, password, name, context, ref) async {
try {
// 사용자 계정 생성
var userCredential = await ref
.read(firebaseAuthServiceProvider)
.signUpWithEmailPassword(email, password);

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

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

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

0 comments on commit 90f0a2b

Please sign in to comment.