Commit b50303b97d2ca5389db38e585f0675f90e7dcaef

Authored by phong
1 parent 915e7d0c7a

update api

Showing 8 changed files with 270 additions and 85 deletions Side-by-side Diff

LifeLog/LifeLog.xcodeproj/project.pbxproj
... ... @@ -35,6 +35,8 @@
35 35 6EDC8BEE1F2C2FB800765ACC /* Utilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EDC8BED1F2C2FB800765ACC /* Utilities.m */; };
36 36 6EDC8BF41F2C68D700765ACC /* CMMotionActivityExtra.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EDC8BF31F2C68D700765ACC /* CMMotionActivityExtra.m */; };
37 37 6EF1630A1F29069300DA306C /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6EF163091F29069300DA306C /* Localizable.strings */; };
  38 + 9CA8AEEA1F31BB4600C5FC74 /* ConfirmForgetPassViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CA8AEE81F31BB4600C5FC74 /* ConfirmForgetPassViewController.m */; };
  39 + 9CA8AEEB1F31BB4600C5FC74 /* ConfirmForgetPassViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9CA8AEE91F31BB4600C5FC74 /* ConfirmForgetPassViewController.xib */; };
38 40 9CBDA0FA1F2ECE2C0055DED1 /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDA0F91F2ECE2C0055DED1 /* BaseViewController.m */; };
39 41 9CBDA0FF1F2F03810055DED1 /* RegisterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDA0FD1F2F03810055DED1 /* RegisterViewController.m */; };
40 42 9CBDA1001F2F03810055DED1 /* RegisterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9CBDA0FE1F2F03810055DED1 /* RegisterViewController.xib */; };
... ... @@ -109,6 +111,9 @@
109 111 6EDC8BF21F2C68D700765ACC /* CMMotionActivityExtra.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CMMotionActivityExtra.h; sourceTree = "<group>"; };
110 112 6EDC8BF31F2C68D700765ACC /* CMMotionActivityExtra.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CMMotionActivityExtra.m; sourceTree = "<group>"; };
111 113 6EF163091F29069300DA306C /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
  114 + 9CA8AEE71F31BB4600C5FC74 /* ConfirmForgetPassViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConfirmForgetPassViewController.h; sourceTree = "<group>"; };
  115 + 9CA8AEE81F31BB4600C5FC74 /* ConfirmForgetPassViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConfirmForgetPassViewController.m; sourceTree = "<group>"; };
  116 + 9CA8AEE91F31BB4600C5FC74 /* ConfirmForgetPassViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ConfirmForgetPassViewController.xib; sourceTree = "<group>"; };
112 117 9CBDA0F81F2ECE2C0055DED1 /* BaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseViewController.h; sourceTree = "<group>"; };
113 118 9CBDA0F91F2ECE2C0055DED1 /* BaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseViewController.m; sourceTree = "<group>"; };
114 119 9CBDA0FC1F2F03810055DED1 /* RegisterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegisterViewController.h; sourceTree = "<group>"; };
... ... @@ -153,6 +158,7 @@
153 158 6E18CECF1F2E398C0029891F /* Login */ = {
154 159 isa = PBXGroup;
155 160 children = (
  161 + 9CA8AEE61F31BB1200C5FC74 /* ConfirmForgetPass */,
156 162 6E18CED01F2E39DB0029891F /* LoginViewController.h */,
157 163 6E18CED11F2E39DB0029891F /* LoginViewController.m */,
158 164 6E18CED21F2E39DB0029891F /* LoginViewController.xib */,
... ... @@ -358,6 +364,16 @@
358 364 name = Common;
359 365 sourceTree = "<group>";
360 366 };
  367 + 9CA8AEE61F31BB1200C5FC74 /* ConfirmForgetPass */ = {
  368 + isa = PBXGroup;
  369 + children = (
  370 + 9CA8AEE71F31BB4600C5FC74 /* ConfirmForgetPassViewController.h */,
  371 + 9CA8AEE81F31BB4600C5FC74 /* ConfirmForgetPassViewController.m */,
  372 + 9CA8AEE91F31BB4600C5FC74 /* ConfirmForgetPassViewController.xib */,
  373 + );
  374 + name = ConfirmForgetPass;
  375 + sourceTree = "<group>";
  376 + };
361 377 9CBDA0F71F2ECDFD0055DED1 /* BaseViewController */ = {
362 378 isa = PBXGroup;
363 379 children = (
... ... @@ -501,6 +517,7 @@
501 517 9CBDA1001F2F03810055DED1 /* RegisterViewController.xib in Resources */,
502 518 6E18CED41F2E39DB0029891F /* LoginViewController.xib in Resources */,
503 519 6E84E3BB1F27A9A0001EB88E /* RankingViewController.xib in Resources */,
  520 + 9CA8AEEB1F31BB4600C5FC74 /* ConfirmForgetPassViewController.xib in Resources */,
504 521 6E84E3C01F27A9B1001EB88E /* SNSViewController.xib in Resources */,
505 522 6E8DA0F81F2BAC3500CCE941 /* TodayViewController.xib in Resources */,
506 523 6E84E3841F27A701001EB88E /* LaunchScreen.storyboard in Resources */,
... ... @@ -590,6 +607,7 @@
590 607 6E84E3BA1F27A9A0001EB88E /* RankingViewController.m in Sources */,
591 608 6EDC8BF41F2C68D700765ACC /* CMMotionActivityExtra.m in Sources */,
592 609 9CBDA0FF1F2F03810055DED1 /* RegisterViewController.m in Sources */,
  610 + 9CA8AEEA1F31BB4600C5FC74 /* ConfirmForgetPassViewController.m in Sources */,
593 611 6EDC8BEE1F2C2FB800765ACC /* Utilities.m in Sources */,
594 612 6E84E3C51F27ACAE001EB88E /* MapViewController.m in Sources */,
595 613 6E18CEDC1F2E40F50029891F /* User.m in Sources */,
LifeLog/LifeLog/LoginViewController.m
... ... @@ -10,6 +10,8 @@
10 10 #import "ServerAPI.h"
11 11 #import "AppDelegate.h"
12 12 #import "RegisterViewController.h"
  13 +#import "Utilities.h"
  14 +#import "ConfirmForgetPassViewController.h"
13 15  
14 16 @interface LoginViewController ()
15 17 @property (nonatomic, weak) IBOutlet UILabel *lblEmail;
16 18  
... ... @@ -64,31 +66,35 @@
64 66 else {
65 67 dispatch_async(dispatch_get_main_queue(), ^{
66 68 NSString *message = [error.userInfo objectForKey:@"message"];
67   - if (message.length > 0) {
68   - UIAlertController * alert= [UIAlertController
69   - alertControllerWithTitle:@"Error"
70   - message:message
71   - preferredStyle:UIAlertControllerStyleAlert];
72   -
73   - UIAlertAction* ok = [UIAlertAction
74   - actionWithTitle:@"OK"
75   - style:UIAlertActionStyleDefault
76   - handler:^(UIAlertAction * action)
77   - {
78   - [alert dismissViewControllerAnimated:YES completion:nil];
79   -
80   - }];
81   -
82   - [alert addAction:ok];
83   -
84   - [weakSelf presentViewController:alert animated:YES completion:nil];
85   - }
  69 + [Utilities showErrorMessage:message withViewController:weakSelf];
86 70 });
87 71 }
88 72 }];
89 73 }
90 74  
91 75 - (IBAction)buttonForgetTouchUpInside:(id)sender {
  76 + if (_tfEmail.text.length > 0) {
  77 + LoginViewController __weak *weakSelf = self;
  78 + [[ServerAPI server] forgetPass:_tfEmail.text CompletionHandler:^(NSError *error) {
  79 + if (error == nil) {
  80 + // goto screen confirm forgetPass
  81 + dispatch_async(dispatch_get_main_queue(), ^{
  82 + ConfirmForgetPassViewController *confirmVC = [[ConfirmForgetPassViewController alloc] initWithNibName:@"ConfirmForgetPassViewController" bundle:nil];
  83 + confirmVC.email = weakSelf.tfEmail.text;
  84 + [weakSelf.navigationController pushViewController:confirmVC animated:YES];
  85 + });
  86 + }
  87 + else {
  88 + dispatch_async(dispatch_get_main_queue(), ^{
  89 + NSString *message = [error.userInfo objectForKey:@"message"];
  90 + [Utilities showErrorMessage:message withViewController:weakSelf];
  91 + });
  92 + }
  93 + }];
  94 + }
  95 + else {
  96 + [Utilities showErrorMessage:@"Please input email" withViewController:self];
  97 + }
92 98 }
93 99  
94 100 - (IBAction)buttonRegisterTouchUpInside:(id)sender {
LifeLog/LifeLog/RegisterViewController.m
... ... @@ -160,8 +160,9 @@
160 160 }
161 161  
162 162 - (IBAction)registButtonPressed:(id)sender {
163   - NSLog(@"registButtonPressed");
164   - [self registerUser];
  163 + if ([self checkAllowRegister]) {
  164 + [self registerUser];
  165 + }
165 166 }
166 167  
167 168 #pragma mark - UIActionSheetDelegate
... ... @@ -203,7 +204,7 @@
203 204 else {
204 205 dispatch_async(dispatch_get_main_queue(), ^{
205 206 NSString *message = [error.userInfo objectForKey:@"message"];
206   - [weakSelf showErrorMessage:message];
  207 + [Utilities showErrorMessage:message withViewController:weakSelf];
207 208 });
208 209 }
209 210 }];
... ... @@ -413,6 +414,67 @@
413 414 return dict;
414 415 }
415 416  
  417 +- (BOOL)checkAllowRegister
  418 +{
  419 + NSString *message = @"";
  420 + if (_tfUsername.text.length <= 0) {
  421 + message = @"Please input username";
  422 + [Utilities showErrorMessage:message withViewController:self];
  423 + return NO;
  424 + }
  425 + if (_tfName.text.length <= 0) {
  426 + message = @"Please input full name";
  427 + [Utilities showErrorMessage:message withViewController:self];
  428 + return NO;
  429 + }
  430 + if (_tfEmail.text.length <= 0) {
  431 + message = @"Please input email";
  432 + [Utilities showErrorMessage:message withViewController:self];
  433 + return NO;
  434 + }
  435 + if (_tfPassword.text.length <= 0) {
  436 + message = @"Please input password";
  437 + [Utilities showErrorMessage:message withViewController:self];
  438 + return NO;
  439 + }
  440 + if (_tfConfirmPassword.text.length <= 0) {
  441 + message = @"Please input confirm password";
  442 + [Utilities showErrorMessage:message withViewController:self];
  443 + return NO;
  444 + }
  445 + if (_tflblSex.text.length <= 0) {
  446 + message = @"Please input gender";
  447 + [Utilities showErrorMessage:message withViewController:self];
  448 + return NO;
  449 + }
  450 + if (_tfUsername.text.length > 100) {
  451 + message = @"Username maximum length 100";
  452 + [Utilities showErrorMessage:message withViewController:self];
  453 + return NO;
  454 + }
  455 + if (_tfName.text.length > 255) {
  456 + message = @"Full name maximum length 255";
  457 + [Utilities showErrorMessage:message withViewController:self];
  458 + return NO;
  459 + }
  460 + if (_tfEmail.text.length > 255) {
  461 + message = @"Email maximum length 255";
  462 + [Utilities showErrorMessage:message withViewController:self];
  463 + return NO;
  464 + }
  465 + if (_tfPassword.text.length < 6) {
  466 + message = @"Password minimum length 6";
  467 + [Utilities showErrorMessage:message withViewController:self];
  468 + return NO;
  469 + }
  470 + if (![_tfEmail.text containsString:@"@"]) {
  471 + message = @"Email invalid";
  472 + [Utilities showErrorMessage:message withViewController:self];
  473 + return NO;
  474 + }
  475 + return YES;
  476 +}
  477 +
