Skip to content

Commit

Permalink
[FEAT] TeamNADA#101 - 더보기뷰 로그아웃, 회원탈퇴 위치 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mini-min committed Dec 1, 2021
1 parent 686fd2d commit 64c5854
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<constraint firstItem="DVO-N6-tSR" firstAttribute="leading" secondItem="wb8-4G-Pj8" secondAttribute="leading" constant="24" id="x8c-f6-C4o"/>
</constraints>
</view>
<tableView autoresizesSubviews="NO" clipsSubviews="YES" contentMode="scaleToFill" bounces="NO" alwaysBounceVertical="YES" scrollEnabled="NO" bouncesZoom="NO" dataMode="prototypes" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" estimatedSectionHeaderHeight="-1" sectionFooterHeight="28" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="WnB-Ge-3qg">
<tableView autoresizesSubviews="NO" clipsSubviews="YES" contentMode="scaleToFill" bounces="NO" alwaysBounceVertical="YES" scrollEnabled="NO" bouncesZoom="NO" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" estimatedSectionHeaderHeight="-1" sectionFooterHeight="28" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="WnB-Ge-3qg">
<rect key="frame" x="0.0" y="104" width="375" height="404"/>
<color key="backgroundColor" name="textBox"/>
<constraints>
Expand Down
4 changes: 2 additions & 2 deletions NADA-iOS-forRelease/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
// window?.rootViewController = UIStoryboard(name: Const.Storyboard.Name.tabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.tabBarViewController)
window?.rootViewController = UIStoryboard(name: Const.Storyboard.Name.login, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.loginViewController)
window?.rootViewController = UIStoryboard(name: Const.Storyboard.Name.tabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.tabBarViewController)
// window?.rootViewController = UIStoryboard(name: Const.Storyboard.Name.login, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.loginViewController)
window?.makeKeyAndVisible()

IQKeyboardManager.shared.enable = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,28 @@ class LoginViewController: UIViewController {
// getUserIDFetchWithAPI(userID: "nada")
// getUserTokenFetchWithAPI(userID: "nada")
// postUserSignUpWithAPI(request: User(userID: "nada3"))
// deleteUserWithAPI(userID: "nada3")
}

// MARK: - IBAction Properties
// 카카오톡으로 로그인 버튼 클릭 시
@IBAction func kakaoLoginButton(_ sender: Any) {
// 카카오톡 설치 여부 확인
if (UserApi.isKakaoTalkLoginAvailable()) {
// 카카오톡 로그인. api 호출 결과를 클로저로 전달.
UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in
if let error = error {
// 예외 처리 (로그인 취소 등)
print(error)
}
else {
print("loginWithKakaoTalk() success.")
// do something
_ = oauthToken
// 어세스토큰
let accessToken = oauthToken?.accessToken
}
}
} else {
// 웹 브라우저로 카카오 로그인
UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in
// 유효한 토큰 검사
if AuthApi.hasToken() {
UserApi.shared.accessTokenInfo { (_, error) in
if let error = error {
print(error)
if let sdkError = error as? SdkError, sdkError.isInvalidTokenError() == true {
self.signUp()
} else {
// 기타 에러
}
} else {
print("loginWithKakaoAccount() success.")

// do something
_ = oauthToken
// 토큰 유효성 체크 성공(필요 시 토큰 갱신됨)
// ✅ 사용자 정보를 가져오고 화면전환을 하는 커스텀 메서드
self.getUserInfo()
}
}
} else {
self.signUp()
}
}

Expand Down Expand Up @@ -115,21 +103,58 @@ extension LoginViewController {
}
}
}
}

