From 425f33905b3b7bbfdeea9679dca194a523dd9379 Mon Sep 17 00:00:00 2001 From: hyungyu Kim Date: Wed, 19 Jan 2022 20:45:36 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[Feat]=20#126=20-=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=84=9C=EB=B2=84=20=EC=97=B0=EA=B2=B0=20=EB=B0=8F?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=AA=A8=EB=8D=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj | 4 ++ .../Source/NetworkModels/Auth/Login.swift | 28 +++++++++++++ .../Source/NetworkServices/Auth/AuthAPI.swift | 41 +++++++++++++++++-- .../NetworkServices/Auth/AuthService.swift | 13 +++++- 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift diff --git a/Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj b/Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj index a520db77..a9dc2db2 100644 --- a/Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj +++ b/Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj @@ -132,6 +132,7 @@ F8E3496827969B61001B67E7 /* AuthAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E3496727969B61001B67E7 /* AuthAPI.swift */; }; F8E3496A27969B67001B67E7 /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E3496927969B67001B67E7 /* AuthService.swift */; }; F8E3496D2796B7F6001B67E7 /* Signup.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8E3496C2796B7F6001B67E7 /* Signup.swift */; }; + F8F6D70027982D6400725537 /* Login.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F6D6FF27982D6400725537 /* Login.swift */; }; F8FAA9722790344D00C4190F /* HomeHabitCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FAA9702790344D00C4190F /* HomeHabitCVC.swift */; }; F8FAA9732790344D00C4190F /* HomeHabitCVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = F8FAA9712790344D00C4190F /* HomeHabitCVC.xib */; }; F8FAA9762790346000C4190F /* HomeWaitingCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FAA9742790346000C4190F /* HomeWaitingCVC.swift */; }; @@ -269,6 +270,7 @@ F8E3496727969B61001B67E7 /* AuthAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthAPI.swift; sourceTree = ""; }; F8E3496927969B67001B67E7 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = ""; }; F8E3496C2796B7F6001B67E7 /* Signup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signup.swift; sourceTree = ""; }; + F8F6D6FF27982D6400725537 /* Login.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Login.swift; sourceTree = ""; }; F8FAA9702790344D00C4190F /* HomeHabitCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeHabitCVC.swift; sourceTree = ""; }; F8FAA9712790344D00C4190F /* HomeHabitCVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HomeHabitCVC.xib; sourceTree = ""; }; F8FAA9742790346000C4190F /* HomeWaitingCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeWaitingCVC.swift; sourceTree = ""; }; @@ -930,6 +932,7 @@ isa = PBXGroup; children = ( F8E3496C2796B7F6001B67E7 /* Signup.swift */, + F8F6D6FF27982D6400725537 /* Login.swift */, ); path = Auth; sourceTree = ""; @@ -1122,6 +1125,7 @@ buildActionMask = 2147483647; files = ( 2BC1726D278E8F1000BA3029 /* UIView+.swift in Sources */, + F8F6D70027982D6400725537 /* Login.swift in Sources */, F8FAA9722790344D00C4190F /* HomeHabitCVC.swift in Sources */, 2B9852072790984C00CE40A7 /* UIViewController+.swift in Sources */, F82B2E0B278EBC4400219628 /* UserDefaultsKey.swift in Sources */, diff --git a/Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift b/Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift new file mode 100644 index 00000000..70660782 --- /dev/null +++ b/Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift @@ -0,0 +1,28 @@ +// +// Login.swift +// Spark-iOS +// +// Created by kimhyungyu on 2022/01/19. +// + +import Foundation + +// MARK: - Login + +struct Login: Codable { + let accesstoken: Accesstoken + + enum CodingKeys: String, CodingKey { + case accesstoken + } +} + +// MARK: - Accesstoken + +struct Accesstoken: Codable { + let accesstoken: String + + enum CodingKeys: String, CodingKey { + case accesstoken + } +} diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift index 606026a1..8646acc1 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift @@ -13,10 +13,11 @@ public class AuthAPI { static let shared = AuthAPI() var userProvider = MoyaProvider(plugins: [MoyaLoggerPlugin()]) - public init() { } + // 객체화할 수 없게 만들어서 싱글톤 패턴으로만 사용하도록 접근 제어자 설정. + private init() { } func signup(socailID: String, profileImg: UIImage, nickname: String, fcmToken: String, completion: @escaping (NetworkResult) -> Void) { - userProvider.request(.signup(socialId: socailID, profileImg: profileImg, nickname: nickname, fcmToken: fcmToken)) { result in + userProvider.request(.signup(socialID: socailID, profileImg: profileImg, nickname: nickname, fcmToken: fcmToken)) { result in switch result { case .success(let response): let statusCode = response.statusCode @@ -31,8 +32,42 @@ public class AuthAPI { } } - private func judgeSignupStatus(by statusCode: Int, _ data: Data) -> NetworkResult { + func login(socialID: String, fcmToken: String, completion: @escaping (NetworkResult) -> Void) { + userProvider.request(.login(socialID: socialID, fcmToken: fcmToken)) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + let networkResult = self.judgeLoginStatus(by: statusCode, data) + completion(networkResult) + + case .failure(let err): + print(err) + } + } + } + + private func judgeLoginStatus(by statusCode: Int, _ data: Data) -> NetworkResult { + let decoder = JSONDecoder() + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) + else { + return .pathErr + } + switch statusCode { + case 200: + return .success(decodedData.data ?? "None-Data") + case 400..<500: + return .requestErr(decodedData.message) + case 500: + return .serverErr + default: + return .networkFail + } + } + + private func judgeSignupStatus(by statusCode: Int, _ data: Data) -> NetworkResult { let decoder = JSONDecoder() guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) else { diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift index 011bf3f7..6bf073f3 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift @@ -9,7 +9,8 @@ import Foundation import Moya enum AuthService { - case signup(socialId: String, profileImg: UIImage, nickname: String, fcmToken: String) + case signup(socialID: String, profileImg: UIImage, nickname: String, fcmToken: String) + case login(socialID: String, fcmToken: String) } extension AuthService: TargetType { @@ -21,6 +22,8 @@ extension AuthService: TargetType { switch self { case .signup: return "/auth/signup" + case .login: + return "/auth/doorbell" } } @@ -28,6 +31,8 @@ extension AuthService: TargetType { switch self { case .signup: return .post + case .login: + return .get } } @@ -47,6 +52,10 @@ extension AuthService: TargetType { multiPartData.append(profileImgData) return .uploadMultipart(multiPartData) + case .login(let socialID, let fcmToken): + return .requestParameters(parameters: ["socialId": socialID, + "fcmToken": fcmToken], + encoding: URLEncoding.queryString) } } @@ -54,6 +63,8 @@ extension AuthService: TargetType { switch self { case .signup: return Const.Header.authrizationHeader + case .login: + return Const.Header.basicHeader } } } From 90e77543a795a9e43aaba4f5b97ce977d8421453 Mon Sep 17 00:00:00 2001 From: hyungyu Kim Date: Wed, 19 Jan 2022 21:44:30 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[Feat]=20#126=20-=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=84=9C=EB=B2=84=20=EC=97=B0=EA=B2=B0=ED=95=B4?= =?UTF-8?q?=EC=84=9C=20=ED=9A=8C=EC=9B=90=EC=A0=95=EB=B3=B4=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=98=EA=B3=A0=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=ED=8E=B8=EC=A7=91=EC=9C=BC=EB=A1=9C=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Spark-iOS/Resource/Constants/Header.swift | 6 +- .../Source/NetworkServices/Auth/AuthAPI.swift | 2 +- .../Spark-iOS/Source/SceneDelegate.swift | 2 +- .../ViewControllers/Login/LoginVC.swift | 61 +++++++++++++------ .../ViewControllers/Splash/SplashVC.swift | 3 +- .../ViewControllers/TabBar/HomeVC.swift | 1 - 6 files changed, 48 insertions(+), 27 deletions(-) diff --git a/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift b/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift index a5c12e76..66d174e3 100644 --- a/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift +++ b/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift @@ -12,9 +12,9 @@ extension Const { /// Content-Type: application/json static var basicHeader = ["Content-Type": "application/json"] /// access token 을 헤더에 담아서 보내야하는 경우에 사용. -// static var authrizationHeader = ["Content-Type": "application/json", -// "Authorization": accessToken] static var authrizationHeader = ["Content-Type": "application/json", - "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcxLCJpYXQiOjE2NDI1NzU5MjksImV4cCI6MTY0NTE2NzkyOSwiaXNzIjoic3BhcmsifQ.na6paylY4-2dGBLcTtalxaJc-Xt380MnqSJV2JyC64I"] + "Authorization": accessToken] +// static var authrizationHeader = ["Content-Type": "application/json", +// "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcxLCJpYXQiOjE2NDI1NzU5MjksImV4cCI6MTY0NTE2NzkyOSwiaXNzIjoic3BhcmsifQ.na6paylY4-2dGBLcTtalxaJc-Xt380MnqSJV2JyC64I"] } } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift index 8646acc1..86334fd6 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift @@ -57,7 +57,7 @@ public class AuthAPI { switch statusCode { case 200: - return .success(decodedData.data ?? "None-Data") + return .success(decodedData.message) case 400..<500: return .requestErr(decodedData.message) case 500: diff --git a/Spark-iOS/Spark-iOS/Source/SceneDelegate.swift b/Spark-iOS/Spark-iOS/Source/SceneDelegate.swift index d80a08d8..555c5abf 100644 --- a/Spark-iOS/Spark-iOS/Source/SceneDelegate.swift +++ b/Spark-iOS/Spark-iOS/Source/SceneDelegate.swift @@ -18,7 +18,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { window = UIWindow(frame: windowScene.coordinateSpace.bounds) window?.windowScene = windowScene - let rootViewController = UIStoryboard(name: Const.Storyboard.Name.mainTabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.mainTabBar) + let rootViewController = UIStoryboard(name: Const.Storyboard.Name.splash, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.splash) window?.rootViewController = rootViewController window?.makeKeyAndVisible() } diff --git a/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift b/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift index 072a7548..9e8a8d6e 100644 --- a/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift +++ b/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift @@ -21,7 +21,6 @@ class LoginVC: UIViewController { @IBOutlet weak var appleLoginButton: UIButton! @IBOutlet weak var logoImageView: UIImageView! - // MARK: - View Life Cycle override func viewDidLoad() { @@ -103,10 +102,10 @@ extension LoginVC { print(error) } else { if let userID = user?.id { - self.signupWithAPI(userID: String(userID)) - UserDefaults.standard.set(String(userID), forKey: Const.UserDefaultsKey.userID) UserDefaults.standard.set(false, forKey: Const.UserDefaultsKey.isAppleLogin) + + self.loginWithAPI(userID: String(userID)) } } } @@ -121,20 +120,6 @@ extension LoginVC { } } -// MARK: - Network - -extension LoginVC { - - // TODO: - Network. 회원가입 서버통신 - - private func signupWithAPI(userID: String) { - - // TODO: - 엑세스 토큰 userdefaults 등록하고 화면전환 - - presentToMainTabBar() - } -} - // MARK: - AppleSignIn extension LoginVC: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding { @@ -146,11 +131,12 @@ extension LoginVC: ASAuthorizationControllerDelegate, ASAuthorizationControllerP func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { switch authorization.credential { case let appleIDCredential as ASAuthorizationAppleIDCredential: - let userIdentifier = appleIDCredential.user - signupWithAPI(userID: userIdentifier) + UserDefaults.standard.set(userIdentifier, forKey: Const.UserDefaultsKey.userID) UserDefaults.standard.set(true, forKey: Const.UserDefaultsKey.isAppleLogin) + + loginWithAPI(userID: userIdentifier) default: break } @@ -161,3 +147,40 @@ extension LoginVC: ASAuthorizationControllerDelegate, ASAuthorizationControllerP // Handle error. } } + +// MARK: - Network + +extension LoginVC { + private func loginWithAPI(userID: String) { + AuthAPI.shared.login(socialID: userID, fcmToken: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.fcmToken) ?? "") { response in + switch response { + case .success(let data): + if let message = data as? String { + if message == "회원가입을 하지 않은 사용자입니다" { + guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.profileSetting, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.profileSetting) as? ProfileSettingVC else { return } + + nextVC.modalPresentationStyle = .fullScreen + + self.present(nextVC, animated: true, completion: nil) + } else { + // 회원 정보를 불러왔습니다 + guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.mainTabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.mainTabBar) as? MainTBC else { return } + + nextVC.modalPresentationStyle = .fullScreen + nextVC.modalTransitionStyle = .crossDissolve + + self.present(nextVC, animated: true, completion: nil) + } + } + case .requestErr(let message): + print("habitRoomFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("habitRoomFetchWithAPI - pathErr") + case .serverErr: + print("habitRoomFetchWithAPI - serverErr") + case .networkFail: + print("habitRoomFetchWithAPI - networkFail") + } + } + } +} diff --git a/Spark-iOS/Spark-iOS/Source/ViewControllers/Splash/SplashVC.swift b/Spark-iOS/Spark-iOS/Source/ViewControllers/Splash/SplashVC.swift index 3e51d2c8..0000b171 100644 --- a/Spark-iOS/Spark-iOS/Source/ViewControllers/Splash/SplashVC.swift +++ b/Spark-iOS/Spark-iOS/Source/ViewControllers/Splash/SplashVC.swift @@ -55,8 +55,7 @@ class SplashVC: UIViewController { super.viewWillAppear(animated) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) { -// if self.appDelegate?.isLogin == true { - if true { + if self.appDelegate?.isLogin == true { self.presentToMain() } else { diff --git a/Spark-iOS/Spark-iOS/Source/ViewControllers/TabBar/HomeVC.swift b/Spark-iOS/Spark-iOS/Source/ViewControllers/TabBar/HomeVC.swift index 26b5bac2..ff909b60 100644 --- a/Spark-iOS/Spark-iOS/Source/ViewControllers/TabBar/HomeVC.swift +++ b/Spark-iOS/Spark-iOS/Source/ViewControllers/TabBar/HomeVC.swift @@ -217,7 +217,6 @@ extension HomeVC { case .networkFail: print("habitRoomFetchWithAPI - networkFail") } - } } } From 2a94102f3301e5cb34c9da5d43705a033019001b Mon Sep 17 00:00:00 2001 From: hyungyu Kim Date: Wed, 19 Jan 2022 23:17:17 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[Feat]=20#126=20-=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EC=84=9C=EB=B2=84=20=EC=97=B0=EA=B2=B0=20=EB=B0=8F=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Spark-iOS/Resource/Constants/Header.swift | 9 ++-- .../NetworkServices/Auth/AuthService.swift | 2 +- .../NetworkServices/Feed/FeedService.swift | 4 +- .../NetworkServices/Home/HomeService.swift | 2 +- .../MyRoom/MyRoomService.swift | 2 +- .../NetworkServices/Room/RoomService.swift | 18 ++++---- .../ViewControllers/Login/LoginVC.swift | 16 +++---- .../Profile/ProfileSettingVC.swift | 42 ++++++++++++++++++- 8 files changed, 68 insertions(+), 27 deletions(-) diff --git a/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift b/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift index 66d174e3..88320e8f 100644 --- a/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift +++ b/Spark-iOS/Spark-iOS/Resource/Constants/Header.swift @@ -10,11 +10,14 @@ import Foundation extension Const { struct Header { /// Content-Type: application/json - static var basicHeader = ["Content-Type": "application/json"] + static let basicHeader = ["Content-Type": "application/json"] /// access token 을 헤더에 담아서 보내야하는 경우에 사용. - static var authrizationHeader = ["Content-Type": "application/json", + static let authorizationHeader = ["Content-Type": "application/json", "Authorization": accessToken] -// static var authrizationHeader = ["Content-Type": "application/json", +// static var authorizationHeader = ["Content-Type": "application/json", // "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcxLCJpYXQiOjE2NDI1NzU5MjksImV4cCI6MTY0NTE2NzkyOSwiaXNzIjoic3BhcmsifQ.na6paylY4-2dGBLcTtalxaJc-Xt380MnqSJV2JyC64I"] + static let multipartHeader = ["Content-Type": "multipart/form-data"] + static let multipartAuthorizationHeader = ["Content-Type": "multipart/form-data", + "Authorization": accessToken] } } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift index 6bf073f3..06050a2e 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.swift @@ -62,7 +62,7 @@ extension AuthService: TargetType { var headers: [String: String]? { switch self { case .signup: - return Const.Header.authrizationHeader + return Const.Header.basicHeader case .login: return Const.Header.basicHeader } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Feed/FeedService.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Feed/FeedService.swift index dfb6e701..a24e484d 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Feed/FeedService.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Feed/FeedService.swift @@ -52,9 +52,9 @@ extension FeedService: TargetType { var headers: [String : String]? { switch self { case .feedFetch: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .feedLike: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader } } } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Home/HomeService.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Home/HomeService.swift index 16687010..0c86e7a3 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Home/HomeService.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Home/HomeService.swift @@ -43,7 +43,7 @@ extension HomeService: TargetType { var headers: [String: String]? { switch self { case .habitRoomFetch: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader } } } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/MyRoom/MyRoomService.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/MyRoom/MyRoomService.swift index 250aafdf..e2f86b35 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/MyRoom/MyRoomService.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/MyRoom/MyRoomService.swift @@ -51,7 +51,7 @@ extension MyRoomService: TargetType { var headers: [String: String]? { switch self { case .myRoomFetch, .myRoomCertiFetch: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader } } } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Room/RoomService.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Room/RoomService.swift index e6202dad..90ef9330 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Room/RoomService.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Room/RoomService.swift @@ -107,23 +107,23 @@ extension RoomService: TargetType { var headers: [String: String]? { switch self { case .waitingFetch: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .codeJoinCheckFetch: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .enterRoom: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .waitingMemberFetch: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .authUpload: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .createRoom: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .sendSpark: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .startRoom: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader case .setConsiderRest: - return Const.Header.authrizationHeader + return Const.Header.authorizationHeader } } } diff --git a/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift b/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift index 9e8a8d6e..a6693775 100644 --- a/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift +++ b/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift @@ -102,10 +102,10 @@ extension LoginVC { print(error) } else { if let userID = user?.id { - UserDefaults.standard.set(String(userID), forKey: Const.UserDefaultsKey.userID) + UserDefaults.standard.set(String("Kakao@\(userID)"), forKey: Const.UserDefaultsKey.userID) UserDefaults.standard.set(false, forKey: Const.UserDefaultsKey.isAppleLogin) - self.loginWithAPI(userID: String(userID)) + self.loginWithAPI(userID: String("Kakao@\(userID)")) } } } @@ -133,10 +133,10 @@ extension LoginVC: ASAuthorizationControllerDelegate, ASAuthorizationControllerP case let appleIDCredential as ASAuthorizationAppleIDCredential: let userIdentifier = appleIDCredential.user - UserDefaults.standard.set(userIdentifier, forKey: Const.UserDefaultsKey.userID) + UserDefaults.standard.set("Apple@\(userIdentifier)", forKey: Const.UserDefaultsKey.userID) UserDefaults.standard.set(true, forKey: Const.UserDefaultsKey.isAppleLogin) - loginWithAPI(userID: userIdentifier) + loginWithAPI(userID: "Apple@\(userIdentifier)") default: break } @@ -173,13 +173,13 @@ extension LoginVC { } } case .requestErr(let message): - print("habitRoomFetchWithAPI - requestErr: \(message)") + print("loginWithAPI - requestErr: \(message)") case .pathErr: - print("habitRoomFetchWithAPI - pathErr") + print("loginWithAPI - pathErr") case .serverErr: - print("habitRoomFetchWithAPI - serverErr") + print("loginWithAPI - serverErr") case .networkFail: - print("habitRoomFetchWithAPI - networkFail") + print("loginWithAPI - networkFail") } } } diff --git a/Spark-iOS/Spark-iOS/Source/ViewControllers/Profile/ProfileSettingVC.swift b/Spark-iOS/Spark-iOS/Source/ViewControllers/Profile/ProfileSettingVC.swift index defe336b..fb2ad835 100644 --- a/Spark-iOS/Spark-iOS/Source/ViewControllers/Profile/ProfileSettingVC.swift +++ b/Spark-iOS/Spark-iOS/Source/ViewControllers/Profile/ProfileSettingVC.swift @@ -114,6 +114,14 @@ class ProfileSettingVC: UIViewController { } } + private func presentToMainTBC() { + guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.mainTabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.mainTabBar) as? MainTBC else { return } + nextVC.modalTransitionStyle = .crossDissolve + nextVC.modalPresentationStyle = .fullScreen + + present(nextVC, animated: true, completion: nil) + } + // MARK: - @objc @objc @@ -180,8 +188,9 @@ class ProfileSettingVC: UIViewController { @objc func touchCompleteButton() { - // TODO: - 화면 전환 - // profileImageView.image, textField.text 전달 + signupWithAPI(profileImg: profileImageView.image ?? UIImage(), nickname: textField.text ?? "") { + self.presentToMainTBC() + } } @objc @@ -291,3 +300,32 @@ extension ProfileSettingVC { } } } + +// MARK: - Network + +extension ProfileSettingVC { + private func signupWithAPI(profileImg: UIImage, nickname: String, completion: @escaping () -> Void) { + AuthAPI.shared.signup(socailID: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "", + profileImg: profileImg, + nickname: nickname, + fcmToken: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.fcmToken) ?? "") { response in + switch response { + case .success(let data): + if let signup = data as? Signup { + UserDefaults.standard.set(signup.accesstoken, forKey: Const.UserDefaultsKey.accessToken) + } + + completion() + case .requestErr(let message): + print("signupWithAPI - requestErr: \(message)") + case .pathErr: + print("signupWithAPI - pathErr") + case .serverErr: + print("signupWithAPI - serverErr") + case .networkFail: + print("signupWithAPI - networkFail") + } + + } + } +} From 622fa23ffb193520a162734f8d369d3ff573d72c Mon Sep 17 00:00:00 2001 From: hyungyu Kim Date: Thu, 20 Jan 2022 03:14:36 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[Feat]=20#126=20-=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=84=9C=EB=B2=84=EC=97=90=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - isNew 필드로 기존회원인지 아닌지를 판단할 수 있도록 데이터를 받음 --- .../Source/NetworkModels/Auth/Login.swift | 14 +++----------- .../Source/NetworkServices/Auth/AuthAPI.swift | 2 +- .../Source/ViewControllers/Login/LoginVC.swift | 9 ++++++--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift b/Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift index 70660782..dbda7c14 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift @@ -10,19 +10,11 @@ import Foundation // MARK: - Login struct Login: Codable { - let accesstoken: Accesstoken - - enum CodingKeys: String, CodingKey { - case accesstoken - } -} - -// MARK: - Accesstoken - -struct Accesstoken: Codable { - let accesstoken: String + let accesstoken: String? + let isNew: Bool enum CodingKeys: String, CodingKey { case accesstoken + case isNew } } diff --git a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift index 86334fd6..8646acc1 100644 --- a/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift +++ b/Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.swift @@ -57,7 +57,7 @@ public class AuthAPI { switch statusCode { case 200: - return .success(decodedData.message) + return .success(decodedData.data ?? "None-Data") case 400..<500: return .requestErr(decodedData.message) case 500: diff --git a/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift b/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift index a6693775..c3c970d2 100644 --- a/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift +++ b/Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift @@ -155,15 +155,18 @@ extension LoginVC { AuthAPI.shared.login(socialID: userID, fcmToken: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.fcmToken) ?? "") { response in switch response { case .success(let data): - if let message = data as? String { - if message == "회원가입을 하지 않은 사용자입니다" { + if let data = data as? Login { + if data.isNew { + // 회원가입을 하지 않은 사용자입니다. guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.profileSetting, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.profileSetting) as? ProfileSettingVC else { return } nextVC.modalPresentationStyle = .fullScreen self.present(nextVC, animated: true, completion: nil) } else { - // 회원 정보를 불러왔습니다 + // 회원 정보를 불러왔습니다. + UserDefaults.standard.set(data.accesstoken, forKey: Const.UserDefaultsKey.accessToken) + guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.mainTabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.mainTabBar) as? MainTBC else { return } nextVC.modalPresentationStyle = .fullScreen