Check for http OR https on login when logging in

This commit is contained in:
Angelo Stavrow 2020-09-25 10:55:42 -04:00
parent f686b6fb76
commit 0bde76c7d8
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 13 additions and 6 deletions

View File

@ -52,10 +52,6 @@ struct AccountLoginView: View {
.padding()
} else {
Button(action: {
let secureProtocolPrefix = "https://"
if !server.hasPrefix(secureProtocolPrefix) {
server = secureProtocolPrefix + server
}
model.login(
to: URL(string: server)!,
as: username, password: password

View File

@ -79,9 +79,20 @@ class WriteFreelyModel: ObservableObject {
extension WriteFreelyModel {
func login(to server: URL, as username: String, password: String) {
let secureProtocolPrefix = "https://"
let insecureProtocolPrefix = "http://"
var serverString = server.absoluteString
// If there's neither an http or https prefix, prepend "https://" to the server string.
if !(serverString.hasPrefix(secureProtocolPrefix) || serverString.hasPrefix(insecureProtocolPrefix)) {
serverString = secureProtocolPrefix + serverString
}
// If the server string is prefixed with http, upgrade to https before attempting to login.
if serverString.hasPrefix(insecureProtocolPrefix) {
serverString = serverString.replacingOccurrences(of: insecureProtocolPrefix, with: secureProtocolPrefix)
}
isLoggingIn = true
account.server = server.absoluteString
client = WFClient(for: server)
account.server = serverString
client = WFClient(for: URL(string: serverString)!)
client?.login(username: username, password: password, completion: loginHandler)
}