@@ -60,7 +60,11 @@ class WebDAVAuthenticationViewController: UIViewController {
6060 hud? . transformToSelfDismissingSuccess ( ) . then {
6161 self . coordinator? . authenticated ( with: credential)
6262 }
63- case . initial, . insecureConnectionNotAllowed, . untrustedCertificate:
63+ case . insecureConnectionNotAllowed:
64+ showInsecureConnectionAlert ( )
65+ case let . untrustedCertificate( certificate: certificate, url: url) :
66+ showUntrustedCertificateAlert ( certificate: certificate, url: url)
67+ case . initial:
6468 break
6569 }
6670 }
@@ -86,6 +90,51 @@ class WebDAVAuthenticationViewController: UIViewController {
8690 hud? . showLoadingIndicator ( )
8791 }
8892
93+ private func showUntrustedCertificateAlert( certificate: TLSCertificate , url: URL ) {
94+ let precondition : Promise < Void >
95+ if let hud = hud {
96+ precondition = hud. dismiss ( animated: true )
97+ } else {
98+ precondition = Promise ( ( ) )
99+ }
100+ precondition. then { [ weak self] in
101+ let message = String ( format: LocalizedString . getValue ( " untrustedTLSCertificate.message " ) , url. absoluteString, certificate. fingerprint)
102+ let alertController = UIAlertController ( title: LocalizedString . getValue ( " untrustedTLSCertificate.title " ) ,
103+ message: message,
104+ preferredStyle: . alert)
105+ let addAction = UIAlertAction ( title: LocalizedString . getValue ( " untrustedTLSCertificate.add " ) ,
106+ style: . default,
107+ handler: { _ in self ? . viewModel. saveAccountWithCertificate ( ) } )
108+ alertController. addAction ( addAction)
109+ alertController. addAction ( UIAlertAction ( title: LocalizedString . getValue ( " untrustedTLSCertificate.dismiss " ) , style: . cancel) )
110+ self ? . present ( alertController, animated: true )
111+ }
112+ }
113+
114+ private func showInsecureConnectionAlert( ) {
115+ let precondition : Promise < Void >
116+ if let hud = hud {
117+ precondition = hud. dismiss ( animated: true )
118+ } else {
119+ precondition = Promise ( ( ) )
120+ }
121+ precondition. then { [ weak self] in
122+ let alertController = UIAlertController ( title: LocalizedString . getValue ( " webDAVAuthentication.httpConnection.alert.title " ) ,
123+ message: LocalizedString . getValue ( " webDAVAuthentication.httpConnection.alert.message " ) ,
124+ preferredStyle: . alert)
125+ let changeToHTTPSAction = UIAlertAction ( title: LocalizedString . getValue ( " webDAVAuthentication.httpConnection.change " ) , style: . default, handler: { _ in
126+ self ? . viewModel. saveAccountWithTransformedURL ( )
127+ } )
128+
129+ alertController. addAction ( changeToHTTPSAction)
130+ alertController. preferredAction = changeToHTTPSAction
131+ alertController. addAction ( UIAlertAction ( title: LocalizedString . getValue ( " webDAVAuthentication.httpConnection.continue " ) , style: . destructive, handler: { _ in
132+ self ? . viewModel. saveAccountWithInsecureConnection ( )
133+ } ) )
134+ self ? . present ( alertController, animated: true )
135+ }
136+ }
137+
89138 @objc func cancel( ) {
90139 coordinator? . cancel ( )
91140 }
0 commit comments