Skip to content

Commit

Permalink
#3 Edit EditPwView
Browse files Browse the repository at this point in the history
  • Loading branch information
JunseokNoh committed Aug 5, 2021
1 parent f15ab3d commit 955eb2d
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 39 deletions.
4 changes: 4 additions & 0 deletions KNU_CSE/KNU_CSE.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
68C7629626BC0CAE00792498 /* BaseViewModelChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629526BC0CAE00792498 /* BaseViewModelChange.swift */; };
68C7629826BC0CEB00792498 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629726BC0CEB00792498 /* URL.swift */; };
68C7629A26BC403700792498 /* BaseAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629926BC403700792498 /* BaseAction.swift */; };
68C7629C26BC5A7000792498 /* EditPwViewModel+Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629B26BC5A7000792498 /* EditPwViewModel+Model.swift */; };
68F1A5B826A0088B007B4B86 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68F1A5B726A0088B007B4B86 /* AppDelegate.swift */; };
68F1A5BA26A0088B007B4B86 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68F1A5B926A0088B007B4B86 /* SceneDelegate.swift */; };
68F1A5BC26A0088B007B4B86 /* SignInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68F1A5BB26A0088B007B4B86 /* SignInView.swift */; };
Expand Down Expand Up @@ -166,6 +167,7 @@
68C7629526BC0CAE00792498 /* BaseViewModelChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewModelChange.swift; sourceTree = "<group>"; };
68C7629726BC0CEB00792498 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
68C7629926BC403700792498 /* BaseAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseAction.swift; sourceTree = "<group>"; };
68C7629B26BC5A7000792498 /* EditPwViewModel+Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EditPwViewModel+Model.swift"; sourceTree = "<group>"; };
68F1A5B426A0088B007B4B86 /* KNU_CSE.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KNU_CSE.app; sourceTree = BUILT_PRODUCTS_DIR; };
68F1A5B726A0088B007B4B86 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
68F1A5B926A0088B007B4B86 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -606,6 +608,7 @@
isa = PBXGroup;
children = (
68F861CE26B1B34E00934BD2 /* EditPwView.swift */,
68C7629B26BC5A7000792498 /* EditPwViewModel+Model.swift */,
);
path = EditPw;
sourceTree = "<group>";
Expand Down Expand Up @@ -971,6 +974,7 @@
681D381126AAA908000D9FE8 /* ReplyCell.swift in Sources */,
681D37B526A419F3000D9FE8 /* MyPageView.swift in Sources */,
68F861D326B1B36400934BD2 /* WrittenBoardListView.swift in Sources */,
68C7629C26BC5A7000792498 /* EditPwViewModel+Model.swift in Sources */,
681D380926A9C5BE000D9FE8 /* BoardDetailModel.swift in Sources */,
68C7629826BC0CEB00792498 /* URL.swift in Sources */,
681D37DB26A4AAAC000D9FE8 /* ReservationViewModel.swift in Sources */,
Expand Down
105 changes: 66 additions & 39 deletions KNU_CSE/KNU_CSE/Main Tab/MyPage/EditPw/EditPwView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,65 @@ class EditPwView:UIViewController,ViewProtocol{

var indicator : IndicatorView!

var findPwViewModel : FindPwViewModel = FindPwViewModel(listener: nil)
var editPwViewModel : EditPwViewModel = EditPwViewModel(listener: nil)

let containerView = UIView()

var pwTextField: BindingTextField! {
didSet {
pwTextField.isSecureTextEntry = true
pwTextField.delegate = self
pwTextField.textContentType = .password
pwTextField.draw()
pwTextField.setUpImage(imageName: "eye.fill", on: .right, color: UIColor.darkGray, width:40, height: 40)
pwTextField.bind { [weak self] pw in
self?.findPwViewModel.account.password = pw
self.pwTextField.isSecureTextEntry = true
self.pwTextField.delegate = self
self.pwTextField.textContentType = .password
self.pwTextField.draw()
self.pwTextField.setUpImage(imageName: "eye.fill", on: .right, color: UIColor.darkGray, width:40, height: 40)
self.pwTextField.bind { [weak self] changePassword in
self?.editPwViewModel.account.changePassword = changePassword
self?.checkChangeValue()
}
}
}

var pw2TextField: BindingTextField! {
didSet {
pw2TextField.isSecureTextEntry = true
pw2TextField.delegate = self
pw2TextField.textContentType = .password
pw2TextField.draw()
pw2TextField.setUpImage(imageName: "eye.fill", on: .right, color: UIColor.darkGray, width:40, height: 40)
pw2TextField.bind { [weak self] pw2 in
self?.findPwViewModel.account.password2 = pw2
self.pw2TextField.isSecureTextEntry = true
self.pw2TextField.delegate = self
self.pw2TextField.textContentType = .password
self.pw2TextField.draw()
self.pw2TextField.setUpImage(imageName: "eye.fill", on: .right, color: UIColor.darkGray, width:40, height: 40)
self.pw2TextField.bind { [weak self] changePassword2 in
self?.editPwViewModel.account.changePassword2 = changePassword2
self?.checkChangeValue()
}
}
}

var registerBtn : UIButton! {
didSet{
registerBtn.backgroundColor = UIColor.lightGray
registerBtn.setTitle("비밀번호 변경", for: .normal)
registerBtn.setTitleColor(UIColor.init(white: 1, alpha: 0.3), for: .highlighted)
registerBtn.layer.cornerRadius = 5
var currentPwTextField: BindingTextField! {
didSet {
self.currentPwTextField.isSecureTextEntry = true
self.currentPwTextField.delegate = self
self.currentPwTextField.textContentType = .password
self.currentPwTextField.draw()
self.currentPwTextField.setUpImage(imageName: "eye.fill", on: .right, color: UIColor.darkGray, width:40, height: 40)
self.currentPwTextField.bind { [weak self] currentPassword in
self?.editPwViewModel.account.currentPassword = currentPassword
self?.checkChangeValue()
}
}
}

var pwTitle : SignUpUILabel!{
didSet{

}
}
var pw2Title : SignUpUILabel!{
var registerBtn : UIButton! {
didSet{

self.registerBtn.backgroundColor = UIColor.lightGray
self.registerBtn.setTitle("비밀번호 변경", for: .normal)
self.registerBtn.setTitleColor(UIColor.init(white: 1, alpha: 0.3), for: .highlighted)
self.registerBtn.layer.cornerRadius = 5
}
}

let pwTitle : SignUpUILabel = SignUpUILabel(text: "새 비밀번호")
let pwCautionTitle : SignUpUILabel = SignUpUILabel(text: "영어,숫자를 조합한 8~20자",alignment: .right, color: UIColor.lightGray)
let pw2Title : SignUpUILabel = SignUpUILabel(text: "새 비밀번호 확인")
let currrentPwTitle : SignUpUILabel = SignUpUILabel(text: "현재 비밀번호")

override func viewWillAppear(_ animated: Bool) {
self.setNavigationTitle(title:"비밀번호 변경")
Expand All @@ -78,19 +85,17 @@ class EditPwView:UIViewController,ViewProtocol{
}

func initUI(){
self.pwTitle = SignUpUILabel(text: "비밀번호")
self.pw2Title = SignUpUILabel(text: "비밀번호 재확인")

self.pwTextField = BindingTextField()
self.pw2TextField = BindingTextField()
self.currentPwTextField = BindingTextField()

self.registerBtn = UIButton()
self.indicator = IndicatorView(viewController: self)
}

func addView(){
self.view.addSubview(containerView)
_ = [self.pwTextField,self.pw2TextField,self.pwTitle,self.pw2Title,self.registerBtn].map{
_ = [self.pwTextField,self.pw2TextField,self.pwTitle,self.pwCautionTitle,self.pw2Title,self.currentPwTextField,self.currrentPwTitle,self.registerBtn].map{
self.containerView.addSubview($0)
}
}
Expand All @@ -112,38 +117,60 @@ class EditPwView:UIViewController,ViewProtocol{
// MARK: - 비밀번호
self.pwTitle.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.width.equalTo(100)
make.top.equalTo(self.containerView.snp.top).offset(top_padding+10)
make.height.equalTo(title_height)
}

self.pwCautionTitle.snp.makeConstraints{ make in
make.left.equalTo(self.pwTitle.snp.right)
make.right.equalTo(right_margin)
make.top.equalTo(containerView.snp.top).offset(top_padding+10)
make.top.equalTo(self.containerView.snp.top).offset(top_padding+10)
make.height.equalTo(title_height)
}

self.pwTextField.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.right.equalTo(right_margin)
make.top.equalTo(pwTitle.snp.bottom).offset(title_To_textField_margin)
make.top.equalTo(self.pwTitle.snp.bottom).offset(title_To_textField_margin)
make.height.equalTo(height)
}

// MARK: - 비밀번호 확인
self.pw2Title.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.right.equalTo(right_margin)
make.top.equalTo(pwTextField.snp.bottom).offset(top_padding)
make.top.equalTo(self.pwTextField.snp.bottom).offset(top_padding)
make.height.equalTo(title_height)
}

self.pw2TextField.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.right.equalTo(right_margin)
make.top.equalTo(pw2Title.snp.bottom).offset(title_To_textField_margin)
make.top.equalTo(self.pw2Title.snp.bottom).offset(title_To_textField_margin)
make.height.equalTo(height)
}

// MARK: - 현재 비밀번호
self.currrentPwTitle.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.right.equalTo(right_margin)
make.top.equalTo(self.pw2TextField.snp.bottom).offset(top_padding*2)
make.height.equalTo(title_height)
}

self.currentPwTextField.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.right.equalTo(right_margin)
make.top.equalTo(self.currrentPwTitle.snp.bottom).offset(title_To_textField_margin)
make.height.equalTo(height)
}

// MARK: - 회원가입 버튼
self.registerBtn.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.right.equalTo(right_margin)
make.top.equalTo(pw2TextField.snp.bottom).offset(top_padding*2)
make.top.equalTo(self.currentPwTextField.snp.bottom).offset(top_padding)
make.height.equalTo(height)
}
}
Expand All @@ -164,7 +191,7 @@ extension EditPwView: UITextFieldDelegate{
}

func checkChangeValue(){
if self.findPwViewModel.SignUpCheck(){
if self.editPwViewModel.SignUpCheck(){
self.addBtnAction()
}else{
self.removeBtnAction()
Expand Down
54 changes: 54 additions & 0 deletions KNU_CSE/KNU_CSE/Main Tab/MyPage/EditPw/EditPwViewModel+Model.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// EditPwViewModel.swift
// KNU_CSE
//
// Created by junseok on 2021/08/06.
//

import Foundation

class EditPwViewModel {
typealias Listener = (EditPwModel) -> Void
var listener: Listener?
var account: EditPwModel = EditPwModel(email: "", changePassword: "", changePassword2: "", currentPassword:"")
var emailCode:String!

init(listener : Listener?){
self.listener = listener
}

func bind(listener: Listener?) {
self.listener = listener
}

func SignUpCheck()-> Bool{
return account.Check()
}
}

class EditPwModel: BaseObject{
var email:String
var changePassword:String
var changePassword2:String
var currentPassword:String

init(email : String, changePassword : String, changePassword2 : String, currentPassword : String){
self.email = email
self.changePassword = changePassword
self.changePassword2 = changePassword2
self.currentPassword = currentPassword
super.init()
}

required init(from decoder: Decoder) throws {
fatalError("init(from:) has not been implemented")
}

func Check() -> Bool{
if self.changePassword != "" && self.changePassword2 != "" && self.currentPassword != "" && self.changePassword == self.changePassword2{
return true
}else{
return false
}
}
}

0 comments on commit 955eb2d

Please sign in to comment.