forked from cubewang/NewsReader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordViewController.m
203 lines (154 loc) · 7.03 KB
/
PasswordViewController.m
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
// ChangePasswordViewController.m
// EnglishFun
//
// Created by cg on 12-8-15.
// Copyright (c) 2012年 iKnow Team. All rights reserved.
//
#import "PasswordViewController.h"
#import "XMPPiKnowUserModule.h"
#import "ArticleDownloader.h"
#import "MessageManager.h"
@implementation PasswordViewController
@synthesize newPasswordTextField;
@synthesize confirmPasswordTextField;
@synthesize tableView;
@synthesize backButton,completeButton;
@synthesize navBar;
- (XMPPiKnowUserModule *)getUserModule
{
return[[[EnglishFunAppDelegate sharedAppDelegate] getXMPPClient] xmppiKnowUserModule];
}
- (IBAction)closeAction:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)savePassword
{
if ([newPasswordTextField.text length] == 0
|| [confirmPasswordTextField.text length] == 0) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"提示", @"")
message:NSLocalizedString(@"密码不能为空", @"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"确定", @"")
otherButtonTitles:nil];
[alertView show];
[alertView release];
return;
}
//验证密码长度,密码有可能为空
if ((newPasswordTextField.text.length > 0 && newPasswordTextField.text.length < PASSWORD_MIN_LENGTH) || newPasswordTextField.text.length > PASSWORD_MAX_LENGTH) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"提示", @"")
message:[NSString stringWithFormat:NSLocalizedString(@"密码长度需要在%d~%d之间", @""), PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH] delegate:self
cancelButtonTitle:NSLocalizedString(@"确定", @"")
otherButtonTitles:nil];
[alertView show];
[alertView release];
return;
}
//验证密码与确认密码是否一致
if (![newPasswordTextField.text isEqualToString:confirmPasswordTextField.text] && ![confirmPasswordTextField.text isEqualToString:@""]) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"提示", @"")
message:NSLocalizedString(@"两次输入的密码不一致", @"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"确定", @"")
otherButtonTitles:nil];
[alertView show];
[alertView release];
return;
}
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
BOOL bRes = [[self getUserModule] changePassword:newPasswordTextField.text];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSString *message = bRes ? NSLocalizedString(@"修改密码成功", @"") : NSLocalizedString(@"修改密码失败", @"");
UIAlertView *view = [[UIAlertView alloc] initWithTitle:nil
message:message
delegate:nil
cancelButtonTitle:NSLocalizedString(@"确定", @"")
otherButtonTitles:nil
];
[view show];
[view release];
});
});
[self closeAction:nil];
}
/*
- (id)initWithStyle:(UITableViewStyle)style
{
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
// Custom initialization.
}
return self;
}*/
- (void)viewDidLoad
{
[super viewDidLoad];
[self.backButton setTitle:NSLocalizedString(@"返回", @"") forState:UIControlStateNormal];
[self.completeButton setTitle:NSLocalizedString(@"保存", @"") forState:UIControlStateNormal];
self.navBar.tintColor = NAV_BAR_ITEM_COLOR;
if ([self.navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
[ self.navBar setBackgroundImage:[UIImage imageNamed:@"settingBar_ipad.png"] forBarMetrics:UIBarMetricsDefault];
}
self.navBar.layer.shadowColor = [[UIColor blackColor] CGColor];
self.navBar.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
self.navBar.layer.shadowRadius = 3.0f;
self.navBar.layer.shadowOpacity = 0.8f;
self.view.backgroundColor = self.tableView.backgroundColor = CELL_BACKGROUND;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.userInteractionEnabled = YES;
self.tableView.alpha = 1;
}
- (void)dealloc
{
[newPasswordTextField release];
[confirmPasswordTextField release];
[[ArticleDownloader shareInstance] cancel];
self.backButton = nil;
self.completeButton = nil;
self.navBar = nil;
[super dealloc];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 2;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"SettingCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
CGRect rc = cell.frame;
rc.size.width -= 50;
rc.origin.x += 10;
rc.origin.y += 5;
if (indexPath.row == 0) {
self.newPasswordTextField = [[UITextField alloc] initWithFrame:rc];
self.newPasswordTextField.placeholder = NSLocalizedString(@"密码", @"");
self.newPasswordTextField.secureTextEntry = YES;
[cell.contentView addSubview:newPasswordTextField];
}
else if (indexPath.row == 1){
self.confirmPasswordTextField = [[UITextField alloc] initWithFrame:rc];
self.confirmPasswordTextField.placeholder = NSLocalizedString(@"确认密码", @"");
self.confirmPasswordTextField.secureTextEntry = YES;
[cell.contentView addSubview:confirmPasswordTextField];
}
}
return cell;
}
@end