Skip to content

Commit

Permalink
callback function to registration
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiayk20 committed Nov 4, 2023
1 parent 14a1029 commit be799b8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/newHere1/newHere/Registration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

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 = ""
Expand All @@ -23,6 +27,7 @@ struct RegistrationView: View {
}

Section(header: Text("Credentials")) {
TextField("Username", text: $userName)
TextField("Email", text: $email)
.keyboardType(.emailAddress)
.autocapitalization(.none)
Expand All @@ -43,6 +48,29 @@ struct RegistrationView: View {
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
]

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

let url = URL(string: registerUrlString) else {
print("Invalid URL")
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
}
}

Expand Down

0 comments on commit be799b8

Please sign in to comment.