diff --git a/enzevalos_iphone/AuthenticationScreen.swift b/enzevalos_iphone/AuthenticationScreen.swift index d986d163db441c4e3a26fa16258a9b924d2f3c40..3ba5aee4cc42a261e52e4c42085e25ceccb7e613 100644 --- a/enzevalos_iphone/AuthenticationScreen.swift +++ b/enzevalos_iphone/AuthenticationScreen.swift @@ -18,81 +18,83 @@ struct AuthenticationScreen: View { @State private var smtpPort: String = "" @State private var imapEncryption = 0 @State private var smtpEncryption = 0 - + @ObservedObject private var viewModel = AuthenticationViewModel() var encryptionOptions = ["Plaintext", "StartTLS", "TLS/SSL"] var body: some View { - ZStack { - Color.white.edgesIgnoringSafeArea(.all) - - VStack { - Text("Please enter Your credentials").padding().foregroundColor(Color.yellow) - Text("Login") - TextField("Please enter your login", text: $login).textFieldStyle(RoundedBorderTextFieldStyle()) - Text("Password") - SecureField("Please enter your password", text: $password).textFieldStyle(RoundedBorderTextFieldStyle()) + ScrollView{ + ZStack { + Color.white.edgesIgnoringSafeArea(.all) - HStack { - Toggle(isOn: self.$viewModel.isDetailedAuthentication) { - Text("Advanced options") - } - Spacer() - Button(action: {self.viewModel.isDetailedAuthentication ? - self.viewModel.validate(self.login, self.password, self.username, self.imapServer, self.imapPort, self.imapEncryption, self.smtpServer, self.smtpPort, self.smtpEncryption) : - self.viewModel.validate(self.login, self.password) - }) { - Text("Button") - } - } - - if self.viewModel.isDetailedAuthentication { - Text("Username") - TextField("Please enter your nickname", text: $username).textFieldStyle(RoundedBorderTextFieldStyle()) - - HStack { - Text("Imap server") - TextField("e.g. imap.web.de", text: $imapServer) - } + VStack { + Text("Please enter Your credentials").padding().foregroundColor(Color.yellow) + Text("Login") + TextField("Please enter your login", text: $login).textFieldStyle(RoundedBorderTextFieldStyle()) + Text("Password") + SecureField("Please enter your password", text: $password).textFieldStyle(RoundedBorderTextFieldStyle()) + HStack { - Text("Imap port") - TextField("e.g. 993", text:$imapPort).keyboardType(.numberPad) - } - Picker(selection: $imapEncryption, label: Text("IMAP-Transportencryption")) { - ForEach(0..<encryptionOptions.count) { - Text(self.encryptionOptions[$0]) + Toggle(isOn: self.$viewModel.isDetailedAuthentication) { + Text("Advanced options") + } + Spacer() + Button(action: {self.viewModel.isDetailedAuthentication ? + self.viewModel.validate(self.login, self.password, self.username, self.imapServer, self.imapPort, self.imapEncryption, self.smtpServer, self.smtpPort, self.smtpEncryption) : + self.viewModel.validate(self.login, self.password) + }) { + Text("Login") } } - HStack { - Text("Smtp server") - TextField("e.g. smtp.web.de", text: $smtpServer) + + if self.viewModel.isDetailedAuthentication { + Text("Username") + TextField("Please enter your username", text: $username).textFieldStyle(RoundedBorderTextFieldStyle()) + + HStack { + Text("Imap server") + TextField("e.g. imap.web.de", text: $imapServer) + } + HStack { + Text("Imap port") + TextField("e.g. 993", text:$imapPort).keyboardType(.numberPad) + } + Picker(selection: $imapEncryption, label: Text("IMAP-Transportencryption")) { + ForEach(0..<encryptionOptions.count) { + Text(self.encryptionOptions[$0]) + } + } + HStack { + Text("Smtp server") + TextField("e.g. smtp.web.de", text: $smtpServer) + } + HStack { + Text("Smtp port") + TextField("e.g. 587", text: $smtpPort).keyboardType(.numberPad) + } + + Picker(selection: $smtpEncryption, label: Text("SMTP-Transportencryption")) { + ForEach(0..<encryptionOptions.count) { + Text(self.encryptionOptions[$0]) + } + } } - HStack { - Text("Smtp port") - TextField("e.g. 587", text: $smtpPort).keyboardType(.numberPad) + + Button(action: { self.viewModel.oauth() }) { + Text("Google login") } + + }.padding() - Picker(selection: $smtpEncryption, label: Text("SMTP-Transportencryption")) { - ForEach(0..<encryptionOptions.count) { - Text(self.encryptionOptions[$0]) - } + //TODO: once SWIFTUI supports optionals improve this if statement + if self.viewModel.errorMessage != nil && !self.viewModel.errorMessage!.isEmpty { + VStack { + Text(self.viewModel.errorMessage!) + .foregroundColor(Color.white) + .background(Color.red) + Spacer() } } - - Button(action: { self.viewModel.oauth() }) { - Text("Google button") - } - - }.padding() - - //TODO: once SWIFTUI supports optionals improve this if statement - if self.viewModel.errorMessage != nil && !self.viewModel.errorMessage!.isEmpty { - VStack { - Text(self.viewModel.errorMessage!) - .foregroundColor(Color.white) - .background(Color.red) - Spacer() - } } } } diff --git a/enzevalos_iphone/AuthenticationViewModel.swift b/enzevalos_iphone/AuthenticationViewModel.swift index 093baac65b7a24b81a2baed11162240ccfc7ab02..6b06149e52006a31d5a4b8c0ea5249e4345c0c97 100644 --- a/enzevalos_iphone/AuthenticationViewModel.swift +++ b/enzevalos_iphone/AuthenticationViewModel.swift @@ -18,11 +18,11 @@ class AuthenticationViewModel : ObservableObject { var login:String = "" - @Published var imapServer: String = "imap.web.de" + @Published var imapServer: String = "imap.example.com" @Published var imapPort: String = String(DEFAULT_IMAP_PORT) @Published var imapTransportEncryption = 2 - @Published var smtpServer: String = "smtp.web.de" + @Published var smtpServer: String = "smtp.example.com" @Published var smtpPort: String = String(DEFAULT_SMTP_PORT) @Published var smtpTransportEncryption = 1 @@ -30,7 +30,7 @@ class AuthenticationViewModel : ObservableObject { var imapConfigurationSuccessful = false var smtpConfigurationSuccessful = false - var startTimeIMAPCheck: Date? //TODO What about SMTP? + var startTimeIMAPCheck: Date? var startTimeView = Date() var transportRows: [Int: String] = [MCOConnectionType.clear.rawValue: NSLocalizedString("Plaintext", comment: ""), MCOConnectionType.startTLS.rawValue: "StartTLS", MCOConnectionType.TLS.rawValue: "TLS/SSL"] @@ -52,7 +52,7 @@ class AuthenticationViewModel : ObservableObject { self.smtpServer = smtpServer self.smtpPort = smtpPort self.smtpTransportEncryption = smtpEncryption - checkDetailConfig(imap: true, login, password, username: "rtes",imapServer, Int(imapPort)!, imapEncryption, smtpServer, Int(smtpPort)!, smtpEncryption) + checkDetailConfig(imap: true, login, password, username: username, imapServer, Int(imapPort)!, imapEncryption, smtpServer, Int(smtpPort)!, smtpEncryption) } func checkIMAPConfig(_ login: String, _ password: String) { @@ -111,7 +111,6 @@ class AuthenticationViewModel : ObservableObject { print("No view controller!") return } - // TODO guard: Internet connection? Logger.log(onboardingState: .GoogleLogIn, duration: 0) EmailHelper.singleton().doEmailLoginIfRequired(onVC: vc, completionBlock: { @@ -171,12 +170,7 @@ class AuthenticationViewModel : ObservableObject { let imapSession = setupIMAPSession(login, password) let smtpSession = setupSMTPSession(login, password) - - var name = login - if let n = username { - name = n - } - + let imapConnValue = 1 << imapEncryption let smtpConnValue = 1 << smtpEncryption