root / Classes / ResetServerAdminPasswordViewController.m @ 9fee07a6
History | View | Annotate | Download (3.8 kB)
1 |
// |
---|---|
2 |
// ResetServerAdminPasswordViewController.m |
3 |
// OpenStack |
4 |
// |
5 |
// Created by Mike Mayo on 2/9/10. |
6 |
// The OpenStack project is provided under the Apache 2.0 license. |
7 |
// |
8 |
|
9 |
#import "ResetServerAdminPasswordViewController.h" |
10 |
#import "ServerViewController.h" |
11 |
#import "RSTextFieldCell.h" |
12 |
#import "UIViewController+Conveniences.h" |
13 |
|
14 |
@implementation ResetServerAdminPasswordViewController |
15 |
|
16 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { |
17 |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); |
18 |
} |
19 |
|
20 |
#pragma mark - |
21 |
#pragma mark View lifecycle |
22 |
|
23 |
- (void)viewDidLoad { |
24 |
[super viewDidLoad]; |
25 |
} |
26 |
|
27 |
- (void)viewWillAppear:(BOOL)animated { |
28 |
[super viewWillAppear:animated]; |
29 |
[textField becomeFirstResponder]; |
30 |
} |
31 |
|
32 |
#pragma mark - |
33 |
#pragma mark Table view data source |
34 |
|
35 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
36 |
return 1; |
37 |
} |
38 |
|
39 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
40 |
return 2; |
41 |
} |
42 |
|
43 |
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { |
44 |
return @"The root password will be updated and the server will be restarted. This process will only work if you have a user line for \"root\" in your passwd or shadow file."; |
45 |
} |
46 |
|
47 |
// Customize the appearance of table view cells. |
48 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
49 |
|
50 |
if (indexPath.row == 0) { |
51 |
static NSString *CellIdentifier = @"Cell"; |
52 |
RSTextFieldCell *cell = (RSTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
53 |
if (cell == nil) { |
54 |
cell = [[[RSTextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; |
55 |
cell.modalPresentationStyle = UIModalPresentationFormSheet; |
56 |
textField = cell.textField; |
57 |
textField.text = @""; |
58 |
textField.secureTextEntry = YES; |
59 |
textField.returnKeyType = UIReturnKeyNext; |
60 |
textField.delegate = self; |
61 |
} |
62 |
cell.textLabel.text = @"Password"; |
63 |
return cell; |
64 |
} else { |
65 |
static NSString *CellIdentifier = @"ConfirmCell"; |
66 |
RSTextFieldCell *cell = (RSTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
67 |
if (cell == nil) { |
68 |
cell = [[[RSTextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; |
69 |
cell.modalPresentationStyle = UIModalPresentationFormSheet; |
70 |
confirmTextField = cell.textField; |
71 |
confirmTextField.text = @""; |
72 |
confirmTextField.secureTextEntry = YES; |
73 |
confirmTextField.delegate = self; |
74 |
} |
75 |
cell.textLabel.text = @"Confirm"; |
76 |
return cell; |
77 |
} |
78 |
|
79 |
} |
80 |
|
81 |
#pragma mark - |
82 |
#pragma mark UITextFieldDelegate |
83 |
|
84 |
- (BOOL)textFieldShouldReturn:(UITextField *)aTextField { |
85 |
if ([textField isEqual:aTextField]) { |
86 |
[textField resignFirstResponder]; |
87 |
[confirmTextField becomeFirstResponder]; |
88 |
} else { |
89 |
[self saveButtonPressed:nil]; |
90 |
} |
91 |
return NO; |
92 |
} |
93 |
|
94 |
#pragma mark - |
95 |
#pragma mark Button Handlers |
96 |
|
97 |
-(void)saveButtonPressed:(id)sender { |
98 |
if ([textField.text isEqualToString:@""]) { |
99 |
[self alert:@"Error" message:@"Please enter a new password."]; |
100 |
} else if ([confirmTextField.text isEqualToString:@""]) { |
101 |
[self alert:@"Error" message:@"Please confirm your new password."]; |
102 |
} else if (![textField.text isEqualToString:confirmTextField.text]) { |
103 |
[self alert:@"Error" message:@"The password and confirmation do not match."]; |
104 |
} else { |
105 |
[self.serverViewController changeAdminPassword:textField.text]; |
106 |
[self dismissModalViewControllerAnimated:YES]; |
107 |
[self.serverViewController.tableView deselectRowAtIndexPath:actionIndexPath animated:YES]; |
108 |
} |
109 |
} |
110 |
|
111 |
#pragma mark - |
112 |
#pragma mark Memory management |
113 |
|
114 |
- (void)dealloc { |
115 |
[super dealloc]; |
116 |
} |
117 |
|
118 |
@end |