Skip to content
Permalink
Browse files

add a custom view for login

  • Loading branch information
Stormacq, Sebastien
Stormacq, Sebastien committed Oct 28, 2019
1 parent ad6b3ea commit bf43285a9ea3eec85fb7d4a3cc33a4acebdbf1d9
@@ -132,6 +132,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

public func signIn(username: String, password: String) {
AWSMobileClient.default().signIn(username: username, password: password) { (signInResult, error) in

if let error = error {
print("\(error)")
// in real life, present an error message to user
} else if let signInResult = signInResult {
switch (signInResult.signInState) {
case .signedIn:
print("User is signed in.")
case .smsMFA:
print("SMS message sent to \(signInResult.codeDetails!.destination!)")
default:
print("Sign In needs info which is not et supported.")
}
}
}
}

public func signOut() {
AWSMobileClient.default().signOut()
}
@@ -0,0 +1,56 @@
import SwiftUI

struct CustomLoginView : View {

@State private var username: String = ""
@State private var password: String = ""

private let app = UIApplication.shared.delegate as! AppDelegate

var body: some View { // The body of the screen view
VStack {
Image("turtlerock")
.resizable()
.aspectRatio(contentMode: ContentMode.fit)
.padding(Edge.Set.bottom, 20)

Text(verbatim: "Login").bold().font(.title)

Text(verbatim: "Explore Landmarks of the world")
.font(.subheadline)
.padding(EdgeInsets(top: 0, leading: 0, bottom: 70, trailing: 0))

TextField("Username", text: $username)
.autocapitalization(.none) //avoid autocapitalization of the first letter
.padding()
.cornerRadius(4.0)
.background(Color(UIColor.systemFill))
.padding(EdgeInsets(top: 0, leading: 0, bottom: 15, trailing: 0))

SecureField("Password", text: $password)
.padding()
.cornerRadius(4.0)
.background(Color(UIColor.systemFill))
.padding(.bottom, 10)

Button(action: { self.app.signIn(username: self.username, password: self.password) }) {
HStack() {
Spacer()
Text("Signin")
.foregroundColor(Color.white)
.bold()
Spacer()
}

}.padding().background(Color.green).cornerRadius(4.0)
}.padding()
}
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
CustomLoginView() // Renders your UI View on the XCode preview
}
}
#endif
@@ -11,19 +11,10 @@ struct LandingView: View {

var body: some View {

let loginView = LoginViewController()

return VStack {
// .wrappedValue is used to extract the Bool from Binding<Bool> type
if (!$user.isSignedIn.wrappedValue) {

ZStack {
loginView
Button(action: { loginView.authenticate() } ) {
UserBadge().scaleEffect(0.5)
}
}

CustomLoginView()
} else {
LandmarkList().environmentObject(user)
}

0 comments on commit bf43285

Please sign in to comment.
You can’t perform that action at this time.