Skip to content

Commit

Permalink
[#73] 로그아웃 구현중
Browse files Browse the repository at this point in the history
  • Loading branch information
00yhsp committed Feb 15, 2024
1 parent d60725a commit 5f3a49f
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 180 deletions.
10 changes: 9 additions & 1 deletion Spon-us.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
DF498F272B79B45D00ADE078 /* KeyChainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F262B79B45D00ADE078 /* KeyChainManager.swift */; };
DF498F2A2B7CDDA200ADE078 /* MyAnnouncementsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F292B7CDDA200ADE078 /* MyAnnouncementsModel.swift */; };
DF498F2C2B7CDDB200ADE078 /* MyAnnouncementsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2B2B7CDDB200ADE078 /* MyAnnouncementsViewModel.swift */; };
DF498F2E2B7DF4F600ADE078 /* LogoutModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */; };
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */; };
DF90A5AB2B64EB5500BC54D0 /* TermsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF90A5AA2B64EB5500BC54D0 /* TermsView.swift */; };
DF90A5AD2B664E5A00BC54D0 /* ProcessingPolicyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF90A5AC2B664E5A00BC54D0 /* ProcessingPolicyView.swift */; };
DF90A5B02B664E9600BC54D0 /* GatherAndUsageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF90A5AF2B664E9600BC54D0 /* GatherAndUsageView.swift */; };
Expand Down Expand Up @@ -204,6 +206,8 @@
DF498F262B79B45D00ADE078 /* KeyChainManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyChainManager.swift; sourceTree = "<group>"; };
DF498F292B7CDDA200ADE078 /* MyAnnouncementsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyAnnouncementsModel.swift; sourceTree = "<group>"; };
DF498F2B2B7CDDB200ADE078 /* MyAnnouncementsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyAnnouncementsViewModel.swift; sourceTree = "<group>"; };
DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutModel.swift; sourceTree = "<group>"; };
DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutViewModel.swift; sourceTree = "<group>"; };
DF90A5AA2B64EB5500BC54D0 /* TermsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TermsView.swift; sourceTree = "<group>"; };
DF90A5AC2B664E5A00BC54D0 /* ProcessingPolicyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcessingPolicyView.swift; sourceTree = "<group>"; };
DF90A5AF2B664E9600BC54D0 /* GatherAndUsageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GatherAndUsageView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -291,10 +295,10 @@
100A1E352B7348DB00AAC1E8 /* Model */ = {
isa = PBXGroup;
children = (
100A1E362B734DA500AAC1E8 /* Onboarding */,
DF498F282B7CDD8200ADE078 /* Portfolio */,
806AF8712B7B84F2008F7F62 /* Announcement */,
806AF8682B79D985008F7F62 /* Category */,
100A1E362B734DA500AAC1E8 /* Onboarding */,
10025B422B7C139300DCCC5A /* ReceivedOffer */,
10025B352B7B7B8700DCCC5A /* SendOffer */,
107D6E672B7A821D005B6261 /* MyPage */,
Expand All @@ -311,6 +315,8 @@
DFB22ED82B767003007903DF /* JoinViewModel.swift */,
DF498F222B791EA800ADE078 /* LoginModel.swift */,
DF498F242B791EB400ADE078 /* LoginViewModel.swift */,
DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */,
DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */,
);
path = Onboarding;
sourceTree = "<group>";
Expand Down Expand Up @@ -723,6 +729,7 @@
10EBD8112B6FD6D60082CD8E /* ProfileEditView.swift in Sources */,
3B81BCB62B622EEA0067E9CB /* Extension.swift in Sources */,
107D6E692B7A8273005B6261 /* OrganizationModel.swift in Sources */,
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */,
100D38B32B4EF15600498977 /* HomeView.swift in Sources */,
10C8AC632B5C34C400B40547 /* CompanyPostView.swift in Sources */,
DF3AD3DF2B61626300DBFCCC /* OnBoardingView.swift in Sources */,
Expand All @@ -739,6 +746,7 @@
DF498F2A2B7CDDA200ADE078 /* MyAnnouncementsModel.swift in Sources */,
DF90A5B02B664E9600BC54D0 /* GatherAndUsageView.swift in Sources */,
806AF8732B7B8504008F7F62 /* AnnouncementViewModel.swift in Sources */,
DF498F2E2B7DF4F600ADE078 /* LogoutModel.swift in Sources */,
10EBD80D2B6F783F0082CD8E /* HonorInfoEditView.swift in Sources */,
100A1E3A2B734DDE00AAC1E8 /* EmailViewModel.swift in Sources */,
1031EC7C2B68B9F20016655B /* AnnouncementView.swift in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions Spon-us/Model/Onboarding/LogoutModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// LogoutModel.swift
// Spon-us
//
// Created by 박현수 on 2/15/24.
//

import Foundation

struct LogoutModel200: Codable {
let statusCode, message, content: String
}

struct LogoutModel400: Codable {
let statusCode, message: String
}
47 changes: 47 additions & 0 deletions Spon-us/Model/Onboarding/LogoutViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// LogoutViewModel.swift
// Spon-us
//
// Created by 박현수 on 2/15/24.
//

import Foundation
import Moya

class LogoutViewModel: ObservableObject {
@Published var logoutModel200: LogoutModel200?
@Published var logoutModel400: LogoutModel400?
let provider = MoyaProvider<SponusAPI>(plugins: [NetworkLoggerPlugin()])

func getLogout(completion: @escaping (Bool) -> Void) {
provider.request(.getLogout) { result in
switch result {
case let .success(response):
switch response.statusCode {
case 200:
do {
let logoutResponse = try response.map(LogoutModel200.self)
self.logoutModel200 = logoutResponse
completion(true)
}
catch {
print("200Error")
}
case 400:
do {
let logoutResponse = try response.map(LogoutModel400.self)
self.logoutModel400 = logoutResponse
completion(false)
}
catch {
print("400Error")
}
default:
print("Unexpected StatusCode")
}
case let .failure(response):
print("response error")
}
}
}
}
12 changes: 12 additions & 0 deletions Spon-us/SponusAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum SponusAPI {
case getAnnouncement(announcementId: Int)
case propose(title: String, content: String, announcementId: Int, attachments: [URL])
case postLogin(email: String, password: String, fcmToken: String)
case getLogout
case getMe
case getSent
case getProposalDetail(proposeId: Int)
Expand Down Expand Up @@ -47,6 +48,8 @@ extension SponusAPI: TargetType {
return "/api/v1/proposes"
case .postLogin:
return "/api/v1/organizations/login"
case .getLogout:
return "/api/v1/organizations/logout"
case .getMe:
return "/api/v1/organizations/me"
case .getSent:
Expand All @@ -59,6 +62,7 @@ extension SponusAPI: TargetType {
return "/api/v1/proposes/received"
case .getMyAnnouncements:
return "/api/v1/announcements/me/opened"

}
}

Expand All @@ -78,6 +82,8 @@ extension SponusAPI: TargetType {
return .post
case .postLogin:
return .post
case .getLogout:
return .get
case .getMe:
return .get
case .getSent:
Expand Down Expand Up @@ -140,6 +146,8 @@ extension SponusAPI: TargetType {
]
]
return try! JSONSerialization.data(withJSONObject: response, options: .prettyPrinted)
case .getLogout:
return Data()
case .getMe:
return Data()
case .getSent:
Expand Down Expand Up @@ -230,6 +238,8 @@ extension SponusAPI: TargetType {
case .postLogin(let email, let password, let fcmToken):
let requestBody = LoginRequestBody(email: email, password: password, fcmToken: fcmToken)
return .requestJSONEncodable(requestBody)
case .getLogout:
return .requestPlain
case .getMe:
return .requestPlain
case .getSent:
Expand All @@ -254,6 +264,8 @@ extension SponusAPI: TargetType {
return nil
case .postLogin:
return nil
case .getLogout:
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
case .getMe:
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
case .getSent:
Expand Down
3 changes: 2 additions & 1 deletion Spon-us/View/Category/CategoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ struct CategoryCell: View {
Spacer()
}
}.frame(width: 160, height: 95).padding(.trailing, 36)
Button(action: {toggleBookmark()}){
Button(action: {toggleBookmark()
print(categoryContent.id)}){
Image(isBookmarked ? "ic_saved_check" : "ic_saved")
.frame(width: 28, height: 28)
}
Expand Down
4 changes: 2 additions & 2 deletions Spon-us/View/Onboarding/RegisterPWView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct RegisterPWView: View {
@FocusState var PWConfirmSecureFieldFocused: Bool
@FocusState var PWConfirmTextFieldFocused: Bool

let PWRegex = /^(?=.*[a-z])(?=.*\d).{8,20}$/
let PWRegex = /^(?=.*[a-z])(?=.*\d).{10,20}$/

var body: some View {
@State var isValidPW = (userPW == userPWConfirm) && (userPW.wholeMatch(of: PWRegex)?.output != nil)
Expand Down Expand Up @@ -73,7 +73,7 @@ struct RegisterPWView: View {
}.padding(.trailing, 16)
}.border((PWTextFieldFocused || PWSecureFieldFocused) ? .sponusPrimary : .sponusGrey100).padding(.top, 16).padding(.top, 32)
HStack(spacing: 0) {
Text("*영문, 숫자 포함 8-20자 이내").font(.system(size: 12)).foregroundStyle(.sponusGrey900)
Text("*영문, 숫자 포함 10-20자 이내").font(.system(size: 12)).foregroundStyle(.sponusGrey900)
Spacer()
}.padding(.top, 12)
HStack(spacing: 0) {
Expand Down
Loading

0 comments on commit 5f3a49f

Please sign in to comment.