// MARK: - Extensions
extension LoginViewController {

// FIXME: - 계정 탈퇴 네트워크 함수 추후 위치 수정
func deleteUserWithAPI(userID: String) {
UserAPI.shared.userDelete(userID: userID) { response in
switch response {
case .success:
print("deleteUserWithAPI - success")
case .requestErr(let message):
print("deleteUserWithAPI - requestErr: \(message)")
case .pathErr:
print("deleteUserWithAPI - pathErr")
case .serverErr:
print("deleteUserWithAPI - serverErr")
case .networkFail:
print("deleteUserWithAPI - networkFail")
func signUp() {
// 카카오톡 설치 여부 확인
if UserApi.isKakaoTalkLoginAvailable() {
// 카카오톡 로그인. api 호출 결과를 클로저로 전달.
UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in
if let error = error {
// 예외 처리 (로그인 취소 등)
print(error)
} else {
print("loginWithKakaoTalk() success.")
// do something
_ = oauthToken
// 어세스토큰
let accessToken = oauthToken?.accessToken
}
}
} else {
// 웹 브라우저로 카카오 로그인
UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in
if let error = error {
print(error)
} else {
print("loginWithKakaoAccount() success.")

// do something
_ = oauthToken
}
}
}
}

// 사용자 정보를 성공적으로 가져왔을 때, 화면전환
private func getUserInfo() {
// 사용자 정보 가져오기
UserApi.shared.me() {(user, error) in
if let error = error {
print(error)
} else {
print("me() success.")

// 이메일 정보
let email = user?.kakaoAccount?.email

guard let nextVC = self.storyboard?.instantiateViewController(withIdentifier: Const.ViewController.Identifier.tabBarViewController) as? TabBarViewController else { return }

// ✅ 화면전환
self.navigationController?.pushViewController(nextVC, animated: true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit
import KakaoSDKUser

class MoreViewController: UIViewController {

Expand All @@ -15,12 +16,12 @@ class MoreViewController: UIViewController {
var secondItems = ["로그아웃", "정보 초기화", "회원탈퇴"]

@IBOutlet weak var moreListTableView: UITableView!
// @IBOutlet weak var darkModeHeaderView: UIView!
// @IBOutlet weak var modeSwitch: UISwitch!
// @IBOutlet weak var darkModeHeaderView: UIView!
// @IBOutlet weak var modeSwitch: UISwitch!

override func viewDidLoad() {
super.viewDidLoad()

moreListTableView.register(MoreListTableViewCell.nib(), forCellReuseIdentifier: "MoreListTableViewCell")

moreListTableView.delegate = self
Expand All @@ -29,34 +30,58 @@ class MoreViewController: UIViewController {

// TODO: - 다크 모드 대응용 서버 코드
// modeSwitch.isOn = defaults.bool(forKey: "darkModeState")

// if let window = UIApplication.shared.windows.first {
// if #available(iOS 13.0, *) {
// window.overrideUserInterfaceStyle = modeSwitch.isOn == true ? .dark : .light
// defaults.set(modeSwitch.isOn, forKey: "darkModeState")
// } else {
// window.overrideUserInterfaceStyle = .light
// }
// }
// if let window = UIApplication.shared.windows.first {
// if #available(iOS 13.0, *) {
// window.overrideUserInterfaceStyle = modeSwitch.isOn == true ? .dark : .light
// defaults.set(modeSwitch.isOn, forKey: "darkModeState")
// } else {
// window.overrideUserInterfaceStyle = .light
// }
// }
}

// @IBAction func darkModeChangeSwitch(_ sender: UISwitch) {
// // TODO: - 다크 모드 대응용 서버 코드
// if let window = UIApplication.shared.windows.first {
// if #available(iOS 13.0, *) {
// window.overrideUserInterfaceStyle = modeSwitch.isOn == true ? .dark : .light
// defaults.set(modeSwitch.isOn, forKey: "darkModeState")
// } else {
// window.overrideUserInterfaceStyle = .light
// }
// }
// }
// @IBAction func darkModeChangeSwitch(_ sender: UISwitch) {
// // TODO: - 다크 모드 대응용 서버 코드
// if let window = UIApplication.shared.windows.first {
// if #available(iOS 13.0, *) {
// window.overrideUserInterfaceStyle = modeSwitch.isOn == true ? .dark : .light
// defaults.set(modeSwitch.isOn, forKey: "darkModeState")
// } else {
// window.overrideUserInterfaceStyle = .light
// }
// }
// }
}

// MARK: - TableView Delegate
extension MoreViewController: UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return 3
return 2
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// tableView.deselectRow(at: indexPath, animated: true)

if indexPath.section == 0 {
switch indexPath.row {
case 0: print("개인정보 처리방침")
case 1: print("서비스 이용약관")
case 2: print("Team NADA")
case 3: print("오픈소스 라이브러리")
default: print("default!")
}
} else if indexPath.section == 1 {
switch indexPath.row {
case 0: print("로그아웃!")
case 1: print("정보 초기화!")
case 2:
print("회원탈퇴!")
// TODO: - 회원탈퇴 서버 전, alert 창이나 별도의 알림 필요, 수정 요함
// deleteUserWithAPI(userID: "nada3")
default: print("default!")
}
}
}
}

Expand Down Expand Up @@ -95,3 +120,42 @@ extension MoreViewController: UITableViewDataSource {
return serviceCell
}
}

// MARK: - Network
extension MoreViewController {
// FIXME: - 계정 탈퇴 네트워크 함수 추후 위치 수정
func deleteUserWithAPI(userID: String) {
UserAPI.shared.userDelete(userID: userID) { response in
switch response {
case .success:
print("deleteUserWithAPI - success")
case .requestErr(let message):
print("deleteUserWithAPI - requestErr: \(message)")
case .pathErr:
print("deleteUserWithAPI - pathErr")
case .serverErr:
print("deleteUserWithAPI - serverErr")
case .networkFail:
print("deleteUserWithAPI - networkFail")
}
}
}
}

// MARK: - Extensions
extension MoreViewController {
func logout() {
// ✅ 로그아웃 : 로그아웃은 API 요청의 성공 여부와 관계없이 토큰을 삭제 처리한다는 점에 유의합니다.
UserApi.shared.logout {(error) in
if let error = error {
print(error)
}
else {
print("logout() success.")

// ✅ 로그아웃 시 메인으로 보냄
self.navigationController?.popViewController(animated: true)
}
}
}
}

0 comments on commit 64c5854

Please sign in to comment.