Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First commit - signup function added to AuthenticationService.swift.… #37

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.xcworkspace/xcuserdata/
DerivedData/
build/
.DS_Store

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
8 changes: 6 additions & 2 deletions MobileAcebook/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Josué Estévez Fernández on 01/10/2023.
//

public struct User {
let username: String


public struct User: Encodable {
let imgUrl: String
let email: String
let password: String
let username: String
}
36 changes: 34 additions & 2 deletions MobileAcebook/Services/AuthenticationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,42 @@
//
// Created by Josué Estévez Fernández on 01/10/2023.
//
import Foundation



class AuthenticationService: AuthenticationServiceProtocol {
struct Response: Codable {
let message : String
}

func signUp(user: User) -> Bool {
// Logic to call the backend API for signing up
return true // placeholder
guard let url = URL(string: "http://localhost:3000/users") else {return false}

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

let body = user
urlRequest.httpBody = try? JSONEncoder().encode(user)
let task = URLSession.shared.dataTask(with : urlRequest) {data, response, error in
guard let data = data else {return}
do {
let response = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
print(response)
print("User created successfully")
}
catch {
print(error)
}
}
task.resume()
return true
}





}

2 changes: 1 addition & 1 deletion MobileAcebook/WelcomePageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct WelcomePageView: View {
VStack {
Spacer()

Text("Welcome to Acebook!")
Text("Welcome to Pawbook!")
.font(.largeTitle)
.padding(.bottom, 20)
.accessibilityIdentifier("welcomeText")
Expand Down