diff --git a/fit-a-pet-client/fit-a-pet-client.xcodeproj/project.pbxproj b/fit-a-pet-client/fit-a-pet-client.xcodeproj/project.pbxproj index 5df322e6..54a381b0 100644 --- a/fit-a-pet-client/fit-a-pet-client.xcodeproj/project.pbxproj +++ b/fit-a-pet-client/fit-a-pet-client.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 4A0750D22B07D44000281A4C /* UploadPetPhotoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A0750D12B07D44000281A4C /* UploadPetPhotoVC.swift */; }; 4A0750D42B0892B900281A4C /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A0750D32B0892B900281A4C /* CustomNavigationBar.swift */; }; 4A0750D82B0D130F00281A4C /* PetRegistrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A0750D72B0D130F00281A4C /* PetRegistrationManager.swift */; }; + 4A0974282B45BFA8008B4E43 /* OauthCodeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A0974272B45BFA8008B4E43 /* OauthCodeVC.swift */; }; 4A0FEA492B1B5F6F0084CA6C /* FindInputPhoneNumVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A0FEA482B1B5F6F0084CA6C /* FindInputPhoneNumVC.swift */; }; 4A0FEA4B2B1B5F820084CA6C /* FindInputAuthNumVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A0FEA4A2B1B5F820084CA6C /* FindInputAuthNumVC.swift */; }; 4A15F2072AA641910098F2F7 /* CustomNextBtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A15F2062AA641910098F2F7 /* CustomNextBtn.swift */; }; @@ -69,6 +70,7 @@ 4A0750D12B07D44000281A4C /* UploadPetPhotoVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UploadPetPhotoVC.swift; sourceTree = ""; }; 4A0750D32B0892B900281A4C /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = ""; }; 4A0750D72B0D130F00281A4C /* PetRegistrationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PetRegistrationManager.swift; sourceTree = ""; }; + 4A0974272B45BFA8008B4E43 /* OauthCodeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OauthCodeVC.swift; sourceTree = ""; }; 4A0FEA482B1B5F6F0084CA6C /* FindInputPhoneNumVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindInputPhoneNumVC.swift; sourceTree = ""; }; 4A0FEA4A2B1B5F820084CA6C /* FindInputAuthNumVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindInputAuthNumVC.swift; sourceTree = ""; }; 4A15F2062AA641910098F2F7 /* CustomNextBtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNextBtn.swift; sourceTree = ""; }; @@ -137,6 +139,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4A0974262B45BF67008B4E43 /* OauthVC */ = { + isa = PBXGroup; + children = ( + 4A0974272B45BFA8008B4E43 /* OauthCodeVC.swift */, + ); + path = OauthVC; + sourceTree = ""; + }; 4A15F20C2AA8B3FB0098F2F7 /* SignUpVC */ = { isa = PBXGroup; children = ( @@ -191,6 +201,7 @@ 4ABE58582A85E8B400E22C5F /* ViewControllers */ = { isa = PBXGroup; children = ( + 4A0974262B45BF67008B4E43 /* OauthVC */, 4AF0C8572B2627BE00A45EEE /* EditUserVC */, 4ACDD49F2AD9B32400CD8F1A /* RegistPet */, 4ACDD49A2AD9A9F600CD8F1A /* FindAccountVC */, @@ -489,6 +500,7 @@ 4ACDD4A92ADAFFD100CD8F1A /* InputPetBirthVC.swift in Sources */, 4A15F2142AA8B4A50098F2F7 /* InputPwVC.swift in Sources */, 4AA999942A8485A500E495FA /* SceneDelegate.swift in Sources */, + 4A0974282B45BFA8008B4E43 /* OauthCodeVC.swift in Sources */, 4AD354222AAF7E62004A47B3 /* TabBarController.swift in Sources */, 4A0FEA4B2B1B5F820084CA6C /* FindInputAuthNumVC.swift in Sources */, 4AF0C8522B24E0F000A45EEE /* TableViewModel.swift in Sources */, diff --git a/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate b/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate index 9ec654ba..44ca0505 100644 Binary files a/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate and b/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/fit-a-pet-client/fit-a-pet-client/API/AlamofireManager.swift b/fit-a-pet-client/fit-a-pet-client/API/AlamofireManager.swift index 36ed2b51..56a20fb3 100644 --- a/fit-a-pet-client/fit-a-pet-client/API/AlamofireManager.swift +++ b/fit-a-pet-client/fit-a-pet-client/API/AlamofireManager.swift @@ -40,6 +40,11 @@ class AlamofireManager { .response { response in switch response.result { case .success(let data): + if let responseHeaders = response.response?.allHeaderFields as? [String: String], + let accessToken = responseHeaders["accessToken"] { + KeychainHelper.saveAccessToken(accessToken: accessToken) + os_log("sms token: %@", log: .default, type: .info, accessToken) + } completion(.success(data)) case .failure(let error): completion(.failure(error)) @@ -267,19 +272,68 @@ class AlamofireManager { } } - func kakaoCodeGet(completion: @escaping(Result) -> Void){ - os_log("MyAlamofireManager - kakaoCodeGet() called ", log: .default, type: .info) + func oauthLogin(completion: @escaping(Result) -> Void){ + os_log("MyAlamofireManager - oauthLogin() called", log: .default, type: .info) + + self.session.request(MySearchRouter.oauthLogin) + .validate(statusCode: 200..<300) + .response { response in + switch response.result { + case .success(let data): + completion(.success(data)) + case .failure(let error): + completion(.failure(error)) + } + } + } + func oauthSendSms(completion: @escaping(Result) -> Void){ + os_log("MyAlamofireManager - oauthSendSms() called", log: .default, type: .info) - self.session.request(MySearchRouter.kakaoCode) + self.session.request(MySearchRouter.oauthSendSms) + .validate(statusCode: 200..<300) .response { response in switch response.result { case .success(let data): completion(.success(data)) case .failure(let error): completion(.failure(error)) - } + } } } + func oauthCheckSms(_ code: String, completion: @escaping(Result) -> Void){ + os_log("MyAlamofireManager - oauthCheckSms() called userInput: %@", log: .default, type: .info, code) + + self.session.request(MySearchRouter.oauthCheckSms(code: code)) + .validate(statusCode: 200..<300) + .response { response in + switch response.result { + case .success(let data): + if let responseHeaders = response.response?.allHeaderFields as? [String: String], + let accessToken = responseHeaders["accessToken"] { + KeychainHelper.saveAccessToken(accessToken: accessToken) + os_log("sms token: %@", log: .default, type: .info, accessToken) + } + completion(.success(data)) + case .failure(let error): + completion(.failure(error)) + } + } + } + + func oauthRegistUser(_ name: String, _ uid: String, completion: @escaping(Result) -> Void){ + os_log("MyAlamofireManager - oauthCheckSms() called userInput: %@ ,, %@", log: .default, type: .info, name, uid) + + self.session.request(MySearchRouter.oauthRegistUser(name: name, uid: uid)) + .validate(statusCode: 200..<300) + .response { response in + switch response.result { + case .success(let data): + completion(.success(data)) + case .failure(let error): + completion(.failure(error)) + } + } + } } diff --git a/fit-a-pet-client/fit-a-pet-client/API/MySearchRouter.swift b/fit-a-pet-client/fit-a-pet-client/API/MySearchRouter.swift index 6c1b18fd..102d0dfd 100644 --- a/fit-a-pet-client/fit-a-pet-client/API/MySearchRouter.swift +++ b/fit-a-pet-client/fit-a-pet-client/API/MySearchRouter.swift @@ -17,11 +17,12 @@ enum MySearchRouter: URLRequestConvertible { case findId(phone: String, code: String) case findPw(phone: String, newPassword: String, code: String) case existId(uid: String) - case userProfileInfo + case userProfileInfo, oauthLogin, oauthSendSms case userNotifyType(type: String) case editUserPw(type: String, prePassword: String, newPassword: String) case editUserName(type: String, name: String) - case kakaoCode + case oauthCheckSms(code: String) + case oauthRegistUser(name: String, uid: String) var baseURL: URL { switch self { @@ -29,8 +30,6 @@ enum MySearchRouter: URLRequestConvertible { return URL(string: API.PRESIGNEDURL)! case .uploadImage: return URL(string: PAYLOADURL.PAYLOAD)! - case .kakaoCode: - return URL(string: "https://kauth.kakao.com/oauth/authorize")! default: return URL(string: API.BASE_URL)! } @@ -38,9 +37,9 @@ enum MySearchRouter: URLRequestConvertible { var method: HTTPMethod { switch self { - case .sendSms, .checkSms, .login, .regist, .presignedurl, .registPet,.sendAuthSms, .checkAuthSms, .findId, .findPw: + case .sendSms, .checkSms, .login, .regist, .presignedurl, .registPet,.sendAuthSms, .checkAuthSms, .findId, .findPw, .oauthLogin, .oauthSendSms, .oauthCheckSms, .oauthRegistUser: return .post - case .kakaoCode, .existId, .userProfileInfo, .userNotifyType: + case .existId, .userProfileInfo, .userNotifyType: return .get case .uploadImage, .editUserPw, .editUserName: return .put @@ -57,20 +56,26 @@ enum MySearchRouter: URLRequestConvertible { return "auth/register" case .presignedurl: return "C7QXbC20ti" - case .uploadImage, .kakaoCode: + case .uploadImage: return " " case .registPet: return "pets" case .sendAuthSms, .checkAuthSms: return "auth/search-sms" + case .oauthLogin: + return "auth/oauth" + case .oauthSendSms, .oauthCheckSms: + return "auth/oauth/\(OauthInfo.oauthId)/sms" + case .oauthRegistUser: + return "auth/oauth/\(OauthInfo.oauthId)" case .findId, .findPw: return "accounts/search" case .existId: return "accounts/exists" case .userProfileInfo, .editUserPw, .editUserName: - return "accounts" + return "accounts/\(UserDefaults.standard.string(forKey: "id")!)" case .userNotifyType: - return "accounts/notify" + return "accounts/\(UserDefaults.standard.string(forKey: "id")!)/notify" } } @@ -103,8 +108,14 @@ enum MySearchRouter: URLRequestConvertible { return ["type": type, "prePassword": prePassword, "newPassword": newPassword] case let .editUserName(type, name): return ["type": type, "name": name] - case .uploadImage(_), .kakaoCode, .userProfileInfo: + case .uploadImage(_), .userProfileInfo, .oauthLogin, .oauthSendSms: return [:] + case let .oauthCheckSms(code): + return ["code": code] + case let .oauthRegistUser(name, uid): + return ["name": name, "uid": uid] +// case let .oauthLogin: +// return ["id": id, "nonce": nonce, "provider": provider] } } @@ -225,6 +236,7 @@ enum MySearchRouter: URLRequestConvertible { case .editUserName(let type, let name): let bodyParameters = ["name": name] let queryParameters = [URLQueryItem(name: "type", value: type)] + print(url) if let accessToken = KeychainHelper.loadAccessToken() { request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters) @@ -232,11 +244,43 @@ enum MySearchRouter: URLRequestConvertible { } else { request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters) } + + case .oauthLogin: + let idToken = KeychainHelper.loadTempToken()! + + let bodyParameters = ["id": OauthInfo.oauthId, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any] + let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider)] + + request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters) + + case .oauthSendSms: + let idToken = KeychainHelper.loadTempToken()! + + let bodyParameters = ["to": OauthInfo.phoneNum, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any] + let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider)] + + request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters) + case .oauthCheckSms(let code): + let idToken = KeychainHelper.loadTempToken()! + + let bodyParameters = ["to": OauthInfo.phoneNum, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any] + let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider), URLQueryItem(name: "code", value: code)] + + request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters) - case .kakaoCode: - let queryParameters = [URLQueryItem(name: "client_id", value: "bbe38742c0998fecfaaaaaef6856fc32"),URLQueryItem(name: "redirect_uri", value: "kakaobbe38742c0998fecfaaaaaef6856fc32://oauth"), URLQueryItem(name: "response_type", value: "code")] + case .oauthRegistUser(let name, let uid): + let idToken = KeychainHelper.loadTempToken()! + + let bodyParameters = ["name": name, "uid": uid, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any] + let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider)] + + if let accessToken = KeychainHelper.loadAccessToken() { + request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters) + request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization") + } else { + request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters) + } - request = createURLRequestWithQuery(url: baseURL, queryParameters: queryParameters) default: request = createURLRequestWithBody(url: url) diff --git a/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift b/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift index 9b67790f..5d0fed90 100644 --- a/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift +++ b/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift @@ -3,7 +3,7 @@ import Foundation enum API{ - static let BASE_URL : String = "http://www.fitapet.co.kr:8080/api/v1/" + static let BASE_URL : String = "https://fitapet.co.kr/api/v1/" static let PRESIGNEDURL : String = "https://h1d5jjb17z.apigw.ntruss.com/obj/photo/" } @@ -36,3 +36,9 @@ enum FindIdPwSwitch{ static var userUid = "" } +enum OauthInfo{ + static var oauthId = 0 + static var phoneNum = "" + static var nonce = "" + static var provider = "" +} diff --git a/fit-a-pet-client/fit-a-pet-client/Utils/KeyChainHelper.swift b/fit-a-pet-client/fit-a-pet-client/Utils/KeyChainHelper.swift index c28328a7..91ae7b4e 100644 --- a/fit-a-pet-client/fit-a-pet-client/Utils/KeyChainHelper.swift +++ b/fit-a-pet-client/fit-a-pet-client/Utils/KeyChainHelper.swift @@ -35,36 +35,68 @@ class KeychainHelper { } } - static func savePassword(password: String) { + static func saveTempToken(tempToken: String) { let passwordQuery: [CFString: Any] = [ kSecClass: kSecClassGenericPassword, - kSecAttrAccount: "password", - kSecValueData: password.data(using: .utf8)!, + kSecAttrAccount: "tempToken", + kSecValueData: tempToken.data(using: .utf8)!, ] let status = SecItemAdd(passwordQuery as CFDictionary, nil) if status == errSecDuplicateItem { - SecItemUpdate(passwordQuery as CFDictionary, [kSecValueData: password.data(using: .utf8)!] as CFDictionary) + SecItemUpdate(passwordQuery as CFDictionary, [kSecValueData: tempToken.data(using: .utf8)!] as CFDictionary) } else if status != noErr { - print("Failed to save password to Keychain") + print("Failed to save tempToken to Keychain") } } - static func loadPassword() -> String? { + static func loadTempToken() -> String? { let query: [CFString: Any] = [ kSecClass: kSecClassGenericPassword, - kSecAttrAccount: "password", + kSecAttrAccount: "tempToken", kSecReturnData: kCFBooleanTrue!, ] var item: CFTypeRef? let status = SecItemCopyMatching(query as CFDictionary, &item) - if status == noErr, let data = item as? Data, let password = String(data: data, encoding: .utf8) { - return password + if status == noErr, let data = item as? Data, let token = String(data: data, encoding: .utf8) { + return token } else { return nil } } + +// static func savePassword(password: String) { +// let passwordQuery: [CFString: Any] = [ +// kSecClass: kSecClassGenericPassword, +// kSecAttrAccount: "password", +// kSecValueData: password.data(using: .utf8)!, +// ] +// +// let status = SecItemAdd(passwordQuery as CFDictionary, nil) +// if status == errSecDuplicateItem { +// SecItemUpdate(passwordQuery as CFDictionary, [kSecValueData: password.data(using: .utf8)!] as CFDictionary) +// } else if status != noErr { +// print("Failed to save password to Keychain") +// } +// } +// +// static func loadPassword() -> String? { +// let query: [CFString: Any] = [ +// kSecClass: kSecClassGenericPassword, +// kSecAttrAccount: "password", +// kSecReturnData: kCFBooleanTrue!, +// ] +// +// var item: CFTypeRef? +// let status = SecItemCopyMatching(query as CFDictionary, &item) +// +// if status == noErr, let data = item as? Data, let password = String(data: data, encoding: .utf8) { +// return password +// } else { +// return nil +// } +// } } diff --git a/fit-a-pet-client/fit-a-pet-client/Utils/ResponseData.swift b/fit-a-pet-client/fit-a-pet-client/Utils/ResponseData.swift index c7ff3a4a..df010286 100644 --- a/fit-a-pet-client/fit-a-pet-client/Utils/ResponseData.swift +++ b/fit-a-pet-client/fit-a-pet-client/Utils/ResponseData.swift @@ -1,4 +1,5 @@ -struct ResponseData: Decodable { - let status: String - let message: String -} + +//struct ResponseData: Decodable { +// let status: String +// let message: String +//} diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/FindAccountVC/FindInputAuthNumVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/FindAccountVC/FindInputAuthNumVC.swift index cf46255d..bd4af748 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/FindAccountVC/FindInputAuthNumVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/FindAccountVC/FindInputAuthNumVC.swift @@ -78,10 +78,13 @@ class FindInputAuthNumVC: CustomNavigationBar{ } @objc func changeFindIdCheckVC(_ sender: UIButton){ - let nextVC = ResetPwVC(title: FindIdPwSwitch.findAuth) + + var nextVC: UIViewController if FindIdPwSwitch.findAuth == "아이디 찾기"{ - let nextVC = FindIdCheckVC(title: FindIdPwSwitch.findAuth) + nextVC = FindIdCheckVC(title: FindIdPwSwitch.findAuth) + }else{ + nextVC = ResetPwVC(title: FindIdPwSwitch.findAuth) } AlamofireManager.shared.checkAuthSms(FindIdPwSwitch.phoneNum, FindIdPwSwitch.code){ diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift index 75a1a23d..24ca101d 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift @@ -168,16 +168,23 @@ extension FirstVC{ extension FirstVC{ @objc func kakaoLoginBtnTapped(_ sender: UIButton){ + + let nextVC = OauthCodeVC() + + let nonce = CryptoHelpers.randomNonceString() + print("nonce 값: \(nonce)") + let hashedString = CryptoHelpers.sha256(nonce) + print("hashedString 값: \(hashedString)") - UserApi.shared.loginWithKakaoAccount(prompts:[.Login]) {(oauthToken, error) in + UserApi.shared.loginWithKakaoAccount(prompts:[.Login], nonce: hashedString) {(oauthToken, error) in if let error = error { print(error) } else { print("loginWithKakaoAccount() success.") - print(oauthToken) - _ = oauthToken + KeychainHelper.saveTempToken(tempToken: oauthToken!.idToken!) + print(oauthToken!.idToken) UserApi.shared.me() {(user, error) in if let error = error { @@ -186,8 +193,29 @@ extension FirstVC{ else { print("사용자 정보 가져오기 성공") - print(user) + print(user!.id) + + OauthInfo.provider = "kakao" + OauthInfo.nonce = hashedString + OauthInfo.oauthId = Int(user!.id!) + AlamofireManager.shared.oauthLogin(){ + result in + switch result { + case .success(let data): + // Handle success + if let responseData = data { + // Process the data + let object = try?JSONSerialization.jsonObject(with: responseData, options: []) as? NSDictionary + guard let jsonObject = object else {return} + print("respose jsonData: \(jsonObject)") + self.navigationController?.pushViewController(nextVC, animated: false) + } + case .failure(let error): + // Handle failure + print("Error: \(error)") + } + } } } } diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift index e71170f9..c28c7f9d 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift @@ -147,7 +147,7 @@ class LoginVC: UIViewController{ let dispatchGroup = DispatchGroup() dispatchGroup.enter() - AlamofireManager.shared.login("heejin", "heejin123") { result in + AlamofireManager.shared.login("heejin", "heejin1234") { result in defer { dispatchGroup.leave() } switch result { @@ -186,12 +186,13 @@ class LoginVC: UIViewController{ let memberDict = dataDict["member"] as? [String: Any] { for (key, value) in memberDict { - print("\(key): \(value)") + //print("\(key): \(value)") UserDefaults.standard.set(value, forKey: key) } UserDefaults.standard.synchronize() } + print("Response JSON Data: \(jsonObject)") } catch { print("Error parsing user profile JSON: \(error)") } diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/OauthVC/OauthCodeVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/OauthVC/OauthCodeVC.swift new file mode 100644 index 00000000..9f75be61 --- /dev/null +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/OauthVC/OauthCodeVC.swift @@ -0,0 +1,155 @@ +import UIKit +import SnapKit +import Alamofire + +class OauthCodeVC: UIViewController { + private let textField1: UITextField = { + let textField = UITextField() + textField.placeholder = "번호 입력" + textField.borderStyle = .roundedRect + return textField + }() + + private let textField2: UITextField = { + let textField = UITextField() + textField.placeholder = "코드 입력" + textField.borderStyle = .roundedRect + return textField + }() + + private let sendsmsButton: UIButton = { + let button = UIButton() + button.setTitle("sendsms", for: .normal) + button.setTitleColor(.systemBlue, for: .normal) + button.addTarget(self, action: #selector(sendsmsButtonTapped), for: .touchUpInside) + return button + }() + + private let checksmsButton: UIButton = { + let button = UIButton() + button.setTitle("checksms", for: .normal) + button.setTitleColor(.systemRed, for: .normal) + button.addTarget(self, action: #selector(checksmsButtonTapped), for: .touchUpInside) + return button + }() + + private let registsButton: UIButton = { + let button = UIButton() + button.setTitle("registuser", for: .normal) + button.setTitleColor(.systemRed, for: .normal) + button.addTarget(self, action: #selector(registButtonTapped), for: .touchUpInside) + return button + }() + + override func viewDidLoad() { + super.viewDidLoad() + + setupUI() + } + + private func setupUI() { + view.addSubview(textField1) + view.addSubview(textField2) + view.addSubview(sendsmsButton) + view.addSubview(checksmsButton) + view.addSubview(registsButton) + + self.view.backgroundColor = .white + + textField1.snp.makeConstraints { make in + make.top.equalTo(view.safeAreaLayoutGuide).offset(20) + make.leading.equalToSuperview().offset(20) + make.trailing.equalToSuperview().offset(-20) + make.height.equalTo(40) + } + + textField2.snp.makeConstraints { make in + make.top.equalTo(textField1.snp.bottom).offset(20) + make.leading.equalToSuperview().offset(20) + make.trailing.equalToSuperview().offset(-20) + make.height.equalTo(40) + } + + sendsmsButton.snp.makeConstraints { make in + make.top.equalTo(textField2.snp.bottom).offset(20) + make.centerX.equalToSuperview().offset(-70) + } + + checksmsButton.snp.makeConstraints { make in + make.top.equalTo(textField2.snp.bottom).offset(20) + make.centerX.equalToSuperview().offset(70) + } + + registsButton.snp.makeConstraints { make in + make.top.equalTo(sendsmsButton.snp.bottom).offset(20) + make.centerX.equalToSuperview().offset(70) + } + } + + @objc private func sendsmsButtonTapped() { + + OauthInfo.phoneNum = textField1.text! + + + if let text1 = textField1.text, let text2 = textField2.text { + print("Text 1: \(text1), Text 2: \(text2)") + } + + AlamofireManager.shared.oauthSendSms(){ + result in + switch result { + case .success(let data): + // Handle success + if let responseData = data { + // Process the data + let object = try?JSONSerialization.jsonObject(with: responseData, options: []) as? NSDictionary + guard let jsonObject = object else {return} + print("respose jsonData: \(jsonObject)") + } + case .failure(let error): + // Handle failure + print("Error: \(error)") + } + } + } + + @objc private func checksmsButtonTapped() { + + AlamofireManager.shared.oauthCheckSms(textField2.text!){ + result in + switch result { + case .success(let data): + // Handle success + if let responseData = data { + // Process the data + let object = try?JSONSerialization.jsonObject(with: responseData, options: []) as? NSDictionary + guard let jsonObject = object else {return} + print("respose jsonData: \(jsonObject)") + } + case .failure(let error): + // Handle failure + print("Error: \(error)") + } + } + } + @objc private func registButtonTapped() { + + AlamofireManager.shared.oauthRegistUser("hee", "jin"){ + result in + switch result { + case .success(let data): + // Handle success + if let responseData = data { + // Process the data + let object = try?JSONSerialization.jsonObject(with: responseData, options: []) as? NSDictionary + guard let jsonObject = object else {return} + print("respose jsonData: \(jsonObject)") + } + case .failure(let error): + // Handle failure + print("Error: \(error)") + } + } + } +} + diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputNickVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputNickVC.swift index 4af7c246..04582114 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputNickVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputNickVC.swift @@ -74,9 +74,6 @@ class InputNickVC : UIViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - RegistrationManager.shared.addInput(nickname: "최희진2") - // RegistrationManager.shared.performRegistration() - self.navigationController?.navigationBar.tintColor = .black self.navigationController?.navigationBar.topItem?.title = " " @@ -88,6 +85,11 @@ class InputNickVC : UIViewController { @objc func changeCompleteSignUpVC(_ sender: UIButton){ + + if let nickname = inputNick.text { + RegistrationManager.shared.addInput(nickname: nickname) + } + AlamofireManager.shared.regist(RegistrationManager.shared.id!, RegistrationManager.shared.nickname!, RegistrationManager.shared.pw!, "", ""){ result in switch result { diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputPwVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputPwVC.swift index 7cc41d48..fc0d442f 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputPwVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/SignUpVC/InputPwVC.swift @@ -107,7 +107,7 @@ class InputPwVC : UIViewController { @objc func changeInputNickVC(_ sender: UIButton){ if let pw = inputPw.text { - RegistrationManager.shared.addInput(pw: pw) + RegistrationManager.shared.addInput(pw: pw) } let nextVC = InputNickVC() diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/SettingVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/SettingVC.swift index 8a3a5599..ce76d0ce 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/SettingVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/SettingVC.swift @@ -1,6 +1,5 @@ import UIKit import SnapKit -import SwiftUI class SettingVC: UIViewController { @@ -32,14 +31,14 @@ class SettingVC: UIViewController { profileUserName.text = UserDefaults.standard.string(forKey: "name")! - if let allValues = UserDefaults.standard.dictionaryRepresentation() as? [String: Any] { - print("All Values in UserDefaults:") - for (key, value) in allValues { - print("\(key): \(value)") - } - } else { - print("Unable to retrieve all values from UserDefaults") - } +// if let allValues = UserDefaults.standard.dictionaryRepresentation() as? [String: Any] { +// print("All Values in UserDefaults:") +// for (key, value) in allValues { +// print("\(key): \(value)") +// } +// } else { +// print("Unable to retrieve all values from UserDefaults") +// } } private func initView() { @@ -199,18 +198,3 @@ extension SettingVC: UITableViewDelegate{ } } - -struct MainViewController_Previews: PreviewProvider { - static var previews: some View { - Container().edgesIgnoringSafeArea(.all) - } - - struct Container: UIViewControllerRepresentable { - func makeUIViewController(context: Context) -> UIViewController { - let rootViewController = SettingVC() - return UINavigationController(rootViewController: rootViewController) - } - func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {} - typealias UIViewControllerType = UIViewController - } -}