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.… #2

Merged
merged 4 commits into from
Apr 16, 2024
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.xcworkspace/xcuserdata/
DerivedData/
build/
.DS_Store
.DS_Store

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
}





}