mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
models now handle authentication
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// AddFeedWranglerAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
|
||||
struct AddFeedWranglerAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddFeedWranglerViewModel()
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.feedWrangler.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your Feed Wrangler account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don't have a Feed Wrangler account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
NSWorkspace.shared.open(URL(string: "https://feedwrangler.net/users/new")!)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateFeedWrangler()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedWranglerAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedWranglerAccountView()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user