• R/O
  • HTTP
  • SSH
  • HTTPS

Tombo: Commit

TOMBO source code


Commit MetaInfo

Revisione3b2310ec5f7cfd656fe656871f26f46e87cad38 (tree)
Time2012-04-12 22:05:07
AuthorHirami <tomohisa.hirami@nift...>
CommiterHirami

Log Message

Support password timeout.

Change Summary

Incremental Difference

--- a/iOS/Tombo/Tombo/PasswordManager.h
+++ b/iOS/Tombo/Tombo/PasswordManager.h
@@ -4,6 +4,8 @@
44
55 @property (strong,nonatomic) NSString *password;
66
7+- (id)init;
8+
79 /*
810 * If current password is not set (including timeout), popup dialog and ask to user. Or not, do nothing.
911 * Note user may be cancel and finally prepare may be failed.
@@ -11,5 +13,9 @@
1113 */
1214 - (BOOL)preparePassword;
1315
16+/*
17+ * Like preparePassword, but this method show password dialog twice. Second input is used to confirm
18+ * the password is correct.
19+ */
1420 - (BOOL)preparePasswordConfirm;
1521 @end
--- a/iOS/Tombo/Tombo/PasswordManager.m
+++ b/iOS/Tombo/Tombo/PasswordManager.m
@@ -1,35 +1,68 @@
11 #import "PasswordManager.h"
22 #import "SinglePasswordDialog.h"
33
4-@implementation PasswordManager
4+@implementation PasswordManager {
5+ NSTimer *timer;
6+}
57
68 @synthesize password = _password;
79
10+- (id)init {
11+ id obj = [super init];
12+ self.password = nil;
13+ return obj;
14+}
15+
816 - (BOOL)preparePassword {
9- SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password"
10- message:@"Please input password"];
11- NSString *pass = [dialog showAndWait];
12- if (pass == nil) return NO;
13-
14- self.password = pass;
17+ if (!self.password) {
18+ SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password"
19+ message:@"Please input password"];
20+ NSString *pass = [dialog showAndWait];
21+ if (pass == nil) return NO;
22+
23+ self.password = pass;
24+ }
25+
26+ [self resetTimer];
1527 return YES;
1628 }
1729
1830 - (BOOL)preparePasswordConfirm {
19- SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password"
20- message:@"Please input password"];
21- NSString *pass1 = [dialog showAndWait];
22- if (pass1 == nil) return NO;
23-
24- dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Confirm" message:@"Input password again"];
25- NSString *pass2 = [dialog showAndWait];
26- if (pass2 == nil) return NO;
27-
28- if (![pass1 isEqualToString:pass2]) {
29- UIAlertView *mismatch = [[UIAlertView alloc] initWithTitle:@"Warn" message:@"Password mismatch." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
30- [mismatch show];
31- return NO;
31+ if (!self.password) {
32+ SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password"
33+ message:@"Please input password"];
34+ NSString *pass1 = [dialog showAndWait];
35+ if (pass1 == nil) return NO;
36+
37+ dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Confirm" message:@"Input password again"];
38+ NSString *pass2 = [dialog showAndWait];
39+ if (pass2 == nil) return NO;
40+
41+ if (![pass1 isEqualToString:pass2]) {
42+ UIAlertView *mismatch = [[UIAlertView alloc] initWithTitle:@"Warn"
43+ message:@"Password mismatch."
44+ delegate:nil cancelButtonTitle:@"OK"
45+ otherButtonTitles:nil];
46+ [mismatch show];
47+ return NO;
48+ }
3249 }
50+
51+ [self resetTimer];
52+
3353 return YES;
3454 }
55+
56+- (void)resetTimer {
57+ if (timer) [timer invalidate];
58+ timer = [NSTimer scheduledTimerWithTimeInterval:60
59+ target:self
60+ selector:@selector(fireTimer:)
61+ userInfo:nil
62+ repeats:NO];
63+}
64+
65+- (void)fireTimer:(NSTimer *)timer {
66+ self.password = nil;
67+}
3568 @end
Show on old repository browser