Skip to content

Commit

Permalink
stopped tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Wang committed Nov 4, 2023
2 parents 85048fc + 743d60c commit 989f2f4
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 9 deletions.
Binary file not shown.
18 changes: 12 additions & 6 deletions app/newHere1/newHere/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
import SwiftUI

struct ContentView: View {
@ObservedObject var locationDataManager = LocationDataManager()
var body: some View {
HomePageView()
.environmentObject(locationDataManager)
@State private var isRegistered = false

var body: some View {
if isRegistered {
HomePageView()
} else {
RegistrationView(isRegistered: $isRegistered)
}
}
}

#Preview {
ContentView()
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
83 changes: 83 additions & 0 deletions app/newHere1/newHere/Registration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Registration.swift
// newHere
//
// Created by TRACY LI on 2023/11/4.
//

import SwiftUI

let registerUrlString = "https://here-swe.vercel.app/auth/register"
let apiKey = "qe5YT6jOgiA422_UcdbmVxxG1Z6G48aHV7fSV4TbAPs"

struct RegistrationView: View {
@State private var firstName: String = ""
@State private var lastName: String = ""
@State private var userName: String = ""
@State private var email: String = ""
@State private var password: String = ""
@State private var confirmPassword: String = ""
@Binding var isRegistered: Bool

var body: some View {
NavigationView {
Form {
Section(header: Text("Name")) {
TextField("First Name", text: $firstName)
TextField("Last Name", text: $lastName)
}

Section(header: Text("Credentials")) {
TextField("Username", text: $userName)
TextField("Email", text: $email)
.keyboardType(.emailAddress)
.autocapitalization(.none)
SecureField("Password", text: $password)
SecureField("Confirm Password", text: $confirmPassword)
}

Section {
Button(action: registerUser) {
Text("Submit")
}
}
}
.navigationBarTitle("Registration")
}
}

func registerUser() {
// Implement registration logic
print("User registration logic goes here.")
let requestBody: [String: Any] = [
"firstName": firstName,
"lastName": lastName,
"userName": userName,
"email": email,
"password": password
]

guard let jsonData = try? JSONSerialization.data(withJSONObject: requestBody)
else {
return
}

guard let url = URL(string: registerUrlString) else {
return
}

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = jsonData
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

URLSession.shared.dataTask(with: request) { data, response, error in }.resume()
self.isRegistered = true
}
}

struct RegistrationView_Previews: PreviewProvider {
static var previews: some View {
RegistrationView(isRegistered: self.isRegistered)
}
}
108 changes: 108 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Note that base url will change with deployment of backend.

# AUTH
- REGISTER: POST "http://localhost:6000/auth/register"
- params:
{
"userName": "JohnDED",
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"password": "secretpassword"
}

- LOGIN: GET "http://localhost:6000/auth/login"
- params:
{
"inputLogin": "JaneD",
"password": "secretpassword"
}

# MESSAGE
- POST MESSAGE: POST "http://localhost:6000/message/post_message"
- params:
{
"user_id": "653d51478ff5b3c9ace45c26",
"text": "Hi, this is a test message - Jane",
"visibility": "friends",
"location": {
"type": "Point",
"coordinates": [40.7128, -74.0060]
}
}

- DELETE MESSAGE: POST "http://localhost:6000/message/delete_message"
- params:
{
"messageId": "653d62a37ce9c61f28dcaa7f"
}

- INCREMENT LIKES: POST "http://localhost:6000/message/increment_likes"
- params:
{
"id": "653d62de7ce9c61f28dcaa87"
}

- CHANGE VISIBILITY: POST "http://localhost:6000/message/change_visibility"
- params:
{
"id": "dsfsf",
"new_data": ""
}

# REPLY
- ADD REPLY: POST "http://localhost:6000/reply/reply_to_message"
- params:
{
"message_id": "653ea4a35b858b2542ea4f13",
"content": "this is a test reply to a test message"
}

- LIKE REPLY: GET "http://localhost:6000/reply/like_reply"
- params:
{
"reply_id": "somekindofreplyid"
}

# USER
- SEARCH USER BY USER_ID: GET "http://localhost:6000/user/search"
- params:
{
"userId": ""
}
- SEARCH USER BY EMAIL: GET "http://localhost:6000/user/search"
- params:
{
"email": "[email protected]"
}

- SEARCH USER BY USERNAME: GET "http://localhost:6000/user/search"
- params:
{
"userName": ""
}

- ADD USER FRIEND: PUT "http://localhost:6000/user/userid"
- params:
{
"friendId": "friend's id"
}

- GET FRIEND OF USER: GET "http://localhost:6000/user/userId/friends"

- TOGGLE NOTIFY FRIENDS: PUT "http://localhost:6000/user/userId/toggle-notify-friends"

- UPDATE PROFILE: PUT "http://localhost:6000/user/userId/update-profile"
- params:
{
"userName": "john_d",
"password": "hello",
"firstName": "Johnn",
"lastName": "Doee",
"email": "[email protected]",
"avatar": ""
}

- REMOVE USER FRIEND: GET "http://localhost:6000/user/search/[email protected]"

- DELETE USER: DELETE "http://localhost:6000/user/653d58a37ab5eaf376965b82"
2 changes: 0 additions & 2 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export const login = async (req, res) => {
$or: [{ email: inputLogin }, { userName: inputLogin }],
});

console.log(inputLogin);

if (!user) {
return handleNotFound(res, "User not found");
}
Expand Down
16 changes: 15 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ dotenv.config();
const app = express();
const PORT = process.env.PORT || 6001;

// API Key Middleware
const apiKeyAuth = (req, res, next) => {
const userApiKey = req.get("X-API-Key");
if (!userApiKey) {
return res.status(401).json({ error: "API key is required" });
}
if (userApiKey !== process.env.API_KEY) {
return res.status(403).json({ error: "Invalid API key" });
}
next();
};

// Apply the API Key middleware globally
app.use(apiKeyAuth);

// Connect to DB
connectDB();

Expand All @@ -33,7 +48,6 @@ app.use("/message", messageRoutes);
app.use("/reply", replyRoutes);
app.use("/user", userRoutes);


const server = app.listen(PORT, console.log(`Server running on port ${PORT}`));

// Handle unhandled promise rejections
Expand Down
28 changes: 28 additions & 0 deletions server/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"version": 2,
"builds": [
{
"src": "server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/auth/(.*)",
"dest": "/server.js"
},
{
"src": "/message/(.*)",
"dest": "/server.js"
},
{
"src": "/reply/(.*)",
"dest": "/server.js"
},
{
"src": "/user/(.*)",
"dest": "/server.js"
}
]
}

0 comments on commit 989f2f4

Please sign in to comment.