-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChangePasswordPanelController.j
74 lines (64 loc) · 2.39 KB
/
ChangePasswordPanelController.j
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
// (c) 2010-2011 by Anton Korenyushkin
@import "RequestPanelController.j"
@implementation ChangePasswordPanelController : RequestPanelController
{
@outlet CPTextField oldPasswordLabel;
@outlet CPTextField oldPasswordField;
@outlet CPTextField newPasswordLabel;
@outlet CPTextField newPasswordField;
@outlet CPTextField confirmLabel;
@outlet CPTextField confirmField;
@outlet CPButton changeButton;
}
- (void)init // public
{
return [super initWithWindowCibName:"ChangePasswordPanel"];
}
- (void)awakeFromCib // private
{
[oldPasswordLabel, newPasswordLabel, confirmLabel].forEach(
function (label) { [label setAlignment:CPRightTextAlignment]; });
[oldPasswordField, newPasswordField, confirmField].forEach(
function (field) { [field setSecure:YES]; });
[changeButton setEnabled:NO];
[changeButton setKeyEquivalent:CPCarriageReturnCharacter];
}
- (void)controlTextDidChange:(id)sender // private
{
[changeButton setEnabled:[oldPasswordField stringValue] && [newPasswordField stringValue] && [confirmField stringValue]];
}
- (@action)changePassword:(id)sender // private
{
var newPassword = [newPasswordField stringValue];
if ([confirmField stringValue] == newPassword)
[self requestWithMethod:"POST"
URL:"/password"
data:{"old": [oldPasswordField stringValue], "new": newPassword}];
else
[[[Alert alloc] initWithMessage:"The new password and its confirmation don't match."
comment:"Please retype the new password twice."
target:self
action:@selector(didEndMatchErrorSheet)]
showSheetForWindow:[self window]];
}
- (void)didEndRequestErrorSheet:(Alert)sender // protected
{
[oldPasswordField setStringValue:""];
[changeButton setEnabled:NO];
[[self window] makeFirstResponder:oldPasswordField];
}
- (void)didEndMatchErrorSheet // private
{
[newPasswordField setStringValue:""];
[confirmField setStringValue:""];
[changeButton setEnabled:NO];
[[self window] makeFirstResponder:newPasswordField];
}
- (void)didReceiveResponse:(JSObject)data // protected
{
[[self window] close];
[oldPasswordField, newPasswordField, confirmField].forEach(
function (field) { [field setStringValue:""]; });
[changeButton setEnabled:NO];
}
@end