Skip to content

Commit

Permalink
#9 add deleteAccount Api
Browse files Browse the repository at this point in the history
  • Loading branch information
JunseokNoh committed Aug 22, 2021
1 parent acccc87 commit bae13cc
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 36 deletions.
16 changes: 16 additions & 0 deletions KNU_CSE/KNU_CSE.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
681D382626ADC61D000D9FE8 /* BoardWriteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681D382526ADC61D000D9FE8 /* BoardWriteView.swift */; };
686889C626C55F6800486985 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 686889C526C55F6800486985 /* CommentView.swift */; };
686889C826C5977D00486985 /* BoardWithPaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 686889C726C5977D00486985 /* BoardWithPaging.swift */; };
686889CB26D2A2A000486985 /* DeleteAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 686889CA26D2A29F00486985 /* DeleteAccountView.swift */; };
686889CD26D2A2B400486985 /* DeleteAccountViewModel+Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 686889CC26D2A2B400486985 /* DeleteAccountViewModel+Model.swift */; };
68C7629126B96EFA00792498 /* CategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629026B96EFA00792498 /* CategoryCell.swift */; };
68C7629326B99F7F00792498 /* ResponseBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629226B99F7F00792498 /* ResponseBody.swift */; };
68C7629626BC0CAE00792498 /* BaseViewModelChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629526BC0CAE00792498 /* BaseViewModelChange.swift */; };
Expand Down Expand Up @@ -169,6 +171,8 @@
681D382526ADC61D000D9FE8 /* BoardWriteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardWriteView.swift; sourceTree = "<group>"; };
686889C526C55F6800486985 /* CommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentView.swift; sourceTree = "<group>"; };
686889C726C5977D00486985 /* BoardWithPaging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardWithPaging.swift; sourceTree = "<group>"; };
686889CA26D2A29F00486985 /* DeleteAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountView.swift; sourceTree = "<group>"; };
686889CC26D2A2B400486985 /* DeleteAccountViewModel+Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DeleteAccountViewModel+Model.swift"; sourceTree = "<group>"; };
68C7629026B96EFA00792498 /* CategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCell.swift; sourceTree = "<group>"; };
68C7629226B99F7F00792498 /* ResponseBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseBody.swift; sourceTree = "<group>"; };
68C7629526BC0CAE00792498 /* BaseViewModelChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewModelChange.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -291,6 +295,7 @@
children = (
68F861C626B1B18B00934BD2 /* UserInfrom */,
68F861C726B1B19D00934BD2 /* EditPw */,
686889C926D2A28200486985 /* DeleteAccount */,
68F861C826B1B1B800934BD2 /* ReservationList */,
68F861C926B1B1C100934BD2 /* WrittenBoardList */,
68F861CA26B1B1CA00934BD2 /* AppSetting */,
Expand Down Expand Up @@ -434,6 +439,15 @@
path = View;
sourceTree = "<group>";
};
686889C926D2A28200486985 /* DeleteAccount */ = {
isa = PBXGroup;
children = (
686889CA26D2A29F00486985 /* DeleteAccountView.swift */,
686889CC26D2A2B400486985 /* DeleteAccountViewModel+Model.swift */,
);
path = DeleteAccount;
sourceTree = "<group>";
};
68C7629426BC0CA200792498 /* Base */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -997,6 +1011,7 @@
68F861EB26B471D600934BD2 /* UserInformViewModel+Model.swift in Sources */,
68C7629326B99F7F00792498 /* ResponseBody.swift in Sources */,
681D37E526A6AD36000D9FE8 /* ViewProtocol.swift in Sources */,
686889CB26D2A2A000486985 /* DeleteAccountView.swift in Sources */,
681D37C426A45442000D9FE8 /* ClassRoomCell.swift in Sources */,
681D382026ADAE85000D9FE8 /* ReplyViewModel.swift in Sources */,
68F861E326B2EE8A00934BD2 /* FindPwView.swift in Sources */,
Expand Down Expand Up @@ -1029,6 +1044,7 @@
681D37F426A737AE000D9FE8 /* SignInNavigationView.swift in Sources */,
68F1A5EE26A008FF007B4B86 /* BaseObject.swift in Sources */,
681D37B926A42782000D9FE8 /* ClassRoomView.swift in Sources */,
686889CD26D2A2B400486985 /* DeleteAccountViewModel+Model.swift in Sources */,
681D37F926A73F71000D9FE8 /* BoardTitleCollectionCell.swift in Sources */,
68C762A626C40FEC00792498 /* Extension+StackView.swift in Sources */,
68F861DF26B2D31D00934BD2 /* ProfileTableCell.swift in Sources */,
Expand Down
15 changes: 15 additions & 0 deletions KNU_CSE/KNU_CSE/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,21 @@
</objects>
<point key="canvasLocation" x="928" y="2546"/>
</scene>
<!--Delete Account View-->
<scene sceneID="tW4-5L-Qft">
<objects>
<viewController storyboardIdentifier="DeleteAccountView" useStoryboardIdentifierAsRestorationIdentifier="YES" id="QCX-va-Ikl" customClass="DeleteAccountView" customModule="KNU_CSE" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="BEb-e2-KMj">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="sYJ-UB-EUo"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="jbm-a7-bel" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3172" y="2546"/>
</scene>
</scenes>
<resources>
<image name="arrow.up.bin.fill" catalog="system" width="128" height="93"/>
Expand Down
45 changes: 20 additions & 25 deletions KNU_CSE/KNU_CSE/Network Service/Base/BaseApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,26 @@ extension BaseApiRequest{
request.method = .get
case .post:
request.method = .post
if(requestBodyObject != nil){
let jsonEncoder = JSONEncoder()
do {
if let data = try? jsonEncoder.encode(requestBodyObject.self){
let jsonString = String(decoding: data, as: UTF8.self)
request.httpBody = data
print(jsonString)
}
}
}
case .put:
request.method = .put
if(requestBodyObject != nil){
let jsonEncoder = JSONEncoder()
do {
if let data = try? jsonEncoder.encode(requestBodyObject.self){
let jsonString = String(decoding: data, as: UTF8.self)
request.httpBody = data
print(jsonString)
}
}
}
case .delete:
request.method = .delete
default:
request.httpMethod = "GET"
break
}

