Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add realm/required suffix to username #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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