Skip to content
This repository has been archived by the owner on Apr 10, 2020. It is now read-only.

Commit

Permalink
add a custom view for login
Browse files Browse the repository at this point in the history
  • Loading branch information
Stormacq, Sebastien committed Oct 28, 2019
1 parent ad6b3ea commit bf43285
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 10 deletions.
19 changes: 19 additions & 0 deletions code/Complete/Landmarks/Landmarks/AppDelegate.swift
Expand Up @@ -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()
}
Expand Down
56 changes: 56 additions & 0 deletions code/Complete/Landmarks/Landmarks/CustomLoginView.swift
@@ -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 changes: 1 addition & 10 deletions code/Complete/Landmarks/Landmarks/LandingView.swift
Expand Up @@ -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)
}
Expand Down

0 comments on commit bf43285

Please sign in to comment.