if(requestBodyObject != nil){
let jsonEncoder = JSONEncoder()
do {
if let data = try? jsonEncoder.encode(requestBodyObject.self){
let jsonString = String(decoding: data, as: UTF8.self)
request.httpBody = data
print(jsonString)
}
}
}

return request
}

Expand All @@ -86,6 +78,8 @@ extension BaseApiRequest{
return getAddress(domain: "user/signIn")
case .SignUp:
return getAddress(domain: "user/signUp")
case .deleteAccount:
return getAddress(domain: "user/deleteMember")
case .codeForPw(let email):
return getAddress(domain: "user/findPassword/\(email)")
case .codeConfirmForPw:
Expand All @@ -100,9 +94,9 @@ extension BaseApiRequest{
return getAddress(domain: "user/profileimage")
case .changePassword:
return getAddress(domain: "user/changePassword")
case .CodeRequest(let email):
return "\(getAddress(domain: "user/verify"))/\(email)"
case .CodeConfirm:
case .codeRequest(let email):
return (getAddress(domain: "user/verify/\(email)"))
case .codeConfirm:
return getAddress(domain: "user/verify")
case .BoardWrite:
return getAddress(domain: "board/write")
Expand Down Expand Up @@ -156,15 +150,16 @@ enum RequestHttpMethod{
enum Environment{
case SignIn
case SignUp
case deleteAccount
case codeForPw(String)
case codeConfirmForPw
case changePasswordForFindPw
case getInform
case setInform
case resetImage
case changePassword
case CodeRequest(String)
case CodeConfirm
case codeRequest(String)
case codeConfirm
case BoardWrite
case getBoardPaging(String,Int,Int)
case getBoard(Int)
Expand Down
196 changes: 196 additions & 0 deletions KNU_CSE/KNU_CSE/View/Main/MyPage/DeleteAccount/DeleteAccountView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
//
// DeleteAccount.swift
// KNU_CSE
//
// Created by junseok on 2021/08/23.
//

import UIKit

class DeleteAccountView:UIViewController,ViewProtocol{

var indicator : IndicatorView!

var deleteAccountViewModel : DeleteAccountViewModel = DeleteAccountViewModel()

let containerView = UIView()
var pwTextField: BindingTextField! {
didSet {
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] password in
self?.deleteAccountViewModel.model.password = password
self?.checkChangeValue()
}
}
}

var pw2TextField: BindingTextField! {
didSet {
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] password2 in
self?.deleteAccountViewModel.model.password2 = password2
self?.checkChangeValue()
}
}
}

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 pw2Title : SignUpUILabel = SignUpUILabel(text: "현재 비밀번호 확인")

override func viewWillAppear(_ animated: Bool) {
self.setNavigationTitle(title:"회원탈퇴")
self.hideBackTitle()
}

override func viewDidLoad() {
super.viewDidLoad()
self.BindingEditPw()

self.initUI()
self.addView()
self.setUpConstraints()
}

func initUI(){
self.pwTextField = BindingTextField()
self.pw2TextField = 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.containerView.addSubview($0)
}
}

