-
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.
- Loading branch information
tkshsbcue
committed
Jun 1, 2024
1 parent
4ef4376
commit 268a532
Showing
9 changed files
with
127 additions
and
12 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 modified
BIN
+4.48 KB
(110%)
...proj/project.xcworkspace/xcuserdata/kumartanay.xcuserdatad/UserInterfaceState.xcuserstate
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,60 @@ | ||
// | ||
// RegisterViewModel.swift | ||
// Tickle | ||
// | ||
// Created by Kumar Tanay on 01/06/24. | ||
// | ||
|
||
import Foundation | ||
import FirebaseAuth | ||
import Firebase | ||
|
||
|
||
class RegisterViewModel: ObservableObject{ | ||
|
||
//state property | ||
@Published var name = "" | ||
@Published var email = "" | ||
@Published var password = "" | ||
init (){} | ||
|
||
func register(){ | ||
guard validate() else{ | ||
return | ||
} | ||
|
||
|
||
Auth.auth().createUser(withEmail: email, password: password){result, error in | ||
guard let userId = result?.user.uid else{ | ||
return | ||
} | ||
self.insertUserRecord(id: userId) | ||
} | ||
|
||
|
||
} | ||
|
||
private func insertUserRecord(id:String){ | ||
let newUser = User(id:id,name: name,email: email,joined: Date().timeIntervalSince1970) | ||
let db = Firestore.firestore() | ||
db.collection("users").document(id).setData(newUser.asDictionary()) | ||
} | ||
|
||
|
||
private func validate() -> Bool { | ||
guard !name.trimmingCharacters(in: .whitespaces).isEmpty, | ||
!email.trimmingCharacters(in: .whitespaces).isEmpty, | ||
!password.trimmingCharacters(in: .whitespaces).isEmpty else{ | ||
return false | ||
} | ||
guard email.contains("@") && email.contains(".")else{ | ||
return false | ||
} | ||
guard password.count >= 6 else{ | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ import SwiftUI | |
@main | ||
struct TickleApp: App { | ||
var body: some Scene { | ||
|
||
WindowGroup { | ||
LoginView() | ||
} | ||
|
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,23 @@ | ||
// | ||
// extension.swift | ||
// Tickle | ||
// | ||
// Created by Kumar Tanay on 01/06/24. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
extension Encodable{ | ||
func asDictionary() -> [String:Any]{ | ||
guard let data = try? JSONEncoder().encode(self) else{ | ||
return [:] | ||
} | ||
do{ | ||
let json = try JSONSerialization.jsonObject(with: data) as? [String:Any] | ||
return json ?? [:] | ||
}catch{ | ||
return [:] | ||
} | ||
} | ||
} |
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,16 @@ | ||
// | ||
// user.swift | ||
// Tickle | ||
// | ||
// Created by Kumar Tanay on 01/06/24. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
struct User: Codable{ | ||
let id: String | ||
let name:String | ||
let email:String | ||
let joined:TimeInterval | ||
} |