@@ -11,6 +11,14 @@ class JetpackLoginViewController: UIViewController {
1111
1212 var blog : Blog
1313
14+ // This variable is used to prevent signing into another WP.com account, if the site is not connected to the already signed-in default account.
15+ private var shouldDisableLogin : Bool {
16+ guard let defaultAccount = try ? WPAccount . lookupDefaultWordPressComAccount ( in: ContextManager . shared. mainContext) else {
17+ return false
18+ }
19+ return defaultAccount. email != blog. jetpack? . connectedEmail
20+ }
21+
1422 // MARK: - Properties
1523
1624 // Defaulting to stats because since that one is written in ObcC we don't have access to the enum there.
@@ -118,7 +126,11 @@ class JetpackLoginViewController: UIViewController {
118126 if jetpack. isSiteConnection {
119127 message = promptType. connectMessage
120128 } else if jetpack. isConnected {
121- message = jetpack. isUpdatedToRequiredVersion ? Constants . Jetpack. isUpdated : Constants . Jetpack. updateRequired
129+ if let connectedEmail = jetpack. connectedEmail, shouldDisableLogin {
130+ message = Constants . Jetpack. connectToDefaultAccount ( connectedEmail: connectedEmail)
131+ } else {
132+ message = jetpack. isUpdatedToRequiredVersion ? Constants . Jetpack. isUpdated : Constants . Jetpack. updateRequired
133+ }
122134 } else {
123135 message = promptType. installMessage
124136 }
@@ -136,7 +148,7 @@ class JetpackLoginViewController: UIViewController {
136148 connectUserButton. contentEdgeInsets = UIEdgeInsets ( top: 12 , left: 20 , bottom: 12 , right: 20 )
137149
138150 signinButton. setTitle ( Constants . Buttons. loginTitle, for: . normal)
139- signinButton. isHidden = !( blog. hasJetpack && !jetpack. isSiteConnection)
151+ signinButton. isHidden = shouldDisableLogin || !( blog. hasJetpack && !jetpack. isSiteConnection)
140152
141153 let paragraph = NSMutableParagraphStyle ( minLineHeight: WPStyleGuide . fontSizeForTextStyle ( . footnote) ,
142154 lineBreakMode: . byWordWrapping,
@@ -338,5 +350,11 @@ private enum Constants {
338350 comment: " Message stating the minimum required " +
339351 " version for Jetpack and asks the user " +
340352 " if they want to upgrade " ) , JetpackState . minimumVersionRequired)
353+ static func connectToDefaultAccount( connectedEmail: String ) -> String {
354+ String . localizedStringWithFormat (
355+ NSLocalizedString ( " jetpackSite.connectToDefaultAccount " , value: " You need to sign in with %@ to use Stats and Notifications. " , comment: " Message stating that the user is unable to use Stats and Notifications because their site is connected to a different WordPress.com account " ) ,
356+ connectedEmail
357+ )
358+ }
341359 }
342360}
0 commit comments