Skip to content

Commit

Permalink
➕[ADD] AuthManager 생성(#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
heerucan committed Nov 12, 2021
1 parent d0f841c commit fa6e4b2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import SnapKit
import Then

class CompleteVC: UIViewController {

// MARK: - Properties

var name: String?

private let logoImageView = UIImageView().then {
Expand All @@ -40,6 +42,7 @@ class CompleteVC: UIViewController {
}

// MARK: - Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
configUI()
Expand All @@ -48,6 +51,7 @@ class CompleteVC: UIViewController {
}

// MARK: - Custom Method

private func configUI() {
view.backgroundColor = .white
navigationController?.navigationBar.isHidden = true
Expand Down Expand Up @@ -88,6 +92,7 @@ class CompleteVC: UIViewController {
}

// MARK: - @objc

@objc func touchupCompleteButton(_ sender: UIButton) {
let mainVC = MainTabVC()
mainVC.modalPresentationStyle = .fullScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import SnapKit
import Then

class LoginVC: UIViewController {

// MARK: - Properties

fileprivate var currentNonce: String?

private let logoImageView = UIImageView().then {
Expand Down Expand Up @@ -71,6 +73,7 @@ class LoginVC: UIViewController {
}

// MARK: - Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
configUI()
Expand All @@ -80,6 +83,7 @@ class LoginVC: UIViewController {
}

// MARK: - Custom Method

private func configUI() {
view.backgroundColor = .white
}
Expand Down Expand Up @@ -144,6 +148,7 @@ class LoginVC: UIViewController {
}

// MARK: - Apple 로그인

@objc func touchUpAppleButton(_ sender: UIButton) {
let request = createAppleIDRequest()
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
Expand Down Expand Up @@ -190,6 +195,7 @@ class LoginVC: UIViewController {
}

// MARK: - @objc

@objc func textFieldDidChange(textField: UITextField){
guard let name = nameTextField.text,
let email = emailTextField.text,
Expand Down Expand Up @@ -241,6 +247,7 @@ class LoginVC: UIViewController {
}

// MARK: - UITextFieldDelegate

extension LoginVC: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
switch textField {
Expand All @@ -254,6 +261,7 @@ extension LoginVC: UITextFieldDelegate {
}

// MARK: - ASAuthorizationControllerDelegate

@available(iOS 13.0, *)
extension LoginVC: ASAuthorizationControllerDelegate {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
Expand Down Expand Up @@ -310,6 +318,7 @@ extension LoginVC: ASAuthorizationControllerDelegate {
}

// MARK: - ASAuthorizationControllerPresentationContextProviding

@available(iOS 13.0, *)
extension LoginVC: ASAuthorizationControllerPresentationContextProviding {
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import SnapKit
import Then

class SignUpVC: UIViewController {

// MARK: - Properties

private let logoImageView = UIImageView().then {
$0.image = Const.Image.logo
$0.contentMode = .scaleAspectFit
Expand Down Expand Up @@ -66,6 +68,7 @@ class SignUpVC: UIViewController {
}

// MARK: - Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
configUI()
Expand All @@ -75,6 +78,7 @@ class SignUpVC: UIViewController {
}

// MARK: - Custom Method

private func configUI() {
view.backgroundColor = .white
}
Expand Down Expand Up @@ -126,6 +130,7 @@ class SignUpVC: UIViewController {
}

// MARK: - @objc

@objc func textFieldDidChange(textField: UITextField){
guard let name = nameTextField.text,
let email = emailTextField.text,
Expand Down Expand Up @@ -187,6 +192,7 @@ class SignUpVC: UIViewController {
}

// MARK: - UITextFieldDelegate

extension SignUpVC: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
switch textField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,54 @@
import Foundation

import Moya

class AuthManager {

// MARK: - Static Properties

static let shared: AuthManager = AuthManager()

// MARK: - Network Properties

private let authProvider = MoyaProvider<AuthService>(plugins: [NetworkLoggerPlugin()])
private var authModel: AuthModel?

// MARK: - POST : Login

func fetchLogin(email: String, password: String, completion: @escaping (() -> ())) {
let param = LoginRequest.init(email, password)
authProvider.request(.login(param: param)) { result in
switch result {
case .success(let result):
do {
self.authModel = try result.map(AuthModel.self)
completion()
} catch(let err) {
print(err.localizedDescription)
}
case .failure(let err):
print(err.localizedDescription)
}
}
}


// MARK: - POST : SignUp

func fetchSignUp(email: String, name: String, password: String, completion: @escaping (() -> ())) {
let param = SignUpRequest.init(email, name, password)
authProvider.request(.signUp(param: param)) { result in
switch result {
case .success(let result):
do {
self.authModel = try result.map(AuthModel.self)
completion()
} catch(let err) {
print(err.localizedDescription)
}
case .failure(let err):
print(err.localizedDescription)
}
}
}
}

0 comments on commit fa6e4b2

Please sign in to comment.