Bug #4519 - added proper handling of authentication failure

This commit is contained in:
Andrzej Wójcik 2016-09-05 19:46:25 +02:00
parent 1b834ddb8d
commit af8aab9ac6
No known key found for this signature in database
GPG key ID: 2BE28BB9C1B5FF02
3 changed files with 45 additions and 4 deletions

View file

@ -51,6 +51,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.newMessage), name: DBChatHistoryStore.MESSAGE_NEW, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.chatItemsUpdated), name: DBChatHistoryStore.CHAT_ITEMS_UPDATED, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.serverCertificateError), name: "serverCertificateError", object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.authenticationFailure), name: "authenticationFailure", object: nil);
updateApplicationIconBadgeNumber();
application.setMinimumBackgroundFetchInterval(60);
@ -142,6 +143,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
topController = topController?.presentedViewController;
}
topController?.presentViewController(alert, animated: true, completion: nil);
}
if let authError = userInfo["auth-error-type"] {
let accountJid = BareJID(userInfo["account"] as! String);
let alert = UIAlertController(title: "Authentication issue", message: "Authentication for account \(accountJid) failed: \(authError)\nVerify provided account password.", preferredStyle: .Alert);
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil));
var topController = UIApplication.sharedApplication().keyWindow?.rootViewController;
while (topController?.presentedViewController != nil) {
topController = topController?.presentedViewController;
}
topController?.presentViewController(alert, animated: true, completion: nil);
}
}
@ -228,6 +242,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
userNotification.category = "ERROR";
UIApplication.sharedApplication().presentLocalNotificationNow(userNotification);
}
func authenticationFailure(notification: NSNotification) {
guard let info = notification.userInfo else {
return;
}
let account = BareJID(info["account"] as! String);
let type = info["auth-error-type"] as! String;
let userNotification = UILocalNotification();
userNotification.alertAction = "fix";
userNotification.alertBody = "Authentication for account \(account) failed: \(type)";
userNotification.userInfo = info;
userNotification.category = "ERROR";
UIApplication.sharedApplication().presentLocalNotificationNow(userNotification);
}
}

View file

@ -11,7 +11,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Tigase iOS Messenger</string>
<string>Tigase Messenger</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>

View file

@ -26,7 +26,7 @@ import TigaseSwift
public class XmppService: Logger, EventHandler {
public var fetchTimeShort: NSTimeInterval = 5;
public var fetchTimeLong: NSTimeInterval = 25;
public var fetchTimeLong: NSTimeInterval = 20;
private var creationDate = NSDate();
@ -189,7 +189,7 @@ public class XmppService: Logger, EventHandler {
}
private func registerEventHandlers(client:XMPPClient) {
client.eventBus.register(self, events: SocketConnector.DisconnectedEvent.TYPE, DiscoveryModule.ServerFeaturesReceivedEvent.TYPE, PresenceModule.BeforePresenceSendEvent.TYPE, SessionEstablishmentModule.SessionEstablishmentSuccessEvent.TYPE, SocketConnector.CertificateErrorEvent.TYPE);
client.eventBus.register(self, events: SocketConnector.DisconnectedEvent.TYPE, DiscoveryModule.ServerFeaturesReceivedEvent.TYPE, PresenceModule.BeforePresenceSendEvent.TYPE, SessionEstablishmentModule.SessionEstablishmentSuccessEvent.TYPE, SocketConnector.CertificateErrorEvent.TYPE, AuthModule.AuthFailedEvent.TYPE);
client.eventBus.register(dbChatHistoryStore, events: MessageModule.MessageReceivedEvent.TYPE, MessageCarbonsModule.CarbonReceivedEvent.TYPE, MucModule.MessageReceivedEvent.TYPE);
for holder in eventHandlers {
client.eventBus.register(holder.handler, events: holder.events);
@ -197,7 +197,7 @@ public class XmppService: Logger, EventHandler {
}
private func unregisterEventHandlers(client:XMPPClient) {
client.eventBus.unregister(self, events: SocketConnector.DisconnectedEvent.TYPE, DiscoveryModule.ServerFeaturesReceivedEvent.TYPE, PresenceModule.BeforePresenceSendEvent.TYPE, SessionEstablishmentModule.SessionEstablishmentSuccessEvent.TYPE, SocketConnector.CertificateErrorEvent.TYPE);
client.eventBus.unregister(self, events: SocketConnector.DisconnectedEvent.TYPE, DiscoveryModule.ServerFeaturesReceivedEvent.TYPE, PresenceModule.BeforePresenceSendEvent.TYPE, SessionEstablishmentModule.SessionEstablishmentSuccessEvent.TYPE, SocketConnector.CertificateErrorEvent.TYPE, AuthModule.AuthFailedEvent.TYPE);
client.eventBus.unregister(dbChatHistoryStore, events: MessageModule.MessageReceivedEvent.TYPE, MessageCarbonsModule.CarbonReceivedEvent.TYPE, MucModule.MessageReceivedEvent.TYPE);
for holder in eventHandlers {
client.eventBus.unregister(holder.handler, events: holder.events);
@ -283,6 +283,17 @@ public class XmppService: Logger, EventHandler {
}
}
reconnectMucRooms(e.sessionObject.userBareJid!);
case let e as AuthModule.AuthFailedEvent:
if let account = AccountManager.getAccount(e.sessionObject.userBareJid!.stringValue) {
account.active = false;
AccountManager.updateAccount(account, notifyChange: true);
}
var info: [String: AnyObject] = [:];
info["account"] = e.sessionObject.userBareJid!.stringValue;
info["auth-error-type"] = e.error.rawValue;
dispatch_async(dispatch_get_main_queue()) {
NSNotificationCenter.defaultCenter().postNotificationName("authenticationFailure", object: self, userInfo: info);
}
default:
log("received unsupported event", event);
}