parent
19250dc929
commit
fa94c5447f
|
@ -10,8 +10,6 @@ import Foundation
|
||||||
struct SignUpRequest: Encodable {
|
struct SignUpRequest: Encodable {
|
||||||
let email: String
|
let email: String
|
||||||
let password: String
|
let password: String
|
||||||
let nickname: String
|
|
||||||
let gender: Gender
|
|
||||||
let marketingPid: String
|
let marketingPid: String
|
||||||
let isAgreeTermsOfService: Bool
|
let isAgreeTermsOfService: Bool
|
||||||
let isAgreePrivacyPolicy: Bool
|
let isAgreePrivacyPolicy: Bool
|
||||||
|
|
|
@ -10,99 +10,127 @@ import SwiftUI
|
||||||
struct SignUpView: View {
|
struct SignUpView: View {
|
||||||
|
|
||||||
@ObservedObject var viewModel = SignUpViewModel()
|
@ObservedObject var viewModel = SignUpViewModel()
|
||||||
|
|
||||||
@StateObject var keyboardHandler = KeyboardHandler()
|
@StateObject var keyboardHandler = KeyboardHandler()
|
||||||
|
@State private var isPasswordVisible: Bool = false
|
||||||
@State private var isShowPhotoPicker = false
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
BaseView(isLoading: $viewModel.isLoading) {
|
BaseView(isLoading: $viewModel.isLoading) {
|
||||||
GeometryReader { proxy in
|
GeometryReader { proxy in
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
DetailNavigationBar(title: viewModel.step == .step2 ? "프로필 설정" : "회원가입") {
|
DetailNavigationBar(title: "회원가입")
|
||||||
viewModel.prevStep()
|
|
||||||
}
|
|
||||||
|
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
VStack(spacing: 13.3) {
|
VStack(spacing: 0) {
|
||||||
if viewModel.step == .step1 {
|
TextField("이메일", text: $viewModel.email)
|
||||||
EmailPasswordView()
|
.autocapitalization(.none)
|
||||||
|
.disableAutocorrection(true)
|
||||||
TermsOfServiceAgreeView()
|
.font(.custom(Font.medium.rawValue, size: 15))
|
||||||
|
.foregroundColor(.grayee)
|
||||||
Text("다음")
|
.keyboardType(.emailAddress)
|
||||||
.font(.custom(Font.bold.rawValue, size: 18.3))
|
.padding(.vertical, 18)
|
||||||
.foregroundColor(Color.white)
|
.padding(.horizontal, 13.3)
|
||||||
.padding(.vertical, 16)
|
.frame(height: 56)
|
||||||
.frame(width: screenSize().width - 53.4)
|
.background(RoundedRectangle(cornerRadius: 6.7).fill(Color.gray33.opacity(0.7)))
|
||||||
.background(Color.button)
|
.padding(.horizontal, 13.3)
|
||||||
.cornerRadius(10)
|
.padding(.top, 13.3)
|
||||||
.padding(.vertical, 13.7)
|
|
||||||
.frame(width: screenSize().width - 26.7)
|
HStack {
|
||||||
.background(Color.gray22)
|
Group {
|
||||||
.cornerRadius(16.7)
|
if isPasswordVisible {
|
||||||
.padding(.top, 13.3)
|
TextField("비밀번호", text: $viewModel.password)
|
||||||
.onTapGesture { viewModel.nextStep() }
|
|
||||||
} else {
|
|
||||||
ZStack {
|
|
||||||
if let selectedImage = viewModel.profileImage {
|
|
||||||
Image(uiImage: selectedImage)
|
|
||||||
.resizable()
|
|
||||||
.scaledToFill()
|
|
||||||
.frame(width: 80, height: 80, alignment: .top)
|
|
||||||
.clipShape(Circle())
|
|
||||||
} else {
|
} else {
|
||||||
Image("ic_logo")
|
SecureField("비밀번호", text: $viewModel.password)
|
||||||
.resizable()
|
}
|
||||||
.scaledToFill()
|
}
|
||||||
.frame(width: 80, height: 80, alignment: .top)
|
.autocapitalization(.none)
|
||||||
.background(Color(hex: "3e3358"))
|
.disableAutocorrection(true)
|
||||||
.clipShape(Circle())
|
.font(.custom(Font.medium.rawValue, size: 15))
|
||||||
|
.foregroundColor(.grayee)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Image(systemName: isPasswordVisible ? "eye.slash.fill" : "eye.fill")
|
||||||
|
.foregroundColor(.grayee)
|
||||||
|
.onTapGesture {
|
||||||
|
isPasswordVisible.toggle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.vertical, 18)
|
||||||
|
.padding(.horizontal, 13.3)
|
||||||
|
.frame(height: 56)
|
||||||
|
.background(RoundedRectangle(cornerRadius: 6.7).fill(Color.gray33.opacity(0.7)))
|
||||||
|
.padding(.horizontal, 13.3)
|
||||||
|
.padding(.top, 16)
|
||||||
|
|
||||||
|
VStack(spacing: 5) {
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
Image(
|
||||||
|
viewModel.isAgreeTerms ?
|
||||||
|
"btn_select_checked" :
|
||||||
|
"btn_select_normal"
|
||||||
|
)
|
||||||
|
.padding(10)
|
||||||
|
.onTapGesture { viewModel.isAgreeTerms.toggle() }
|
||||||
|
|
||||||
|
HStack(spacing: 5) {
|
||||||
|
Text("이용약관")
|
||||||
|
.font(.custom(Font.medium.rawValue, size: 12))
|
||||||
|
.foregroundColor(Color.grayee)
|
||||||
|
|
||||||
|
Text("(필수)")
|
||||||
|
.font(.custom(Font.medium.rawValue, size: 12))
|
||||||
|
.foregroundColor(Color.button)
|
||||||
|
}
|
||||||
|
.onTapGesture {
|
||||||
|
AppState.shared.setAppStep(step: .terms)
|
||||||
}
|
}
|
||||||
|
|
||||||
Image("ic_camera")
|
Spacer()
|
||||||
.padding(10)
|
|
||||||
.background(Color.button)
|
|
||||||
.cornerRadius(30)
|
|
||||||
.offset(x: 40, y: 40)
|
|
||||||
}
|
|
||||||
.frame(alignment: .bottomTrailing)
|
|
||||||
.padding(.top, 13.3)
|
|
||||||
.onTapGesture {
|
|
||||||
isShowPhotoPicker = true
|
|
||||||
}
|
}
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.onTapGesture { viewModel.isAgreeTerms.toggle() }
|
||||||
|
|
||||||
VStack(spacing: 16.7) {
|
HStack(spacing: 10) {
|
||||||
UserTextField(
|
Image(
|
||||||
title: "닉네임",
|
viewModel.isAgreePrivacyPolicy ?
|
||||||
hint: "닉네임을 입력해 주세요",
|
"btn_select_checked" :
|
||||||
isSecure: false,
|
"btn_select_normal"
|
||||||
variable: $viewModel.nickname
|
|
||||||
)
|
)
|
||||||
.padding(.horizontal, 13.3)
|
.padding(10)
|
||||||
|
.onTapGesture { viewModel.isAgreePrivacyPolicy.toggle() }
|
||||||
|
|
||||||
GenderSelectView()
|
HStack(spacing: 5) {
|
||||||
|
Text("개인정보수집 및 이용동의")
|
||||||
|
.font(.custom(Font.medium.rawValue, size: 12))
|
||||||
|
.foregroundColor(Color.grayee)
|
||||||
|
|
||||||
|
Text("(필수)")
|
||||||
|
.font(.custom(Font.medium.rawValue, size: 12))
|
||||||
|
.foregroundColor(Color.button)
|
||||||
|
}
|
||||||
|
.onTapGesture {
|
||||||
|
AppState.shared.setAppStep(step: .privacy)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
.padding(.vertical, 20)
|
.contentShape(Rectangle())
|
||||||
.frame(width: screenSize().width - 26.7, alignment: .leading)
|
.onTapGesture { viewModel.isAgreePrivacyPolicy.toggle() }
|
||||||
.background(Color.gray22)
|
|
||||||
.cornerRadius(6.7)
|
|
||||||
.padding(.top, 16.7)
|
|
||||||
|
|
||||||
Text("회원가입")
|
|
||||||
.font(.custom(Font.bold.rawValue, size: 18.3))
|
|
||||||
.foregroundColor(Color.white)
|
|
||||||
.padding(.vertical, 16)
|
|
||||||
.frame(width: screenSize().width - 53.4)
|
|
||||||
.background(Color.button)
|
|
||||||
.cornerRadius(10)
|
|
||||||
.padding(.vertical, 13.7)
|
|
||||||
.frame(width: screenSize().width - 26.7)
|
|
||||||
.background(Color.gray22)
|
|
||||||
.cornerRadius(16.7)
|
|
||||||
.padding(.top, 13.3)
|
|
||||||
.onTapGesture { viewModel.signUp() }
|
|
||||||
}
|
}
|
||||||
|
.padding(.top, 20)
|
||||||
|
.padding(.horizontal, 13.3)
|
||||||
|
|
||||||
|
Text("회원가입")
|
||||||
|
.font(.custom(Font.bold.rawValue, size: 18.3))
|
||||||
|
.foregroundColor(Color.white)
|
||||||
|
.padding(.vertical, 16)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.background(Color.button)
|
||||||
|
.cornerRadius(10)
|
||||||
|
.padding(.horizontal, 13.3)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.onTapGesture { viewModel.signUp() }
|
||||||
|
.padding(.top, 26.7)
|
||||||
|
|
||||||
Rectangle()
|
Rectangle()
|
||||||
.foregroundColor(Color.black)
|
.foregroundColor(Color.black)
|
||||||
|
@ -121,14 +149,6 @@ struct SignUpView: View {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isShowPhotoPicker {
|
|
||||||
ImagePicker(
|
|
||||||
isShowing: $isShowPhotoPicker,
|
|
||||||
selectedImage: $viewModel.profileImage,
|
|
||||||
sourceType: .photoLibrary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
|
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
|
||||||
GeometryReader { geo in
|
GeometryReader { geo in
|
||||||
|
@ -150,194 +170,6 @@ struct SignUpView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
func EmailPasswordView() -> some View {
|
|
||||||
VStack(spacing: 26.7) {
|
|
||||||
UserTextField(
|
|
||||||
title: "이메일",
|
|
||||||
hint: "이메일 주소를 입력해 주세요",
|
|
||||||
isSecure: false,
|
|
||||||
variable: $viewModel.email,
|
|
||||||
keyboardType: .emailAddress
|
|
||||||
)
|
|
||||||
.padding(.horizontal, 13.3)
|
|
||||||
|
|
||||||
UserTextField(
|
|
||||||
title: "비밀번호",
|
|
||||||
hint: "비밀번호 (영문, 숫자 포함 8~20자)",
|
|
||||||
isSecure: true,
|
|
||||||
variable: $viewModel.password,
|
|
||||||
keyboardType: .emailAddress
|
|
||||||
)
|
|
||||||
.padding(.horizontal, 13.3)
|
|
||||||
|
|
||||||
UserTextField(
|
|
||||||
title: "비밀번호 확인",
|
|
||||||
hint: "비밀번호를 다시 입력해 주세요",
|
|
||||||
isSecure: true,
|
|
||||||
variable: $viewModel.passwordConfirm,
|
|
||||||
keyboardType: .emailAddress
|
|
||||||
)
|
|
||||||
.padding(.horizontal, 13.3)
|
|
||||||
}
|
|
||||||
.padding(.vertical, 20)
|
|
||||||
.frame(width: screenSize().width - 26.7)
|
|
||||||
.background(Color.gray22)
|
|
||||||
.cornerRadius(6.7)
|
|
||||||
.padding(.top, 13.3)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
func GenderSelectView() -> some View {
|
|
||||||
VStack(alignment: .leading, spacing: 13.3) {
|
|
||||||
Text("성별")
|
|
||||||
.font(.custom(Font.bold.rawValue, size: 12))
|
|
||||||
.foregroundColor(Color.grayee)
|
|
||||||
.padding(.leading, 6.7)
|
|
||||||
|
|
||||||
HStack(spacing: 0) {
|
|
||||||
HStack(spacing: 13.3) {
|
|
||||||
Image(
|
|
||||||
viewModel.gender == .FEMALE ?
|
|
||||||
"btn_radio_select_selected" :
|
|
||||||
"btn_radio_select_normal"
|
|
||||||
).resizable()
|
|
||||||
.frame(width: 20, height: 20)
|
|
||||||
|
|
||||||
Text("여자")
|
|
||||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
|
||||||
.foregroundColor(Color.grayee)
|
|
||||||
}
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
if viewModel.gender != .FEMALE {
|
|
||||||
viewModel.gender = .FEMALE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
HStack(spacing: 13.3) {
|
|
||||||
Image(
|
|
||||||
viewModel.gender == .MALE ?
|
|
||||||
"btn_radio_select_selected" :
|
|
||||||
"btn_radio_select_normal"
|
|
||||||
).resizable()
|
|
||||||
.frame(width: 20, height: 20)
|
|
||||||
|
|
||||||
Text("남자")
|
|
||||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
|
||||||
.foregroundColor(Color.grayee)
|
|
||||||
}
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
if viewModel.gender != .MALE {
|
|
||||||
viewModel.gender = .MALE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
HStack(spacing: 13.3) {
|
|
||||||
Image(
|
|
||||||
viewModel.gender == .NONE ?
|
|
||||||
"btn_radio_select_selected" :
|
|
||||||
"btn_radio_select_normal"
|
|
||||||
).resizable()
|
|
||||||
.frame(width: 20, height: 20)
|
|
||||||
|
|
||||||
Text("공개 안 함")
|
|
||||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
|
||||||
.foregroundColor(Color.grayee)
|
|
||||||
}
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
if viewModel.gender != .NONE {
|
|
||||||
viewModel.gender = .NONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
.padding(.leading, 6.7)
|
|
||||||
}
|
|
||||||
.frame(width: screenSize().width - 53.4)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
func TermsOfServiceAgreeView() -> some View {
|
|
||||||
VStack(spacing: 0) {
|
|
||||||
Text("약관 동의")
|
|
||||||
.font(.custom(Font.bold.rawValue, size: 12))
|
|
||||||
.foregroundColor(Color.grayee)
|
|
||||||
.frame(width: screenSize().width - 60, height: 50, alignment: .leading)
|
|
||||||
|
|
||||||
Rectangle()
|
|
||||||
.frame(width: screenSize().width - 53.4, height: 1)
|
|
||||||
.foregroundColor(Color.gray90)
|
|
||||||
|
|
||||||
HStack(spacing: 6.7) {
|
|
||||||
Text("이용약관 (필수)")
|
|
||||||
.font(.custom(Font.medium.rawValue, size: 12))
|
|
||||||
.foregroundColor(Color.grayee)
|
|
||||||
|
|
||||||
Text("(필수)")
|
|
||||||
.font(.custom(Font.medium.rawValue, size: 12))
|
|
||||||
.foregroundColor(Color.button)
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Image(
|
|
||||||
viewModel.isAgreeTerms ?
|
|
||||||
"btn_select_checked" :
|
|
||||||
"btn_select_normal"
|
|
||||||
).resizable()
|
|
||||||
.frame(width: 20, height: 20)
|
|
||||||
}
|
|
||||||
.frame(width: screenSize().width - 60, height: 50, alignment: .leading)
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
viewModel.isAgreeTerms.toggle()
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle()
|
|
||||||
.frame(width: screenSize().width - 53.4, height: 1)
|
|
||||||
.foregroundColor(Color.gray90)
|
|
||||||
|
|
||||||
HStack(spacing: 6.7) {
|
|
||||||
Text("개인정보수집 동의")
|
|
||||||
.font(.custom(Font.medium.rawValue, size: 12))
|
|
||||||
.foregroundColor(Color.grayee)
|
|
||||||
|
|
||||||
Text("(필수)")
|
|
||||||
.font(.custom(Font.medium.rawValue, size: 12))
|
|
||||||
.foregroundColor(Color.button)
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Image(
|
|
||||||
viewModel.isAgreePrivacyPolicy ?
|
|
||||||
"btn_select_checked" :
|
|
||||||
"btn_select_normal"
|
|
||||||
).resizable()
|
|
||||||
.frame(width: 20, height: 20)
|
|
||||||
}
|
|
||||||
.frame(width: screenSize().width - 60, height: 50, alignment: .leading)
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
viewModel.isAgreePrivacyPolicy.toggle()
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle()
|
|
||||||
.frame(width: screenSize().width - 53.4, height: 1)
|
|
||||||
.foregroundColor(Color.gray90)
|
|
||||||
}
|
|
||||||
.padding(.vertical, 13.3)
|
|
||||||
.frame(width: screenSize().width - 26.7)
|
|
||||||
.background(Color.gray22)
|
|
||||||
.cornerRadius(6.7)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SignUpView_Previews: PreviewProvider {
|
struct SignUpView_Previews: PreviewProvider {
|
||||||
|
|
|
@ -19,117 +19,65 @@ final class SignUpViewModel: ObservableObject {
|
||||||
@Published var isLoading = false
|
@Published var isLoading = false
|
||||||
|
|
||||||
@Published var email = ""
|
@Published var email = ""
|
||||||
@Published var nickname = ""
|
|
||||||
@Published var gender: Gender = .NONE
|
|
||||||
|
|
||||||
@Published var password = ""
|
@Published var password = ""
|
||||||
@Published var passwordConfirm = ""
|
|
||||||
|
|
||||||
@Published var profileImage: UIImage? = nil
|
|
||||||
|
|
||||||
@Published var isAgreeTerms = false
|
@Published var isAgreeTerms = false
|
||||||
@Published var isAgreePrivacyPolicy = false
|
@Published var isAgreePrivacyPolicy = false
|
||||||
|
|
||||||
enum Step {
|
|
||||||
case step1, step2
|
|
||||||
}
|
|
||||||
|
|
||||||
@Published private(set) var step = Step.step1
|
|
||||||
|
|
||||||
func prevStep() {
|
|
||||||
if step == .step1 {
|
|
||||||
AppState.shared.back()
|
|
||||||
} else {
|
|
||||||
step = .step1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func nextStep() {
|
|
||||||
if validateStep1() {
|
|
||||||
step = .step2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func signUp() {
|
func signUp() {
|
||||||
if validateStep2() {
|
if validate() {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
|
|
||||||
let request = SignUpRequest(
|
let request = SignUpRequest(
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
nickname: nickname,
|
|
||||||
gender: gender,
|
|
||||||
marketingPid: UserDefaults.string(forKey: .marketingPid),
|
marketingPid: UserDefaults.string(forKey: .marketingPid),
|
||||||
isAgreeTermsOfService: true,
|
isAgreeTermsOfService: true,
|
||||||
isAgreePrivacyPolicy: true
|
isAgreePrivacyPolicy: true
|
||||||
)
|
)
|
||||||
|
|
||||||
var multipartData = [MultipartFormData]()
|
repository.signUp(request: request)
|
||||||
|
.sink { result in
|
||||||
let encoder = JSONEncoder()
|
switch result {
|
||||||
encoder.outputFormatting = .withoutEscapingSlashes
|
case .finished:
|
||||||
let jsonData = try? encoder.encode(request)
|
DEBUG_LOG("finish")
|
||||||
|
case .failure(let error):
|
||||||
if let jsonData = jsonData {
|
ERROR_LOG(error.localizedDescription)
|
||||||
if let profileImage = profileImage, let imageData = profileImage.jpegData(compressionQuality: 0.8) {
|
}
|
||||||
multipartData.append(
|
} receiveValue: { response in
|
||||||
MultipartFormData(
|
self.isLoading = false
|
||||||
provider: .data(imageData),
|
let responseData = response.data
|
||||||
name: "profileImage",
|
do {
|
||||||
fileName: "\(UUID().uuidString)_\(Date().timeIntervalSince1970 * 1000).jpg",
|
let jsonDecoder = JSONDecoder()
|
||||||
mimeType: "image/*")
|
let decoded = try jsonDecoder.decode(ApiResponse<LoginResponse>.self, from: responseData)
|
||||||
)
|
|
||||||
}
|
if let data = decoded.data, decoded.success {
|
||||||
|
FirebaseTracking.shared.signUp(method: "email")
|
||||||
multipartData.append(MultipartFormData(provider: .data(jsonData), name: "request"))
|
UserDefaults.set(data.profileImage, forKey: .profileImage)
|
||||||
|
UserDefaults.set(data.nickname, forKey: .nickname)
|
||||||
repository.signUp(parameters: multipartData)
|
UserDefaults.set(data.userId, forKey: .userId)
|
||||||
.sink { result in
|
UserDefaults.set(data.email, forKey: .email)
|
||||||
switch result {
|
UserDefaults.set(data.token, forKey: .token)
|
||||||
case .finished:
|
AppState.shared.back()
|
||||||
DEBUG_LOG("finish")
|
} else {
|
||||||
case .failure(let error):
|
if let message = decoded.message {
|
||||||
ERROR_LOG(error.localizedDescription)
|
self.errorMessage = message
|
||||||
}
|
|
||||||
} receiveValue: { response in
|
|
||||||
self.isLoading = false
|
|
||||||
let responseData = response.data
|
|
||||||
do {
|
|
||||||
let jsonDecoder = JSONDecoder()
|
|
||||||
let decoded = try jsonDecoder.decode(ApiResponse<LoginResponse>.self, from: responseData)
|
|
||||||
|
|
||||||
if let data = decoded.data, decoded.success {
|
|
||||||
FirebaseTracking.shared.signUp(method: "email")
|
|
||||||
UserDefaults.set(data.profileImage, forKey: .profileImage)
|
|
||||||
UserDefaults.set(data.nickname, forKey: .nickname)
|
|
||||||
UserDefaults.set(data.userId, forKey: .userId)
|
|
||||||
UserDefaults.set(data.email, forKey: .email)
|
|
||||||
UserDefaults.set(data.token, forKey: .token)
|
|
||||||
AppState.shared.back()
|
|
||||||
} else {
|
} else {
|
||||||
if let message = decoded.message {
|
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||||
self.errorMessage = message
|
|
||||||
} else {
|
|
||||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
|
||||||
}
|
|
||||||
|
|
||||||
self.isShowPopup = true
|
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
|
||||||
self.isShowPopup = true
|
self.isShowPopup = true
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||||
|
self.isShowPopup = true
|
||||||
}
|
}
|
||||||
.store(in: &subscription)
|
}
|
||||||
} else {
|
.store(in: &subscription)
|
||||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
|
||||||
self.isShowPopup = true
|
|
||||||
self.isLoading = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func validateStep1() -> Bool {
|
private func validate() -> Bool {
|
||||||
if email.trimmingCharacters(in: .whitespaces).isEmpty || !validateEmail() {
|
if email.trimmingCharacters(in: .whitespaces).isEmpty || !validateEmail() {
|
||||||
errorMessage = "올바른 이메일을 입력하세요"
|
errorMessage = "올바른 이메일을 입력하세요"
|
||||||
isShowPopup = true
|
isShowPopup = true
|
||||||
|
@ -148,12 +96,6 @@ final class SignUpViewModel: ObservableObject {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if password != passwordConfirm {
|
|
||||||
errorMessage = "비밀번호가 일치하지 않습니다."
|
|
||||||
isShowPopup = true
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isAgreeTerms || !isAgreePrivacyPolicy {
|
if !isAgreeTerms || !isAgreePrivacyPolicy {
|
||||||
errorMessage = "약관에 동의하셔야 회원가입이 가능합니다."
|
errorMessage = "약관에 동의하셔야 회원가입이 가능합니다."
|
||||||
isShowPopup = true
|
isShowPopup = true
|
||||||
|
@ -163,16 +105,6 @@ final class SignUpViewModel: ObservableObject {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateStep2() -> Bool {
|
|
||||||
if nickname.trimmingCharacters(in: .whitespaces).isEmpty || nickname.trimmingCharacters(in: .whitespaces).count < 2 {
|
|
||||||
errorMessage = "닉네임은 2자 이상 입력해 주세요."
|
|
||||||
isShowPopup = true
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private func validateEmail() -> Bool {
|
private func validateEmail() -> Bool {
|
||||||
let emailRegEx = "^.+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*$"
|
let emailRegEx = "^.+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*$"
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import Moya
|
||||||
|
|
||||||
enum UserApi {
|
enum UserApi {
|
||||||
case login(request: LoginRequest)
|
case login(request: LoginRequest)
|
||||||
case signUp(parameters: [MultipartFormData])
|
case signUp(request: SignUpRequest)
|
||||||
case findPassword(request: ForgotPasswordRequest)
|
case findPassword(request: ForgotPasswordRequest)
|
||||||
case searchUser(nickname: String)
|
case searchUser(nickname: String)
|
||||||
case getMypage
|
case getMypage
|
||||||
|
@ -48,7 +48,7 @@ extension UserApi: TargetType {
|
||||||
return "/member/login"
|
return "/member/login"
|
||||||
|
|
||||||
case .signUp:
|
case .signUp:
|
||||||
return "/member/signup"
|
return "/member/signup/v2"
|
||||||
|
|
||||||
case .findPassword:
|
case .findPassword:
|
||||||
return "/forgot-password"
|
return "/forgot-password"
|
||||||
|
@ -137,8 +137,8 @@ extension UserApi: TargetType {
|
||||||
case .login(let request):
|
case .login(let request):
|
||||||
return .requestJSONEncodable(request)
|
return .requestJSONEncodable(request)
|
||||||
|
|
||||||
case .signUp(let parameters):
|
case .signUp(let request):
|
||||||
return .uploadMultipart(parameters)
|
return .requestJSONEncodable(request)
|
||||||
|
|
||||||
case .findPassword(let request):
|
case .findPassword(let request):
|
||||||
return .requestJSONEncodable(request)
|
return .requestJSONEncodable(request)
|
||||||
|
|
|
@ -17,8 +17,8 @@ final class UserRepository {
|
||||||
return api.requestPublisher(.login(request: request))
|
return api.requestPublisher(.login(request: request))
|
||||||
}
|
}
|
||||||
|
|
||||||
func signUp(parameters: [MultipartFormData]) -> AnyPublisher<Response, MoyaError> {
|
func signUp(request: SignUpRequest) -> AnyPublisher<Response, MoyaError> {
|
||||||
return api.requestPublisher(.signUp(parameters: parameters))
|
return api.requestPublisher(.signUp(request: request))
|
||||||
}
|
}
|
||||||
|
|
||||||
func findPassword(email: String) -> AnyPublisher<Response, MoyaError> {
|
func findPassword(email: String) -> AnyPublisher<Response, MoyaError> {
|
||||||
|
|
Loading…
Reference in New Issue