mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Check for http OR https on login when logging in
This commit is contained in:
parent
f686b6fb76
commit
0bde76c7d8
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user