-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathAuthenticationFailureController.m
More file actions
119 lines (94 loc) · 4.85 KB
/
AuthenticationFailureController.m
File metadata and controls
119 lines (94 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// AuthenticationFailureController.m
// Telephone
//
// Copyright © 2008-2016 Alexey Kuznetsov
// Copyright © 2016-2022 64 Characters
//
// Telephone is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Telephone is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
#import "AuthenticationFailureController.h"
#import "AKSIPUserAgent.h"
#import "AKKeychain.h"
#import "AccountController.h"
#import "AppController.h"
#import "SIPResponseLocalization.h"
NSString * const AKAuthenticationFailureControllerDidChangeUsernameAndPasswordNotification
= @"AKAuthenticationFailureControllerDidChangeUsernameAndPassword";
@implementation AuthenticationFailureController
- (instancetype)initWithAccountController:(AccountController *)accountController userAgent:(AKSIPUserAgent *)userAgent {
self = [super initWithWindowNibName:@"AuthenticationFailure"];
if (self != nil) {
_accountController = accountController;
_userAgent = userAgent;
}
return self;
}
- (void)awakeFromNib {
[[self informativeText] setStringValue:
[NSString stringWithFormat:
NSLocalizedString(@"Telephone was unable to login to %@. Change user name or password and try again.",
@"Registrar authentication failed."), self.accountController.account.registrar]];
NSString *username = [[[self accountController] account] username];
NSString *service = [NSString stringWithFormat:@"SIP: %@", [[[self accountController] account] registrar]];
NSString *password = [AKKeychain passwordForService:service account:username];
[[self usernameField] setStringValue:username];
[[self passwordField] setStringValue:password];
}
- (IBAction)closeSheet:(id)sender {
[self.window.sheetParent endSheet:self.window];
}
- (IBAction)changeUsernameAndPassword:(id)sender {
[self closeSheet:sender];
NSCharacterSet *spacesSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *username = [[[self usernameField] stringValue] stringByTrimmingCharactersInSet:spacesSet];
if ([username length] > 0) {
[[self accountController] removeAccountFromUserAgent];
[[[self accountController] account] updateUsername:username];
[[self accountController] showConnectingState];
// Add account to the user agent.
[[self userAgent] addAccount:[[self accountController] account]
withPassword:[[self passwordField] stringValue]];
// Error connecting to registrar.
if (![[self accountController] isAccountRegistered] &&
[[[self accountController] account] registrationExpireTime] == kAKSIPAccountRegistrationExpireTimeNotSpecified) {
[[self accountController] showUnavailableState];
NSString *statusText;
NSString *preferredLocalization = [[NSBundle mainBundle] preferredLocalizations][0];
if ([preferredLocalization isEqualToString:@"ru"]) {
statusText = LocalizedStringForSIPResponseCode([[[self accountController] account] registrationStatus]);
} else {
statusText = [[[self accountController] account] registrationStatusText];
}
NSString *error;
if (statusText == nil) {
error = [NSString stringWithFormat:
NSLocalizedString(@"Error %ld", @"Error #."),
[[[self accountController] account] registrationStatus]];
error = [error stringByAppendingString:@"."];
} else {
error = [NSString stringWithFormat:
NSLocalizedString(@"The error was: “%ld %@”.", @"Error description."),
[[[self accountController] account] registrationStatus], statusText];
}
[[self accountController] showRegistrarConnectionErrorSheetWithError:error];
}
if ([[self mustSaveCheckBox] state] == NSControlStateValueOn) {
NSString *service = [NSString stringWithFormat:@"SIP: %@", [[[self accountController] account] registrar]];
[AKKeychain addItemWithService:service account:username password:[[self passwordField] stringValue]];
}
[[NSNotificationCenter defaultCenter]
postNotificationName:AKAuthenticationFailureControllerDidChangeUsernameAndPasswordNotification
object:self];
}
[[self passwordField] setStringValue:@""];
}
@end