-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSignUpPageView.swift
168 lines (156 loc) · 6.9 KB
/
SignUpPageView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// SignUpPageView.swift
// MobileAcebook
//
// Created by Venera Zhargakova on 16/04/2024.
//
import Foundation
import SwiftUI
struct SignUpError: Identifiable {
let id = UUID()
let message: String
}
let authService = AuthenticationService()
struct SignUpPageView: View {
@State private var email = ""
@State private var imgUrl = ""
@State private var username = ""
@State private var password = ""
@State var isShowingPassword: Bool = false
@State private var signUpError: String? = nil
@State private var showAlert = false
@State private var isSignUpComplete = false
//errors:
@State private var emailError = ""
//let authService: AuthenticationServiceProtocol
@State private var showAlert = false
@State private var alertMessage = ""
var body: some View {
NavigationView {
VStack(spacing: 30) {
Spacer()
Spacer()
Text("Sign Up")
.font(.largeTitle)
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
VStack(spacing:0) {
Text("Email Address")
.frame(maxWidth: 250, alignment: .topLeading)
.padding()
TextField("", text: $email)
.frame(width: 250, height: 40)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color.gray)
.stroke(Color.gray)
)
.autocapitalization(. none)
.accessibilityIdentifier("email")
Text("Full Name")
.frame(maxWidth: 250, alignment: .topLeading)
.padding()
TextField("", text: $username)
TextField("", text: $username)
.frame(width: 250, height: 40)
.multilineTextAlignment(.center)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color.gray)
.stroke(Color.gray)
)
.autocapitalization(. none)
.accessibilityIdentifier("Full Name")
Text("Password")
.frame(maxWidth: 250, alignment: .topLeading)
.padding()
VStack {
Group {
if isShowingPassword {
TextField("", text: $password)
.frame(width: 250, height: 40)
.multilineTextAlignment(.center)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(Color.gray))
}else {
SecureField("", text: $password)
.frame(width: 250, height: 40)
.multilineTextAlignment(.center)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(Color.gray))
}
Group {
if isShowingPassword {
TextField("", text: $password)
.frame(width: 250, height: 40)
.multilineTextAlignment(.center)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(Color.gray))
}else {
SecureField("", text: $password)
.frame(width: 250, height: 40)
.multilineTextAlignment(.center)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(Color.gray))
}
}
.disableAutocorrection(true)
.autocapitalization(.none)
Button {
isShowingPassword.toggle()
} label: {
if isShowingPassword {
Text("Hide password")
} else {
Text("Show password")
}
}.padding()
}
VStack{
Button("Sign Up") {
let newUser = User(imgUrl: imgUrl, email: email, password: password, username: username)
authService.signUp(user: newUser) { success in
if success {
// Clear fields if signup successful
DispatchQueue.main.async {
email = ""
username = ""
password = ""
alertMessage = "Account created successfully"
showAlert = true
}
} else {
DispatchQueue.main.async {
alertMessage = "Error creating account"
showAlert = true
}
}
}
}
.frame(width: 250, height: 40)
.background(Color(red: 0x50/255, green: 0xB7/255, blue: 0xB7/255))
.foregroundColor(.white)
.cornerRadius(10)
}
}
.padding(.top, 40)
Spacer()
HStack(spacing:3){
Text("Already have an account?")
NavigationLink(destination: LoginPageView()){
Text("Login here")
.fontWeight(.bold)}
}
.padding()
}
.alert(isPresented: $showAlert) {
Alert(
title: Text(alertMessage),
dismissButton: .default(Text("OK"))
)}
}
}
}
#Preview {
SignUpPageView()
}