-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/yale-swe/f23-here
- Loading branch information
Showing
13 changed files
with
162 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// | ||
// LoginView.swift | ||
// newHere | ||
// | ||
// Created by TRACY LI on 2023/11/7. | ||
// | ||
|
||
import SwiftUI | ||
|
||
let loginUrlString = "https://here-swe.vercel.app/auth/login" | ||
let logApiKey = "qe5YT6jOgiA422_UcdbmVxxG1Z6G48aHV7fSV4TbAPs" | ||
|
||
struct LoginView: View { | ||
@State private var username: String = "" | ||
@State private var password: String = "" | ||
@State private var isRegistered = false | ||
@Binding var isAuthenticated: Bool | ||
|
||
var body: some View { | ||
|
||
NavigationView { | ||
VStack { | ||
Text("Login") | ||
.font(.largeTitle) | ||
.padding(.bottom, 50) | ||
|
||
TextField("Username", text: $username) | ||
.padding() | ||
.background(Color(.systemGray6)) | ||
.cornerRadius(5.0) | ||
.padding(.bottom, 20) | ||
|
||
SecureField("Password", text: $password) | ||
.padding() | ||
.background(Color(.systemGray6)) | ||
.cornerRadius(5.0) | ||
.padding(.bottom, 20) | ||
|
||
Button(action: LogInUser) { | ||
Text("Login") | ||
.frame(minWidth: 0, maxWidth: .infinity) | ||
.frame(height: 50) | ||
.foregroundColor(.white) | ||
.font(.system(size: 18, weight: .bold)) | ||
.background(Color.blue) | ||
.cornerRadius(5.0) | ||
} | ||
.padding(.horizontal) | ||
|
||
NavigationLink(destination: RegistrationView(isRegistered: $isRegistered)) { | ||
Text("Don't have an account? Signup") | ||
} | ||
.padding() | ||
|
||
Spacer() | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
func LogInUser(){ | ||
let requestBody: [String: Any] = [ | ||
"userName": username, | ||
"password": password] | ||
|
||
guard let jsonData = try? JSONSerialization.data(withJSONObject: requestBody) | ||
else{ | ||
return | ||
} | ||
|
||
guard let url = URL(string: loginUrlString) else { | ||
return | ||
} | ||
|
||
var request = URLRequest(url: url) | ||
request.httpMethod = "POST" | ||
request.httpBody = jsonData | ||
request.setValue("application/json", forHTTPHeaderField: "Content-Type") | ||
request.setValue(logApiKey, forHTTPHeaderField: "x-api-key") | ||
|
||
|
||
URLSession.shared.dataTask(with: request) { data, response, error in | ||
if let error = error{ | ||
print("error:\(error)") | ||
} else if let data = data { | ||
if let responseString = String(data: data, encoding: .utf8) { | ||
print("Response: \(responseString)") | ||
} | ||
self.isAuthenticated = true; | ||
} | ||
}.resume() | ||
|
||
} | ||
|
||
} | ||
|
||
//// Preview Provider | ||
//struct LoginView_Previews: PreviewProvider { | ||
// static var previews: some View { | ||
// LoginView(isAuthenticated: $isAuthenticated) | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.