Skip to content

Commit

Permalink
Merge pull request #92 from wordpress-mobile/try/fix-bug-login-in-wit…
Browse files Browse the repository at this point in the history
…h-site-adress

Fixes login with site address.
  • Loading branch information
diegoreymendez authored May 5, 2019
2 parents db4418b + 9e5ac49 commit d7283bd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion WordPressAuthenticator/Model/LoginFields+Validation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ extension LoginFields {
/// Returns *true* if the siteURL contains a valid URL. False otherwise.
///
func validateSiteForSignin() -> Bool {
return siteAddress.isValidURL()
guard let url = URL(string: NSURL.idnEncodedURL(siteAddress)) else {
return false
}

return !url.absoluteString.isEmpty
}

/// Returns *true* if the credentials required for account creation have been provided.
Expand Down
2 changes: 1 addition & 1 deletion WordPressAuthenticator/Services/LoginFacade.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ - (void)signInToSelfHosted:(LoginFields *)loginFields

[self.delegate displayLoginMessage:NSLocalizedString(@"Authenticating", nil)];

NSString *siteUrl = [NSURL IDNEncodedURL:loginFields.siteAddress];
NSString *siteUrl = [NSURL IDNEncodedURL: loginFields.siteAddress];
[self.wordpressXMLRPCAPIFacade guessXMLRPCURLForSite:siteUrl success:guessXMLRPCURLSuccess failure:guessXMLRPCURLFailure];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,16 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder
view.endEditing(true)
displayError(message: "")

let siteAddress = WordPressAuthenticator.baseSiteURL(string: loginFields.siteAddress)
// We need to to this here because before this point we need the URL to be pre-validated
// exactly as the user inputs it, and after this point we need the URL to be the base site URL.
// This isn't really great, but it's the only sane solution I could come up with given the current
// architecture of this pod.
loginFields.siteAddress = WordPressAuthenticator.baseSiteURL(string: loginFields.siteAddress)

configureViewLoading(true)

let facade = WordPressXMLRPCAPIFacade()
facade.guessXMLRPCURL(forSite: siteAddress, success: { [weak self] (url) in
facade.guessXMLRPCURL(forSite: loginFields.siteAddress, success: { [weak self] (url) in
// Success! We now know that we have a valid XML-RPC endpoint.
// At this point, we do NOT know if this is a WP.com site or a self-hosted site.
if let url = url {
Expand Down Expand Up @@ -302,7 +306,7 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder

// MARK: - URL Validation

/// Does a local / quick Site Adrress validation and refreshes the UI with an error
/// Does a local / quick Site Address validation and refreshes the UI with an error
/// if necessary.
///
/// - Returns: `true` if the Site Address contains a valid URL. `false` otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LoginFieldsValidationTests: XCTestCase {
XCTAssertFalse(loginFields.validateSiteForSignin(), "Empty site should not validate.")

loginFields.siteAddress = "hostname"
XCTAssertFalse(loginFields.validateSiteForSignin(), "Since we want to validate simple mistakes, to use a hostname you'll need an http:// or https:// prefix.")
XCTAssertTrue(loginFields.validateSiteForSignin(), "Hostnames should validate.")

loginFields.siteAddress = "http://hostname"
XCTAssert(loginFields.validateSiteForSignin(), "Since we want to validate simple mistakes, to use a hostname you'll need an http:// or https:// prefix.")
Expand Down

0 comments on commit d7283bd

Please sign in to comment.