Skip to content

Commit

Permalink
Further adjustments for swiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfej94 committed Feb 18, 2022
1 parent eb61682 commit 8c55cec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion PassportKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "PassportKit"
spec.version = "1.7.1"
spec.version = "1.7.2"
spec.license = "MIT"
spec.summary = "Swift library used for quick and easy oauth authentication."
spec.homepage = "https://github.com/appoly/PassportKit"
Expand Down
8 changes: 4 additions & 4 deletions Sources/Network/PassportAuthAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ enum PassportAuthAPI {
case .login(let configuration, let model):
switch configuration.mode {
case .sanctum:
let username = model.email!.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let password = model.password!.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let username = model.email.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let password = model.password.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
return "username=\(username)&password=\(password)"
.data(using: .utf8)
case .standard(let clientID, let clientSecret):
let username = model.email!.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let password = model.password!.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let username = model.email.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let password = model.password.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let clientID = clientID.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
let clientSecret = clientSecret.addingPercentEncoding(withAllowedCharacters: Self.allowedCharacters) ?? ""
return "username=\(username)&password=\(password)&client_id=\(clientID)&client_secret=\(clientSecret)&grant_type=password"
Expand Down
10 changes: 8 additions & 2 deletions Sources/PassportKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import Foundation
import LocalAuthentication
import SwiftUI



Expand Down Expand Up @@ -59,11 +60,16 @@ public class PassportKit: NSObject, ObservableObject {
public func setup(_ configuration: PassportConfiguration) {
self.configuration = configuration
self.authManager = PassportKitAuthenticationManager(configuration.keychainID)
self.isAuthenticated = self.authManager.isAuthenticated
NotificationCenter.default.addObserver(forName: .passportKitAuthenticationStateChanged, object: nil, queue: .main) { [weak self] _ in
withAnimation { [weak self] in
guard let self = self else { return }
self.isAuthenticated = self.authManager.isAuthenticated
}
NotificationCenter.default.addObserver(forName: .passportKitAuthenticationStateChanged, object: nil, queue: .main) { _ in
withAnimation { [weak self] in
guard let self = self else { return }
self.isAuthenticated = self.authManager.isAuthenticated
}
}
}


Expand Down
25 changes: 8 additions & 17 deletions Sources/PassportViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

import Foundation
import UIKit
import SwiftUI



public class PassportViewModel: NSObject {
open class PassportViewModel: NSObject, ObservableObject {

// MARK: - Variables

private(set) var email: String?
private(set) var password: String?
@Published public var email: String = ""
@Published public var password: String = ""
private let passwordRegex: String?
private let authController = PassportKitAuthService()

Expand All @@ -37,22 +38,12 @@ public class PassportViewModel: NSObject {
// MARK: - Setters

@objc public func setPassword(_ sender: UITextField) {
password = sender.text
password = sender.text ?? ""
}


@objc public func setEmail(_ sender: UITextField) {
email = sender.text
}


public func setPassword(string: String) {
password = string
}


public func setEmail(string: String) {
email = string
email = sender.text ?? ""
}


Expand All @@ -61,8 +52,8 @@ public class PassportViewModel: NSObject {

public func validateForLogin(completion: @escaping PassportKitValidationResponse) {

let email = self.email ?? ""
let password = self.password ?? ""
let email = self.email
let password = self.password

guard !email.isEmpty else {
DispatchQueue.main.async { completion(PassportKitValidationError.missingEmail) }
Expand Down

0 comments on commit 8c55cec

Please sign in to comment.