 // MARK: Text field validation
 extension JoinViewController {
 
-    private func allFieldsValid() -> Bool {
-        return validateEmail(emailField.text) && validateUsername(usernameField.text) && validatePassword(passwordField.text)
+    private func allFieldsValid(#email: String, username: String, password: String) -> Bool {
+        return emailIsValid(email) && usernameIsValid(username) && passwordIsValid(password)
     }
 
     private func extraHeight() -> CGFloat {

        })
    }

    private func validateUsername(text: String) -> Bool {
        if text.isEmpty {
            self.hideMessageLabel()
            let msg = NSLocalizedString("Username is required.", comment: "username is required message")
            self.showErrorLabel(msg)
            return false
        }
        else {
            return true
        }
    }

    private func validatePassword(text: String) -> Bool {
        if text.isValidPassword() {
            self.hideErrorLabel()
            return true
        }
        else {
            let msg = NSLocalizedString("Password must be at least 8\ncharacters long.", comment: "password length error message")
            self.showErrorLabel(msg)
            return false
        }
    }


            }
        }
        else {
            if let msg = emailErrorMessage(email) {
                self.showErrorLabel(msg)
            }
            else if let msg = usernameErrorMessage(username) {
                self.showErrorLabel(msg)
            }
            else if let msg = passwordErrorMessage(email) {
                self.showErrorLabel(msg)
            }

            Tracker.sharedTracker.joinInvalid()
        }
    }
