mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add an account login view for testing
This commit is contained in:
parent
0bf89b4cff
commit
8870d2ff38
@ -22,6 +22,10 @@
|
||||
1756AE7A24CB65DF00FD7257 /* PostList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756AE7924CB65DF00FD7257 /* PostList.swift */; };
|
||||
1756AE7B24CB65DF00FD7257 /* PostList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756AE7924CB65DF00FD7257 /* PostList.swift */; };
|
||||
1756AE8124CB844500FD7257 /* View+Keyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756AE8024CB844500FD7257 /* View+Keyboard.swift */; };
|
||||
17A5388824DDA31F00DEFF9A /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388724DDA31F00DEFF9A /* SettingsView.swift */; };
|
||||
17A5388C24DDC83F00DEFF9A /* AccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388B24DDC83F00DEFF9A /* AccountModel.swift */; };
|
||||
17A5388F24DDEC7400DEFF9A /* AccountLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5388D24DDEC7400DEFF9A /* AccountLogin.swift */; };
|
||||
17A5389324DDED0000DEFF9A /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A5389124DDED0000DEFF9A /* Preferences.swift */; };
|
||||
17DF329D24C87D3500BCE2E3 /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF329C24C87D3500BCE2E3 /* Tests_iOS.swift */; };
|
||||
17DF32A824C87D3500BCE2E3 /* Tests_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF32A724C87D3500BCE2E3 /* Tests_macOS.swift */; };
|
||||
17DF32AA24C87D3500BCE2E3 /* WriteFreely_MultiPlatformApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */; };
|
||||
@ -62,6 +66,10 @@
|
||||
1756AE7624CB2EDD00FD7257 /* PostEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostEditor.swift; sourceTree = "<group>"; };
|
||||
1756AE7924CB65DF00FD7257 /* PostList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostList.swift; sourceTree = "<group>"; };
|
||||
1756AE8024CB844500FD7257 /* View+Keyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Keyboard.swift"; sourceTree = "<group>"; };
|
||||
17A5388724DDA31F00DEFF9A /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||
17A5388B24DDC83F00DEFF9A /* AccountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountModel.swift; sourceTree = "<group>"; };
|
||||
17A5388D24DDEC7400DEFF9A /* AccountLogin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountLogin.swift; sourceTree = "<group>"; };
|
||||
17A5389124DDED0000DEFF9A /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
|
||||
17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteFreely_MultiPlatformApp.swift; sourceTree = "<group>"; };
|
||||
17DF328224C87D3300BCE2E3 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
17DF328324C87D3500BCE2E3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
@ -126,6 +134,16 @@
|
||||
path = Extensions;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
17A5388924DDA50500DEFF9A /* Settings */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
17A5388D24DDEC7400DEFF9A /* AccountLogin.swift */,
|
||||
17A5389124DDED0000DEFF9A /* Preferences.swift */,
|
||||
17A5388724DDA31F00DEFF9A /* SettingsView.swift */,
|
||||
);
|
||||
path = Settings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
17DF327B24C87D3300BCE2E3 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -149,12 +167,11 @@
|
||||
children = (
|
||||
17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */,
|
||||
17DF328324C87D3500BCE2E3 /* Assets.xcassets */,
|
||||
17DF32D024C8B75C00BCE2E3 /* Model */,
|
||||
17DF32D024C8B75C00BCE2E3 /* Account */,
|
||||
1756AE7F24CB841200FD7257 /* Extensions */,
|
||||
17DF32CC24C8B72300BCE2E3 /* Navigation */,
|
||||
17DF32D224C8B78D00BCE2E3 /* PostCollection */,
|
||||
17DF32D124C8B78500BCE2E3 /* Post */,
|
||||
17DF32D324C8C9F600BCE2E3 /* Components */,
|
||||
);
|
||||
path = Shared;
|
||||
sourceTree = "<group>";
|
||||
@ -183,6 +200,7 @@
|
||||
children = (
|
||||
17DF329224C87D3500BCE2E3 /* Info.plist */,
|
||||
17DF329324C87D3500BCE2E3 /* macOS.entitlements */,
|
||||
17A5388924DDA50500DEFF9A /* Settings */,
|
||||
);
|
||||
path = macOS;
|
||||
sourceTree = "<group>";
|
||||
@ -220,11 +238,12 @@
|
||||
path = Navigation;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
17DF32D024C8B75C00BCE2E3 /* Model */ = {
|
||||
17DF32D024C8B75C00BCE2E3 /* Account */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
17A5388B24DDC83F00DEFF9A /* AccountModel.swift */,
|
||||
);
|
||||
path = Model;
|
||||
path = Account;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
17DF32D124C8B78500BCE2E3 /* Post */ = {
|
||||
@ -249,13 +268,6 @@
|
||||
path = PostCollection;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
17DF32D324C8C9F600BCE2E3 /* Components */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
path = Components;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@ -486,9 +498,13 @@
|
||||
1756AE7B24CB65DF00FD7257 /* PostList.swift in Sources */,
|
||||
171BFDFB24D4AF8300888236 /* CollectionSidebar.swift in Sources */,
|
||||
17DF32AB24C87D3500BCE2E3 /* WriteFreely_MultiPlatformApp.swift in Sources */,
|
||||
17A5388C24DDC83F00DEFF9A /* AccountModel.swift in Sources */,
|
||||
17A5389324DDED0000DEFF9A /* Preferences.swift in Sources */,
|
||||
1756AE6F24CB255B00FD7257 /* PostStore.swift in Sources */,
|
||||
1756AE6C24CB1E4B00FD7257 /* Post.swift in Sources */,
|
||||
17A5388F24DDEC7400DEFF9A /* AccountLogin.swift in Sources */,
|
||||
1756AE7524CB26FA00FD7257 /* PostCell.swift in Sources */,
|
||||
17A5388824DDA31F00DEFF9A /* SettingsView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -649,6 +665,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 0.0.3;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform";
|
||||
PRODUCT_NAME = "WriteFreely-MultiPlatform";
|
||||
SDKROOT = iphoneos;
|
||||
@ -671,6 +688,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 0.0.3;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.abunchtell.WriteFreely-MultiPlatform";
|
||||
PRODUCT_NAME = "WriteFreely-MultiPlatform";
|
||||
SDKROOT = iphoneos;
|
||||
|
@ -7,12 +7,12 @@
|
||||
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>1</integer>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
|
@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
130
macOS/Settings/AccountLogin.swift
Normal file
130
macOS/Settings/AccountLogin.swift
Normal file
@ -0,0 +1,130 @@
|
||||
//
|
||||
// AccountLogin.swift
|
||||
// WriteFreely-MultiPlatform
|
||||
//
|
||||
// Created by Angelo Stavrow on 2020-08-07.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AccountLogin: View {
|
||||
@State var accountModel = AccountModel()
|
||||
|
||||
@State private var username: String = ""
|
||||
@State private var password: String = ""
|
||||
@State private var server: String = ""
|
||||
@State private var isLoggingIn: Bool = false
|
||||
@State private var isLoggedIn: Bool = false
|
||||
@State private var isShowingAlert: Bool = false
|
||||
@State private var alertMessage: String = ""
|
||||
|
||||
var body: some View {
|
||||
if isLoggedIn {
|
||||
VStack {
|
||||
Spacer()
|
||||
HStack {
|
||||
Text("Logged in as")
|
||||
Text(accountModel.username ?? "UNKNOWN")
|
||||
.font(.system(.body, design: .monospaced))
|
||||
Text("on")
|
||||
Text(accountModel.server ?? "UNKNOWN")
|
||||
.font(.system(.body, design: .monospaced))
|
||||
}
|
||||
Spacer()
|
||||
Button(action: logoutHandler, label: {
|
||||
Text("Logout")
|
||||
})
|
||||
Spacer()
|
||||
}
|
||||
} else {
|
||||
Form {
|
||||
Section(header: Text("Login to your account")) {
|
||||
VStack {
|
||||
HStack {
|
||||
Spacer()
|
||||
Image(systemName: "person.circle")
|
||||
.foregroundColor(.gray)
|
||||
TextField("Username", text: $username)
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Image(systemName: "lock.circle")
|
||||
.foregroundColor(.gray)
|
||||
TextField("Password", text: $password)
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Image(systemName: "link.circle")
|
||||
.foregroundColor(.gray)
|
||||
TextField("Server URL", text: $server)
|
||||
Spacer()
|
||||
}
|
||||
Spacer()
|
||||
if isLoggingIn {
|
||||
ProgressView("Logging in...")
|
||||
} else {
|
||||
Button(action: {
|
||||
accountModel.login(
|
||||
to: server,
|
||||
as: username, password: password,
|
||||
completion: loginHandler
|
||||
)
|
||||
isLoggingIn = true
|
||||
}, label: {
|
||||
Text("Login")
|
||||
}).disabled(isLoggedIn)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.alert(isPresented: $isShowingAlert) {
|
||||
Alert(
|
||||
title: Text("Error Logging In"),
|
||||
message: Text(alertMessage),
|
||||
dismissButton: .default(Text("OK"))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loginHandler(result: Result<UUID, AccountError>) {
|
||||
do {
|
||||
_ = try result.get()
|
||||
isLoggedIn = true
|
||||
isLoggingIn = false
|
||||
} catch AccountError.serverNotFound {
|
||||
alertMessage = """
|
||||
The server could not be found. Please check that you've entered the information correctly and try again.
|
||||
"""
|
||||
isLoggedIn = false
|
||||
isLoggingIn = false
|
||||
isShowingAlert = true
|
||||
} catch AccountError.invalidCredentials {
|
||||
alertMessage = """
|
||||
Invalid username or password. Please check that you've entered the information correctly and try again.
|
||||
"""
|
||||
isLoggedIn = false
|
||||
isLoggingIn = false
|
||||
isShowingAlert = true
|
||||
} catch {
|
||||
alertMessage = "An unknown error occurred. Please try again."
|
||||
isLoggedIn = false
|
||||
isLoggingIn = false
|
||||
isShowingAlert = true
|
||||
}
|
||||
}
|
||||
|
||||
func logoutHandler() {
|
||||
isLoggedIn = false
|
||||
isLoggingIn = false
|
||||
}
|
||||
}
|
||||
struct AccountLogin_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AccountLogin()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user