-
Notifications
You must be signed in to change notification settings - Fork 25
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
signup exercise succeed #68
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?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> | ||
<key>SchemeUserState</key> | ||
<dict> | ||
<key>SwiftUIBasics.xcscheme_^#shared#^_</key> | ||
<dict> | ||
<key>orderHint</key> | ||
<integer>0</integer> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,9 +16,21 @@ class SignUpViewModel: ObservableObject { | |||||
|
||||||
// outputs | ||||||
@Published var isValidUsernameLength: Bool = false | ||||||
|
||||||
@Published var isValidPasswordLength: Bool = false | ||||||
|
||||||
@Published var isValidPasswordUpperCase: Bool = false | ||||||
|
||||||
@Published var isValidPasswordLowerCase: Bool = false | ||||||
|
||||||
@Published var isValidPasswordHasNumber: Bool = false | ||||||
|
||||||
@Published var isValidPasswordHasSpecialCharacter: Bool = false | ||||||
|
||||||
|
||||||
|
||||||
Comment on lines
+23
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too many line jumps |
||||||
@Published var isValidPasswordMatch: Bool = false | ||||||
|
||||||
@Published var isValid: Bool = false | ||||||
|
||||||
private var cancelableSet: Set<AnyCancellable> = [] | ||||||
|
@@ -27,7 +39,12 @@ class SignUpViewModel: ObservableObject { | |||||
$username | ||||||
.receive(on: RunLoop.main) | ||||||
.map { username in | ||||||
return username.count >= 4 | ||||||
let pattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | ||||||
if let _ = username.range(of: pattern, options: .regularExpression) { | ||||||
return true | ||||||
} else { | ||||||
return false | ||||||
} | ||||||
} | ||||||
.assign(to: \.isValidUsernameLength, on: self) | ||||||
Comment on lines
+42
to
49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the username validating email? |
||||||
.store(in: &cancelableSet) | ||||||
|
@@ -52,6 +69,57 @@ class SignUpViewModel: ObservableObject { | |||||
} | ||||||
.assign(to: \.isValidPasswordUpperCase, on: self) | ||||||
.store(in: &cancelableSet) | ||||||
|
||||||
$password | ||||||
.receive(on: RunLoop.main) | ||||||
.map { | ||||||
password in | ||||||
let pattern = "[a-z]" | ||||||
if let _ = password.range(of: pattern, options: .regularExpression) { | ||||||
return true | ||||||
} else { | ||||||
return false | ||||||
} | ||||||
} | ||||||
.assign(to: \.isValidPasswordLowerCase, on: self) | ||||||
.store(in: &cancelableSet) | ||||||
|
||||||
$password | ||||||
.receive(on: RunLoop.main) | ||||||
.map { | ||||||
password in | ||||||
let pattern = "[0-9]" | ||||||
if let _ = password.range(of: pattern, options: .regularExpression) { | ||||||
return true | ||||||
} else { | ||||||
return false | ||||||
} | ||||||
} | ||||||
.assign(to: \.isValidPasswordHasNumber, on: self) | ||||||
.store(in: &cancelableSet) | ||||||
|
||||||
$password | ||||||
.receive(on: RunLoop.main) | ||||||
.map { | ||||||
password in | ||||||
let pattern = "[!@#$%^&*]" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if let _ = password.range(of: pattern, options: .regularExpression) { | ||||||
return true | ||||||
} else { | ||||||
return false | ||||||
} | ||||||
} | ||||||
.assign(to: \.isValidPasswordHasSpecialCharacter, on: self) | ||||||
.store(in: &cancelableSet) | ||||||
|
||||||
$passwordConfirm | ||||||
.receive(on: RunLoop.main) | ||||||
.map{ | ||||||
passwordConfirm in | ||||||
return self.password == passwordConfirm | ||||||
} | ||||||
.assign(to: \.isValidPasswordMatch, on: self) | ||||||
.store(in: &cancelableSet) | ||||||
|
||||||
Publishers.CombineLatest($password, $passwordConfirm) | ||||||
.receive(on: RunLoop.main) | ||||||
|
@@ -80,15 +148,27 @@ struct SignUpView: View { | |||||
.bold() | ||||||
.foregroundStyle(.maryBlue) | ||||||
.padding(.bottom, 30) | ||||||
FormTextField(name: "Username", value: $vm.username) | ||||||
RequirementText(text: "A minimum of 4 characters", isValid: vm.isValidUsernameLength) | ||||||
FormTextField(name: "e-mail", value: $vm.username) | ||||||
.autocorrectionDisabled() | ||||||
.textInputAutocapitalization(.never) | ||||||
.keyboardType(.emailAddress) | ||||||
|
||||||
RequirementText(text: "This field should be an email", isValid: vm.isValidUsernameLength) | ||||||
.padding() | ||||||
|
||||||
|
||||||
FormTextField(name: "Password", value: $vm.password, isSecure: true) | ||||||
VStack { | ||||||
RequirementText(text: "A minimum of 8 characters", isValid: vm.isValidPasswordLength) | ||||||
RequirementText(text: "One uppercase letter", isValid: vm.isValidPasswordUpperCase) | ||||||
RequirementText(text: "One lowercase letter", isValid: vm.isValidPasswordLowerCase) | ||||||
RequirementText(text: "One special character", isValid: vm.isValidPasswordHasSpecialCharacter) | ||||||
RequirementText(text: "At least one number", isValid: vm.isValidPasswordHasNumber) | ||||||
|
||||||
} | ||||||
.padding() | ||||||
|
||||||
|
||||||
FormTextField(name: "Confirm Password", value: $vm.passwordConfirm, isSecure: true) | ||||||
RequirementText(text: "Your confirm password should be the same as password", isValid: vm.isValidPasswordMatch) | ||||||
.padding() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File not needed on PR