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

signup exercise succeed #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Member

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

<!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>
86 changes: 83 additions & 3 deletions SwiftUIBasics/Views/SignUpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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> = []
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the username validating email?

.store(in: &cancelableSet)
Expand All @@ -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 = "[!@#$%^&*]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let pattern = "[!@#$%^&*]"
let pattern = "[\\W]"

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)
Expand Down Expand Up @@ -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()
Expand Down