Skip to content

Commit

Permalink
Merge pull request #52 from geteduroam/feature/51-automatically-add-r…
Browse files Browse the repository at this point in the history
…ealmrequired-suffix-to-username

Automatically add realm/required suffix to username
  • Loading branch information
johankool authored Aug 31, 2023
2 parents 966109c + 8213024 commit 2d0c909
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import SwiftUI

public struct CredentialAlert {
public init(title: String, isPresented: Binding<Bool>, usernamePrompt: String, username: Binding<String>, passwordPrompt: String, password: Binding<String>, cancelButtonTitle: String, cancelAction: @escaping () -> (), doneButtonTitle: String, doneAction: @escaping () -> (), message: String) {
public init(title: String, isPresented: Binding<Bool>, usernamePrompt: String, username: Binding<String>, onUsernameSubmit: @escaping () -> (), passwordPrompt: String, password: Binding<String>, cancelButtonTitle: String, cancelAction: @escaping () -> (), doneButtonTitle: String, doneAction: @escaping () -> (), message: String) {
self.title = title
self.isPresented = isPresented
self.usernamePrompt = usernamePrompt
self.username = username
self.onUsernameSubmit = onUsernameSubmit
self.passwordPrompt = passwordPrompt
self.password = password
self.cancelButtonTitle = cancelButtonTitle
Expand All @@ -21,6 +22,7 @@ public struct CredentialAlert {
let isPresented: Binding<Bool>
let usernamePrompt: String
let username: Binding<String>
let onUsernameSubmit: () -> ()
let passwordPrompt: String
let password: Binding<String>
let cancelButtonTitle: String
Expand Down Expand Up @@ -77,6 +79,7 @@ public extension Backport where Content: View {
actions: {
TextField(alert.usernamePrompt, text: alert.username)
.textContentType(.username)
.onSubmit(alert.onUsernameSubmit)
SecureField(alert.passwordPrompt, text: alert.password)
.textContentType(.password)
Button(alert.cancelButtonTitle, role: .cancel, action: alert.cancelAction)
Expand Down
13 changes: 13 additions & 0 deletions geteduroam/GeteduroamPackage/Sources/Connect/ConnectFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public struct Connect: Reducer {
}
}

public mutating func appendRequiredUserNameSuffix() {
guard let requiredUserNameSuffix, let username = credentials?.username, !username.isEmpty, !username.contains("@") else {
return
}
credentials?.username = username + "@" + requiredUserNameSuffix
}

public var password: String {
credentials?.password ?? ""
}
Expand Down Expand Up @@ -172,6 +179,7 @@ public struct Connect: Reducer {
case foundSSID(String)
case logInButtonTapped
case onAppear
case onUsernameSubmit
case select(Profile.ID)
case startAgainTapped
case updatePassword(String)
Expand Down Expand Up @@ -450,7 +458,12 @@ public struct Connect: Reducer {
}
return .none

case .onUsernameSubmit:
state.appendRequiredUserNameSuffix()
return .none

case let .updatePassword(password):
state.appendRequiredUserNameSuffix()
let trimmedPassword = password.trimmingCharacters(in: .whitespacesAndNewlines)
if let _ = state.credentials {
state.credentials?.password = trimmedPassword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public struct ConnectView_iOS: View {
.binding(
get: \.username,
send: Connect.Action.updateUsername),
onUsernameSubmit: {
viewStore.send(.onUsernameSubmit)
},
passwordPrompt: NSLocalizedString("Password", bundle: .module, comment: ""),
password: viewStore
.binding(
Expand Down

0 comments on commit 2d0c909

Please sign in to comment.