-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #57 - 비밀번호 변경 뷰 구현
- Loading branch information
Showing
16 changed files
with
438 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
SOPT-Stamp-iOS/Projects/Data/Sources/Transform/PasswordSettingTransform.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// PasswordSettingTransform.swift | ||
// Data | ||
// | ||
// Created by sejin on 2022/12/26. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
import Network | ||
|
||
extension PasswordChangeEntity { | ||
|
||
public func toDomain() -> PasswordChangeModel { | ||
return PasswordChangeModel.init() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SOPT-Stamp-iOS/Projects/Domain/Sources/Model/PasswordChangeModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// PasswordChangeModel.swift | ||
// Domain | ||
// | ||
// Created by sejin on 2022/12/26. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct PasswordChangeModel { | ||
|
||
public init() { | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...p-iOS/Projects/Domain/Sources/RepositoryInterface/PasswordChangeRepositoryInterface.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// PasswordChangeRepositoryInterface.swift | ||
// Domain | ||
// | ||
// Created by sejin on 2022/12/26. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
public protocol PasswordChangeRepositoryInterface { | ||
func changePassword(password: String) -> AnyPublisher<Bool, Error> | ||
} |
86 changes: 86 additions & 0 deletions
86
SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/PasswordChangeUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// PasswordChangeUseCase.swift | ||
// Domain | ||
// | ||
// Created by sejin on 2022/12/26. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
import Core | ||
|
||
public protocol PasswordChangeUseCase { | ||
func checkPassword(password: String) | ||
func checkAccordPassword(firstPassword: String, secondPassword: String) | ||
func changePassword(password: String) | ||
|
||
var isPasswordFormValid: CurrentValueSubject<Bool, Error> { get set } | ||
var isAccordPassword: CurrentValueSubject<Bool, Error> { get set } | ||
var isValidForm: CurrentValueSubject<Bool, Error> { get set } | ||
var passwordChangeSuccess: CurrentValueSubject<Bool, Error> { get set } | ||
} | ||
|
||
public class DefaultPasswordChangeUseCase { | ||
|
||
private let repository: PasswordChangeRepositoryInterface | ||
private var cancelBag = CancelBag() | ||
|
||
public var isPasswordFormValid = CurrentValueSubject<Bool, Error>(false) | ||
public var isAccordPassword = CurrentValueSubject<Bool, Error>(false) | ||
public var isValidForm = CurrentValueSubject<Bool, Error>(false) | ||
public var passwordChangeSuccess = CurrentValueSubject<Bool, Error>(false) | ||
|
||
public init(repository: PasswordChangeRepositoryInterface) { | ||
self.repository = repository | ||
self.bindFormValid() | ||
} | ||
} | ||
|
||
extension DefaultPasswordChangeUseCase: PasswordChangeUseCase { | ||
public func checkPassword(password: String) { | ||
checkPasswordForm(password: password) | ||
} | ||
|
||
public func checkAccordPassword(firstPassword: String, secondPassword: String) { | ||
checkAccordPasswordForm(firstPassword: firstPassword, secondPassword: secondPassword) | ||
} | ||
|
||
public func changePassword(password: String) { | ||
repository.changePassword(password: password) | ||
.sink { event in | ||
print("PasswordChangeUseCase: \(event)") | ||
} receiveValue: { isSuccess in | ||
self.passwordChangeSuccess.send(isSuccess) | ||
}.store(in: cancelBag) | ||
} | ||
} | ||
|
||
// MARK: - Methods | ||
|
||
extension DefaultPasswordChangeUseCase { | ||
func bindFormValid() { | ||
isPasswordFormValid.combineLatest(isAccordPassword) | ||
.map { (isPasswordValid, isAccordPassword) in | ||
(isPasswordValid && isAccordPassword) | ||
} | ||
.sink { event in | ||
print("PasswordChangeUseCase - completion: \(event)") | ||
} receiveValue: { isValid in | ||
self.isValidForm.send(isValid) | ||
}.store(in: cancelBag) | ||
} | ||
|
||
func checkPasswordForm(password: String) { | ||
let passwordRegEx = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+=-]).{8,15}" // 8자리 ~ 15자리 영어+숫자+특수문자 | ||
let passwordTest = NSPredicate(format: "SELF MATCHES %@", passwordRegEx) | ||
let isValid = passwordTest.evaluate(with: password) | ||
isPasswordFormValid.send(isValid) | ||
} | ||
|
||
func checkAccordPasswordForm(firstPassword: String, secondPassword: String) { | ||
let isValid = (firstPassword == secondPassword) | ||
isAccordPassword.send(isValid) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
SOPT-Stamp-iOS/Projects/Modules/Network/Sources/Entity/PasswordChangeEntity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// PasswordChangeEntity.swift | ||
// Network | ||
// | ||
// Created by sejin on 2022/12/26. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct PasswordChangeEntity { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.