@@ -194,6 +194,77 @@ import WordPressKit
194194 showGetStarted ( from: presenter, jetpackLogin: jetpackLogin, connectedEmail: connectedEmail, siteURL: siteURL)
195195 }
196196
197+ /// Used to present the Verify Email flow from the app delegate.
198+ ///
199+ /// - Parameters:
200+ /// - presenter: The view controller that presents the Verify Email view.
201+ /// - xmlrpc: The URL to reach the XMLRPC file of the site to log in to.
202+ /// - connectedEmail: The email address used to authorized Jetpack connection with the site.
203+ /// - siteURL: The URL of the site to log in to.
204+ ///
205+ @objc public class func showVerifyEmailForWPCom( from presenter: UIViewController , xmlrpc: String , connectedEmail: String , siteURL: String ) {
206+ guard let xmlrpcURL = URL ( string: xmlrpc) else {
207+ DDLogError ( " Failed to initiate XML-RPC URL from \( xmlrpc) " )
208+ return
209+ }
210+ let loginFields = LoginFields ( )
211+ loginFields. meta. xmlrpcURL = xmlrpcURL as NSURL
212+ loginFields. username = connectedEmail
213+ loginFields. siteAddress = siteURL
214+
215+ guard let vc = VerifyEmailViewController . instantiate ( from: . verifyEmail) else {
216+ DDLogError ( " Failed to navigate to VerifyEmailViewController " )
217+ return
218+ }
219+
220+ vc. loginFields = loginFields
221+ let navController = LoginNavigationController ( rootViewController: vc)
222+ navController. modalPresentationStyle = . fullScreen
223+ presenter. present ( navController, animated: true , completion: nil )
224+ }
225+
226+ /// Used to present the site credential login flow directly from the delegate.
227+ ///
228+ /// - Parameters:
229+ /// - presenter: The view controller that presents the site credential login flow.
230+ /// - siteURL: The URL of the site to log in to.
231+ /// - onCompletion: The closure to be trigged when the login succeeds with the input credentials.
232+ ///
233+ public class func showSiteCredentialLogin( from presenter: UIViewController , siteURL: String , onCompletion: @escaping ( WordPressOrgCredentials ) -> Void ) {
234+ let controller = SiteCredentialsViewController . instantiate ( from: . siteAddress) { coder in
235+ SiteCredentialsViewController ( coder: coder, isDismissible: true , onCompletion: onCompletion)
236+ }
237+ guard let controller = controller else {
238+ DDLogError ( " Failed to navigate from GetStartedViewController to SiteCredentialsViewController " )
239+ return
240+ }
241+
242+ let loginFields = LoginFields ( )
243+ loginFields. siteAddress = siteURL
244+ controller. loginFields = loginFields
245+ controller. dismissBlock = { _ in
246+ controller. navigationController? . dismiss ( animated: true )
247+ }
248+
249+ let navController = LoginNavigationController ( rootViewController: controller)
250+ navController. modalPresentationStyle = . fullScreen
251+ presenter. present ( navController, animated: true , completion: nil )
252+ }
253+
254+ /// A helper method to fetch site info for a given URL.
255+ /// - Parameters:
256+ /// - siteURL: The URL of the site to fetch information for.
257+ /// - onCompletion: The closure to be triggered when fetching site info is done.
258+ ///
259+ public class func fetchSiteInfo( for siteURL: String , onCompletion: @escaping ( Result < WordPressComSiteInfo , Error > ) -> Void ) {
260+ let service = WordPressComBlogService ( )
261+ service. fetchUnauthenticatedSiteInfoForAddress ( for: siteURL, success: { siteInfo in
262+ onCompletion ( . success( siteInfo) )
263+ } , failure: { error in
264+ onCompletion ( . failure( error) )
265+ } )
266+ }
267+
197268 /// Shows the unified Login/Signup flow.
198269 ///
199270 private class func showGetStarted( from presenter: UIViewController , jetpackLogin: Bool , connectedEmail: String ? = nil , siteURL: String ? = nil ) {
0 commit comments