func setUpConstraints(){
let title_height:CGFloat = self.view.frame.width * 0.05
let height:CGFloat = self.view.frame.height * 0.05
let top_padding:CGFloat = 15
let title_To_textField_margin:CGFloat = 3
let left_margin:CGFloat = 30
let right_margin:CGFloat = -30

self.containerView.snp.makeConstraints{ make in
make.top.equalTo(self.view.safeAreaLayoutGuide).offset(10)
make.left.right.equalToSuperview()
make.bottom.equalTo(self.view.safeAreaLayoutGuide)
}

// 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.pwTextField.snp.makeConstraints{ make in
make.left.equalTo(left_margin)
make.right.equalTo(right_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(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(self.pw2Title.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(self.pw2TextField.snp.bottom).offset(top_padding)
make.height.equalTo(height)
}
}
}


extension DeleteAccountView: UITextFieldDelegate{

//touch any space then keyboard shut down
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
self.view.endEditing(true)
}

//if keyboard show up and press return button then keyboard shutdown
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}

func checkChangeValue(){
if self.deleteAccountViewModel.PwCheck(){
self.addBtnAction()
}else{
self.removeBtnAction()
}
}

func addBtnAction(){
self.registerBtn.backgroundColor = Color.mainColor
self.registerBtn.addAction{ [weak self] in
Alert(title: "회원탈퇴", message: "정말로 계정을 탈퇴하시겠습니까?", viewController: self!).popUpNormalAlert{ [weak self] _ in
self?.deleteAccountViewModel.deleteAccount()
}
}
}

func removeBtnAction(){
self.registerBtn.backgroundColor = UIColor.lightGray
self.registerBtn.removeTarget(nil, action: nil, for: .allEvents)
}
}

extension DeleteAccountView{
func BindingEditPw(){
self.deleteAccountViewModel.deleteAccountAction.binding(successHandler: { response in
if response.success{
Alert(title: "회원 탈퇴", message: "회원님의 계정이 정상적으로 탈퇴처리 되었습니다.\n이용해주셔서 감사합니다.", viewController: self).popUpDefaultAlert(action:{ action in
self.popTwiceView()
self.logOut()
})
}else{
Alert(title: "회원 탈퇴 실패", message: response.error!.message, viewController: self).popUpDefaultAlert(action:nil)
}
}, failHandler: { Error in
Alert(title: "실패", message: "네트워크 상태를 확인하세요", viewController: self).popUpDefaultAlert(action: nil)
}, asyncHandler: {

}, endHandler: {

})
}
}

Loading

0 comments on commit bae13cc

Please sign in to comment.