416 478 - (NSDictionary *)createParamsForRegisterUser {
417 479 NSMutableDictionary *dictResutl = [[NSMutableDictionary alloc] init];
418 480 dictResutl = [self addParam:@"username" value:_tfUsername.text withDict:dictResutl];
419 481  
420 482  
421 483  
422 484  
... ... @@ -420,20 +482,24 @@
420 482 dictResutl = [self addParam:@"nickname" value:_tfNickname.text withDict:dictResutl];
421 483 dictResutl = [self addParam:@"email" value:_tfEmail.text withDict:dictResutl];
422 484 dictResutl = [self addParam:@"password" value:_tfPassword.text withDict:dictResutl];
423   - //dictResutl = [self addParam:@"confirm_password" value:_tfConfirmPassword.text withDict:dictResutl];
424   - NSString *valueSex = nil; // 0 - ็”ท, 1 - ๅฅณ
  485 + dictResutl = [self addParam:@"password_confirmation" value:_tfConfirmPassword.text withDict:dictResutl];
  486 + // 0 - ็”ท, 1 - ๅฅณ // NSString *valueSex = nil;
425 487 if (_tflblSex.text.length > 0) {
426 488 if ([_tflblSex.text isEqualToString:@"็”ท"]) {
427   - valueSex = @"0";
  489 + [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"gender"];
428 490 }
429 491 else if ([_tflblSex.text isEqualToString:@"ๅฅณ"]) {
430   - valueSex = @"1";
  492 + [dictResutl setValue:[NSNumber numberWithInt:1] forKey:@"gender"];
431 493 }
432 494 }
433   - dictResutl = [self addParam:@"gender" value:valueSex withDict:dictResutl];
  495 + //dictResutl = [self addParam:@"gender" value:valueSex withDict:dictResutl];
434 496 NSString *valueBirthDay = nil;
435 497 if (_tfBirthday.text.length > 0) {
436   - valueBirthDay = [NSString stringWithFormat:@"%ld-%ld-%ld", (long)[dateBirthDay getYear], (long)[dateBirthDay getMonth], (long)[dateBirthDay getDay]];
  498 + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  499 + [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  500 + valueBirthDay = [dateFormatter stringFromDate:dateBirthDay];
  501 + //valueBirthDay = [NSString stringWithFormat:@"%ld-%ld-%ld", (long)[dateBirthDay getYear], (long)[dateBirthDay getMonth], (long)[dateBirthDay getDay]];
  502 + dictResutl = [self addParam:@"birthday" value:valueBirthDay withDict:dictResutl];
437 503 }
438 504 dictResutl = [self addParam:@"height" value:_tfHeight.text withDict:dictResutl];
439 505 dictResutl = [self addParam:@"weight" value:_tfWeight.text withDict:dictResutl];
440 506  
... ... @@ -445,13 +511,25 @@
445 511 if (![profile_image isEqualToString:@""]) {
446 512 dictResutl = [self addParam:@"profile_image" value:profile_image withDict:dictResutl];
447 513 }
  514 + // hardcode
  515 + // require
  516 + [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"receive_notification"];
  517 + // = [self addParam:@"receive_notification" value:@"0" withDict:dictResutl];
  518 + [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"share_data"];
  519 + // dictResutl = [self addParam:@"share_data" value:@"0" withDict:dictResutl];
  520 +
  521 + // Option
  522 + //dictResutl = [self addParam:@"phone" value:@"01676582596" withDict:dictResutl];
  523 + [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"remember"];
  524 + //dictResutl = [self addParam:@"remember" value:@"0" withDict:dictResutl];
  525 +
448 526 return dictResutl;
449 527 }
450 528  
451 529 - (void)registerUser {
452 530 NSDictionary *paramRegister = [self createParamsForRegisterUser];
453 531 RegisterViewController __weak *weakSelf = self;
454   - [[ServerAPI server] registerUserWithParams:paramRegister CompletionHandler:^(NSError *error) {
  532 + [[ServerAPI server] registerUserWithParams:paramRegister CompletionHandler:^(User *user, NSString *token, NSError *error) {
455 533 if (weakSelf == nil) {
456 534 return ;
457 535 }
458 536  
... ... @@ -463,33 +541,10 @@
463 541 else {
464 542 dispatch_async(dispatch_get_main_queue(), ^{
465 543 NSString *message = [error.userInfo objectForKey:@"message"];
466   - [weakSelf showErrorMessage:message];
  544 + [Utilities showErrorMessage:message withViewController:weakSelf];
467 545 });
468 546 }
469 547 }];
470   -}
471   -
472   -- (void)showErrorMessage:(NSString *)message
473   -{
474   - if (message.length > 0) {
475   - UIAlertController * alert= [UIAlertController
476   - alertControllerWithTitle:@"Error"
477   - message:message
478   - preferredStyle:UIAlertControllerStyleAlert];
479   -
480   - UIAlertAction* ok = [UIAlertAction
481   - actionWithTitle:@"OK"
482   - style:UIAlertActionStyleDefault
483   - handler:^(UIAlertAction * action)
484   - {
485   - [alert dismissViewControllerAnimated:YES completion:nil];
486   -
487   - }];
488   -
489   - [alert addAction:ok];
490   -
491   - [self presentViewController:alert animated:YES completion:nil];
492   - }
493 548 }
494 549  
495 550 @end
LifeLog/LifeLog/ServerAPI.h
... ... @@ -13,7 +13,9 @@
13 13 + (instancetype) server;
14 14 @property (nonatomic, assign) NSTimeInterval timeOutInterval;
15 15 - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion;
16   -- (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(NSError *)) completion;
  16 +- (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion;
17 17 - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion;
  18 +- (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion;
  19 +- (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion;
18 20 @end
LifeLog/LifeLog/ServerAPI.m
... ... @@ -68,8 +68,7 @@
68 68 if (error == nil)
69 69 {
70 70 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
71   -
72   -
  71 +
73 72 int status = [dataResult[@"status"] intValue];
74 73 if (status == 1) { // status = 1 success
75 74 NSString *token = dataResult[@"result"][@"token"];
... ... @@ -103,7 +102,7 @@
103 102 }
104 103  
105 104 // Register
106   -- (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(NSError *)) completion {
  105 +- (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion {
107 106 [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" paras:params completion:^(NSData *data, NSError *error) {
108 107  
109 108 if (completion == NULL) {
110 109  
111 110  
112 111  
113 112  
114 113  
... ... @@ -113,29 +112,92 @@
113 112 if (error == nil)
114 113 {
115 114 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
116   - completion(nil);
117   - /*
  115 +
  116 + int status = [dataResult[@"status"] intValue];
  117 + if (status == 1) { // status = 1 success
  118 + NSString *token = dataResult[@"result"][@"token"];
  119 + NSDictionary *dictUser = dataResult[@"result"][@"user"];
  120 + User *user = [[User alloc] init];
  121 + user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]];
  122 + user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]];
  123 + user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]];
  124 + user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]];
  125 + user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]];
  126 + user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]];
  127 + user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]];
  128 + user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]];
  129 + user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue];
  130 + user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue];
  131 + user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue];
  132 + user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]];
  133 + completion(user, token, nil);
  134 + }
  135 + else { // status = 0 error
  136 + NSString *message = dataResult[@"message"];
  137 + NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
  138 + completion(nil, nil, loginFaild);
  139 + }
  140 + }
  141 + else
  142 + {
  143 + completion(nil, nil, error);
  144 + }
  145 + }];
  146 +}
  147 +
  148 +- (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion {
  149 + [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" paras:@{@"email":email} completion:^(NSData *data, NSError *error) {
  150 +
  151 + if (completion == NULL) {
  152 + return ;
  153 + }
  154 +
  155 + if (error == nil)
  156 + {
118 157 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
119   - if (dataResult == nil) {
  158 +
  159 + int status = [dataResult[@"status"] intValue];
  160 + if (status == 1) { // status = 1 success
120 161 completion(nil);
121 162 }
122   -
  163 + else { // status = 0 error
  164 + NSString *message = dataResult[@"message"];
  165 + NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
  166 + completion(forgetPass);
  167 + }
  168 + }
  169 + else
  170 + {
  171 + completion(error);
  172 + }
  173 + }];
  174 +}
  175 +- (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion {
  176 + [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) {
  177 +
  178 + if (completion == NULL) {
  179 + return ;
  180 + }
  181 +
  182 + if (error == nil)
  183 + {
  184 + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
  185 +
123 186 int status = [dataResult[@"status"] intValue];
124 187 if (status == 1) { // status = 1 success
125 188 completion(nil);
126 189 }
127 190 else { // status = 0 error
128 191 NSString *message = dataResult[@"message"];
129   - NSError *registerFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
130   - completion(registerFaild);
  192 + NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
  193 + completion(confirmForgetPass);
131 194 }
132   - */
133 195 }
134 196 else
135 197 {
136 198 completion(error);
137 199 }
138   - }];
  200 + }];
139 201 }
140 202  
141 203 - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion {
LifeLog/LifeLog/User.m
... ... @@ -9,25 +9,43 @@
9 9 #import "User.h"
10 10  
11 11 @implementation User
12   -//- (id)initWithCoder:(NSCoder *)decoder {
13   -// self = [super init];
14   -// if (!self) {
15   -// return nil;
16   -// }
17   -//
18   -// self.user_id = [decoder decodeObjectForKey:@"user_id"];
19   -// self.access_token = [decoder decodeObjectForKey:@"access_token"];
20   -// self.full_name = [decoder decodeObjectForKey:@"full_name"];
21   -// self.picture = [decoder decodeObjectForKey:@"picture"];
22   -//
23   -// return self;
24   -//}
25   -//
26   -//- (void)encodeWithCoder:(NSCoder *)encoder {
27   -// [encoder encodeObject:self.user_id forKey:@"user_id"];
28   -// [encoder encodeObject:self.access_token forKey:@"access_token"];
29   -// [encoder encodeObject:self.full_name forKey:@"full_name"];
30   -// [encoder encodeObject:self.picture forKey:@"picture"];
31   -//}
  12 +- (id)initWithCoder:(NSCoder *)decoder {
  13 + self = [super init];
  14 + if (!self) {
  15 + return nil;
  16 + }
  17 +
  18 + self.user_id = [decoder decodeObjectForKey:@"user_id"];
  19 + self.username = [decoder decodeObjectForKey:@"username"];
  20 + self.password = [decoder decodeObjectForKey:@"password"];
  21 + self.full_name = [decoder decodeObjectForKey:@"full_name"];
  22 + self.nickname = [decoder decodeObjectForKey:@"nickname"];
  23 + self.birthday = [decoder decodeObjectForKey:@"birthday"];
  24 + self.height = [decoder decodeFloatForKey:@"height"];
  25 + self.weight = [decoder decodeFloatForKey:@"weight"];
  26 + self.gender = [decoder decodeIntForKey:@"gender"];
  27 + self.address = [decoder decodeObjectForKey:@"address"];
  28 + self.user_description = [decoder decodeObjectForKey:@"user_description"];
  29 + self.email = [decoder decodeObjectForKey:@"email"];
  30 + self.phone = [decoder decodeObjectForKey:@"phone"];
  31 +
  32 + return self;
  33 +}
  34 +
  35 +- (void)encodeWithCoder:(NSCoder *)encoder {
  36 + [encoder encodeObject:self.user_id forKey:@"user_id"];
  37 + [encoder encodeObject:self.username forKey:@"username"];
  38 + [encoder encodeObject:self.password forKey:@"password"];
  39 + [encoder encodeObject:self.full_name forKey:@"full_name"];
  40 + [encoder encodeObject:self.nickname forKey:@"nickname"];
  41 + [encoder encodeObject:self.birthday forKey:@"birthday"];
  42 + [encoder encodeFloat:self.height forKey:@"height"];
  43 + [encoder encodeFloat:self.weight forKey:@"weight"];
  44 + [encoder encodeInt:self.gender forKey:@"gender"];
  45 + [encoder encodeObject:self.address forKey:@"address"];
  46 + [encoder encodeObject:self.user_description forKey:@"user_description"];
  47 + [encoder encodeObject:self.email forKey:@"email"];
  48 + [encoder encodeObject:self.phone forKey:@"phone"];
  49 +}
32 50 @end
LifeLog/LifeLog/Utilities.h
... ... @@ -12,5 +12,6 @@
12 12 @interface Utilities : NSObject
13 13 + (NSString *)addCommaFromNumber:(NSInteger)number;
14 14 + (UIColor *)convertHecToColor:(int) hex;
  15 ++ (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc;
15 16 @end
LifeLog/LifeLog/Utilities.m
... ... @@ -25,5 +25,28 @@
25 25 blue:((float)(hex & 0xFF))/255.0 alpha:1.0];
26 26 }
27 27  
  28 ++ (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc
  29 +{
  30 + if (message.length > 0) {
  31 + UIAlertController * alert= [UIAlertController
  32 + alertControllerWithTitle:@"Error"
  33 + message:message
  34 + preferredStyle:UIAlertControllerStyleAlert];
  35 +
  36 + UIAlertAction* ok = [UIAlertAction
  37 + actionWithTitle:@"OK"
  38 + style:UIAlertActionStyleDefault
  39 + handler:^(UIAlertAction * action)
  40 + {
  41 + [alert dismissViewControllerAnimated:YES completion:nil];
  42 +
  43 + }];
  44 +
  45 + [alert addAction:ok];
  46 +
  47 + [vc presentViewController:alert animated:YES completion:nil];
  48 + }
  49 +}
  50 +
28 51 @end